MDL-60167 upgrade: Fix duplicate site registrations

This commit is contained in:
Marina Glancy
2017-09-24 18:51:12 +08:00
parent 2f0bd18ad9
commit 1ce18b558b
2 changed files with 21 additions and 2 deletions
+20 -1
View File
@@ -2906,7 +2906,12 @@ function xmldb_main_upgrade($oldversion) {
['hub', '%' . $DB->sql_like_escape('_' . $cleanoldhuburl)]);
foreach ($entries as $entry) {
$newname = substr($entry->name, 0, -strlen($cleanoldhuburl)) . $cleannewhuburl;
$DB->update_record('config_plugins', ['id' => $entry->id, 'name' => $newname]);
try {
$DB->update_record('config_plugins', ['id' => $entry->id, 'name' => $newname]);
} catch (dml_exception $e) {
// Entry with new name already exists, remove the one with an old name.
$DB->delete_records('config_plugins', ['id' => $entry->id]);
}
}
// Update published courses.
@@ -2942,5 +2947,19 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2017051502.01);
}
if ($oldversion < 2017051502.04) {
// Remove duplicate registrations.
$newhuburl = "https://moodle.net";
$registrations = $DB->get_records('registration_hubs', ['huburl' => $newhuburl], 'confirmed DESC, id ASC');
if (count($registrations) > 1) {
$reg = array_shift($registrations);
$DB->delete_records_select('registration_hubs', 'huburl = ? AND id <> ?', [$newhuburl, $reg->id]);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2017051502.04);
}
return true;
}
+1 -1
View File
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2017051502.03; // 20170515 = branching date YYYYMMDD - do not modify!
$version = 2017051502.04; // 20170515 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.