MDL-71801 mod_lti: set default keytype value when upgrading tool types

MDL-66920 added this field but didn't set defaults for upgrading tool
types. This patch fixes that for any 1.3 tools which don't yet have a
value for this field.
This commit is contained in:
Jake Dallimore 2021-05-31 13:12:20 +08:00
parent 34ce1463cc
commit a1e763e670
2 changed files with 26 additions and 1 deletions

View File

@ -180,5 +180,30 @@ function xmldb_lti_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2021052501, 'lti');
}
if ($oldversion < 2022032900) {
// This option 'Public key type' was added in MDL-66920, but no value was set for existing 1.3 tools.
// Set a default of 'RSA Key' for those LTI 1.3 tools without a value, representing the only key type they
// could use at the time of their creation. Existing tools which have since been resaved will not be impacted.
$sql = "SELECT t.id
FROM {lti_types} t
LEFT JOIN {lti_types_config} tc
ON (tc.typeid = t.id AND tc.name = :typename)
WHERE t.ltiversion = :ltiversion
AND tc.value IS NULL";
$params = ['typename' => 'keytype', 'ltiversion' => '1.3.0'];
$recordset = $DB->get_recordset_sql($sql, $params);
foreach ($recordset as $record) {
$DB->insert_record('lti_types_config', (object) [
'typeid' => $record->id,
'name' => 'keytype',
'value' => 'RSA_KEY'
]);
}
$recordset->close();
// Lti savepoint reached.
upgrade_mod_savepoint(true, 2022032900, 'lti');
}
return true;
}

View File

@ -48,7 +48,7 @@
defined('MOODLE_INTERNAL') || die;
$plugin->version = 2021052502; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2022032900; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2021052500; // Requires this Moodle version.
$plugin->component = 'mod_lti'; // Full name of the plugin (used for diagnostics).
$plugin->cron = 0;