Merge branch 'MDL-50955-310' of git://github.com/peterRd/moodle into MOODLE_310_STABLE
authorAdrian Greeve <abgreeve@gmail.com>
Tue, 17 Nov 2020 05:08:48 +0000 (13:08 +0800)
committerAdrian Greeve <abgreeve@gmail.com>
Tue, 17 Nov 2020 05:08:48 +0000 (13:08 +0800)
1  2 
lib/db/upgrade.php

@@@ -2995,8 -2995,23 +2995,26 @@@ function xmldb_main_upgrade($oldversion
          upgrade_main_savepoint(true, 2020102700.04);
      }
  
 +    // Automatically generated Moodle v3.10.0 release upgrade line.
 +    // Put any upgrade step following this.
 +
+     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;
  }