From 962f75ec5359c27098629fd27cf5d074c1cd37f4 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Mon, 31 May 2021 13:12:20 +0800 Subject: [PATCH] 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. --- mod/lti/db/upgrade.php | 25 +++++++++++++++++++++++++ mod/lti/version.php | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/mod/lti/db/upgrade.php b/mod/lti/db/upgrade.php index 165448bf875..a82ff0f3021 100644 --- a/mod/lti/db/upgrade.php +++ b/mod/lti/db/upgrade.php @@ -186,5 +186,30 @@ function xmldb_lti_upgrade($oldversion) { // Automatically generated Moodle v3.11.0 release upgrade line. // Put any upgrade step following this. + if ($oldversion < 2021051701) { + // 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, 2021051701, 'lti'); + } + return true; } diff --git a/mod/lti/version.php b/mod/lti/version.php index d49b71b6a16..7c5ae3c4651 100644 --- a/mod/lti/version.php +++ b/mod/lti/version.php @@ -48,7 +48,7 @@ defined('MOODLE_INTERNAL') || die; -$plugin->version = 2021051700; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2021051701; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2021051100; // Requires this Moodle version. $plugin->component = 'mod_lti'; // Full name of the plugin (used for diagnostics). $plugin->cron = 0;