Skip to content

Commit

Permalink
MDL-82916 core: minor fixes to lti upgrade steps
Browse files Browse the repository at this point in the history
Fixes:
- Conditionally rename the service table, preventing an orphaned table
when re-running upgrade steps. If the replacement plugin exists, it's
assumed that the migration has already taken place.
- Whitespace + spacing issues.
  • Loading branch information
snake committed Oct 24, 2024
1 parent f8b5b66 commit 6eb8376
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1450,22 +1450,23 @@ function xmldb_main_upgrade($oldversion) {
if ($oldversion < 2024100700.02) {
// Move mod_lti keys into new core lti config.
if (!empty(get_config('mod_lti', 'kid')) && !empty(get_config('mod_lti', 'privatekey'))) {
set_config('kid', get_config('mod_lti', 'kid'), 'core_ltix');
set_config('privatekey', get_config('mod_lti', 'privatekey'), 'core_ltix');
set_config('kid', get_config('mod_lti', 'kid'), 'core_ltix');
set_config('privatekey', get_config('mod_lti', 'privatekey'), 'core_ltix');
set_config('kid', null, 'mod_lti');
set_config('privatekey', null, 'mod_lti');
}

// Rename the ltiservice_gradebookservices table so that it's not removed during the uninstallation of that plugin.
// This permits data migration to the replacement ltixservice_gradebookservices during that plugin's install.php.
if (!$dbman->table_exists(new xmldb_table('ltixservice_gradebookservices'))) {
// Define table ltiservice_gradebookservices to be renamed to tmp_ltiservice_gradebookservices.
$table = new xmldb_table('ltiservice_gradebookservices');

// Define table ltiservice_gradebookservices to be renamed to tmp_ltiservice_gradebookservices.
$table = new xmldb_table('ltiservice_gradebookservices');

// Launch rename table for ltiservice_gradebookservices.
$dbman->rename_table($table, 'tmp_ltiservice_gradebookservices');
// Launch rename table for ltiservice_gradebookservices.
$dbman->rename_table($table, 'tmp_ltiservice_gradebookservices');
}

$servicetypes = ['basicoutcomes', 'gradebookservices', 'memberships','profile', 'toolproxy', 'toolsettings'];
$servicetypes = ['basicoutcomes', 'gradebookservices', 'memberships', 'profile', 'toolproxy', 'toolsettings'];
foreach ($servicetypes as $type) {
$versionfile = $CFG->dirroot . "mod/lti/service/{$type}/version.php";

Expand All @@ -1481,7 +1482,7 @@ function xmldb_main_upgrade($oldversion) {
[$insql, $inparams] = $DB->get_in_or_equal($pluginconfigoptions, SQL_PARAMS_NAMED, 'name');
$sql = "UPDATE {lti_types_config}
SET name = REPLACE(name, :oldprefix, :newprefix)
WHERE name ".$insql;
WHERE name " . $insql;
$params = ['oldprefix' => 'ltiservice_', 'newprefix' => 'ltixservice_'];
$DB->execute($sql, array_merge($params, $inparams));

Expand Down

0 comments on commit 6eb8376

Please sign in to comment.