Merge branch 'MDL-66357-master' of git://github.com/sarjona/moodle
[moodle.git] / lib / db / upgrade.php
index 8fb38d4..dc266b3 100644 (file)
@@ -2213,6 +2213,17 @@ function xmldb_main_upgrade($oldversion) {
     }
 
     if ($oldversion < 2020040200.01) {
+        // Clean up completion criteria records referring to courses that no longer exist.
+        $select = 'criteriatype = :type AND courseinstance NOT IN (SELECT id FROM {course})';
+        $params = ['type' => 8]; // COMPLETION_CRITERIA_TYPE_COURSE.
+
+        $DB->delete_records_select('course_completion_criteria', $select, $params);
+
+        // Main savepoint reached.
+        upgrade_main_savepoint(true, 2020040200.01);
+    }
+
+    if ($oldversion < 2020040700.00) {
         // Remove deprecated Mozilla OpenBadges backpack.
         $url = 'https://backpack.openbadges.org';
         $bp = $DB->get_record('badge_external_backpack', ['backpackapiurl' => $url]);
@@ -2244,7 +2255,7 @@ function xmldb_main_upgrade($oldversion) {
             unset_config('badges_site_backpack');
         }
 
-        upgrade_main_savepoint(true, 2020040200.01);
+        upgrade_main_savepoint(true, 2020040700.00);
     }
 
     return true;