MDL-50955 core: Reset lessons completion criteria if grade type is none
authorPeter Dias <peter@moodle.com>
Wed, 7 Oct 2020 02:55:25 +0000 (10:55 +0800)
committerPeter Dias <peter@moodle.com>
Mon, 16 Nov 2020 08:35:33 +0000 (16:35 +0800)
lib/db/upgrade.php
version.php

index 3976d5f..bf10f18 100644 (file)
@@ -2995,5 +2995,23 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint(true, 2020102700.04);
     }
 
+    if ($oldversion < 2020110900.01) {
+        // Get all lessons that are set with a completion criteria of 'requires grade' but with no grade type set.
+        $sql = "SELECT cm.id
+                  FROM {course_modules} cm
+                  JOIN {lesson} l ON l.id = cm.instance
+                  JOIN {modules} m ON m.id = cm.module
+                 WHERE m.name = :name AND cm.completiongradeitemnumber IS NOT NULL AND l.grade = :grade";
+
+        do {
+            if ($invalidconfigrations = $DB->get_records_sql($sql, ['name' => 'lesson', 'grade' => 0], 0, 1000)) {
+                list($insql, $inparams) = $DB->get_in_or_equal(array_keys($invalidconfigrations), SQL_PARAMS_NAMED);
+                $DB->set_field_select('course_modules', 'completiongradeitemnumber', null, "id $insql", $inparams);
+            }
+        } while ($invalidconfigrations);
+
+        upgrade_main_savepoint(true, 2020110900.01);
+    }
+
     return true;
 }
index 68359d5..f12a1f5 100644 (file)
@@ -29,7 +29,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2020110900.00;              // 20201109      = branching date YYYYMMDD - do not modify!
+$version  = 2020110900.01;              // 20201109      = branching date YYYYMMDD - do not modify!
                                         //         RR    = release increments - 00 in DEV branches.
                                         //           .XX = incremental changes.
 $release  = '3.10 (Build: 20201109)';// Human-friendly version name