MDL-76170 enrol_lti: fix missing secret in enrol_lti_users

If member sync runs before the user launches the tool, a partial record
is created, without consumer secret. Subsequent launches of the tool by
that member don't resolve this and this results in grade sync failing
for any affected users. This patch:
- data fixes the existing affected rows
- fixes the launch code, ensuring secret is recorded on launch,
irrespective of whether the user info record has been created already
or not.
This commit is contained in:
Jake Dallimore
2022-11-09 10:03:50 +08:00
parent 543b0e0055
commit 4938cb25b1
3 changed files with 25 additions and 1 deletions
+3
View File
@@ -344,6 +344,9 @@ class tool_provider extends ToolProvider {
if ($userlog->serviceurl != $serviceurl) {
$userlog->serviceurl = $serviceurl;
}
if (empty($userlog->consumersecret)) {
$userlog->consumersecret = $this->consumer->secret;
}
$userlog->lastaccess = time();
$DB->update_record('enrol_lti_users', $userlog);
} else {
+21
View File
@@ -492,5 +492,26 @@ function xmldb_enrol_lti_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2022041902, 'enrol', 'lti');
}
if ($oldversion < 2022041903) {
// Update lti user information for any users missing a consumer secret.
// This applies to any user who has launched the tool (i.e. has lastaccess) but who doesn't have a secret recorded.
// This fixes a bug where enrol_lti_users records are created first during a member sync, and are missing the secret,
// even despite having launched the tool subsequently.
$sql = "SELECT lu.id, lc.secret
FROM {enrol_lti_users} lu
JOIN {enrol_lti_lti2_consumer} lc
ON (lu.consumerkey = lc.consumerkey256)
WHERE lu.consumersecret IS NULL
AND lu.lastaccess IS NOT NULL";
$affectedltiusersrs = $DB->get_recordset_sql($sql);
foreach ($affectedltiusersrs as $ltiuser) {
$DB->set_field('enrol_lti_users', 'consumersecret', $ltiuser->secret, ['id' => $ltiuser->id]);
}
$affectedltiusersrs->close();
// Lti savepoint reached.
upgrade_plugin_savepoint(true, 2022041903, 'enrol', 'lti');
}
return true;
}
+1 -1
View File
@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2022041902; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2022041903; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2022041200; // Requires this Moodle version.
$plugin->component = 'enrol_lti'; // Full name of the plugin (used for diagnostics).
$plugin->dependencies = [