From 4aa4d88da86eca598e46c86794d2c0513d00514c Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Tue, 4 Jun 2013 15:56:25 +0800 Subject: [PATCH] MDL-38314 repository: Remove orphan repository instances --- lib/db/upgrade.php | 14 ++++++++++++++ version.php | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index c6bafe0f1af..26562e2f82a 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2190,5 +2190,19 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2013061700.00); } + if ($oldversion < 2013062700.01) { + + // Remove orphan repository instances. + $sql = 'SELECT contextid FROM {repository_instances} ri + WHERE NOT EXISTS ( + SELECT id FROM {context} c + WHERE c.id = ri.contextid)'; + $ids = $DB->get_fieldset_sql($sql); + $DB->delete_records_list('repository_instances', 'contextid', $ids); + + // Main savepoint reached. + upgrade_main_savepoint(true, 2013062700.01); + } + return true; } diff --git a/version.php b/version.php index beef47c567c..fadb22aba84 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2013062700.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2013062700.01; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes