]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-7218 workshop: remove orphaned assessments on upgrade
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:32:23 +0000 (18:32 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:32:23 +0000 (18:32 +0000)
Clones the upgrade procedure from MOODLE_19_STABLE.

mod/workshop/db/upgrade.php

index 9160a9233fa33162cacf848136ccd1c5587f5341..616e7e0fedb067f751bbd3ea3b6e741a797d01a3 100644 (file)
@@ -38,6 +38,29 @@ function xmldb_workshop_upgrade($oldversion) {
     $dbman = $DB->get_manager();
     $result = true;
 
+    //===== 1.9.0 upgrade line ======//
+
+    /**
+     * the following blocks contain all the db/upgrade.php logic from MOODLE_19_STABLE branch
+     * so that it does not matter if we are upgrading from 1.9.0, 1.9.3 or 1.9.whatever
+     */
+
+    if ($result && $oldversion < 2007101510) {
+        $orphans = $DB->get_records_sql('SELECT wa.id
+                                           FROM {workshop_assessments} wa
+                                      LEFT JOIN {workshop_submissions} ws ON wa.submissionid = ws.id
+                                          WHERE ws.id IS NULL');
+        if (!empty($orphans)) {
+            echo $OUTPUT->notification('Orphaned assessment records found - cleaning...');
+            foreach (array_keys($orphans) as $waid) {
+                $DB->delete_records('workshop_assessments', 'id', $waid);
+            }
+        }
+        upgrade_mod_savepoint($result, 2007101510, 'workshop');
+    }
+
+    //===== end of 1.9.0 upgrade line ======//
+
     /**
      * Upgrading from workshop 1.9.x - big things going to happen now...
      * The migration procedure is divided into smaller chunks using incremental