Merge branch 'MDL-69751-310' of git://github.com/mihailges/moodle into MOODLE_310_STABLE
authorJake Dallimore <jake@moodle.com>
Wed, 21 Oct 2020 02:02:08 +0000 (10:02 +0800)
committerJake Dallimore <jake@moodle.com>
Wed, 21 Oct 2020 02:02:47 +0000 (10:02 +0800)
1  2 
lib/db/upgrade.php
version.php

@@@ -2783,37 -2783,40 +2783,73 @@@ function xmldb_main_upgrade($oldversion
      }
  
      if ($oldversion < 2020101600.01) {
 -        upgrade_main_savepoint(true, 2020101600.01);
 +        // Delete orphaned course_modules_completion rows; these were not deleted properly
 +        // by remove_course_contents function.
 +        $DB->delete_records_subquery('course_modules_completion', 'id', 'id',
 +               "SELECT cmc.id
 +                  FROM {course_modules_completion} cmc
 +             LEFT JOIN {course_modules} cm ON cm.id = cmc.coursemoduleid
 +                 WHERE cm.id IS NULL");
 +        upgrade_main_savepoint(true, 2020101600.01);
 +    }
 +
 +    if ($oldversion < 2020101600.02) {
 +        // Script to fix incorrect records of "hidden" field in existing grade items.
 +        $sql = "SELECT cm.instance, cm.course
 +                  FROM {course_modules} cm
 +                  JOIN {modules} m ON m.id = cm.module
 +                 WHERE m.name = :module AND cm.visible = :visible";
 +        $hidequizlist = $DB->get_recordset_sql($sql, ['module' => 'quiz', 'visible' => 0]);
 +
 +        foreach ($hidequizlist as $hidequiz) {
 +            $params = [
 +                'itemmodule'    => 'quiz',
 +                'courseid'      => $hidequiz->course,
 +                'iteminstance'  => $hidequiz->instance,
 +            ];
 +
 +            $DB->set_field('grade_items', 'hidden', 1, $params);
 +        }
 +        $hidequizlist->close();
 +
 +        upgrade_main_savepoint(true, 2020101600.02);
 +    }
 +
++    if ($oldversion < 2020102100.01) {
+         // Get the current guest user which is also set as 'deleted'.
+         $guestuser = $DB->get_record('user', ['id' => $CFG->siteguest, 'deleted' => 1]);
+         // If there is a deleted guest user, reset the user to not be deleted and make sure the related
+         // user context exists.
+         if ($guestuser) {
+             $guestuser->deleted = 0;
+             $DB->update_record('user', $guestuser);
+             // Get the guest user context.
+             $guestusercontext = $DB->get_record('context',
+                 ['contextlevel' => CONTEXT_USER, 'instanceid' => $guestuser->id]);
+             // If the guest user context does not exist, create it.
+             if (!$guestusercontext) {
+                 $record = new stdClass();
+                 $record->contextlevel = CONTEXT_USER;
+                 $record->instanceid = $guestuser->id;
+                 $record->depth = 0;
+                 // The path is not known before insert.
+                 $record->path = null;
+                 $record->locked = 0;
+                 $record->id = $DB->insert_record('context', $record);
+                 // Update the path.
+                 $record->path = '/' . SYSCONTEXTID . '/' . $record->id;
+                 $record->depth = substr_count($record->path, '/');
+                 $DB->update_record('context', $record);
+             }
+         }
+         // Main savepoint reached.
++        upgrade_main_savepoint(true, 2020102100.01);
+     }
      return true;
  }
diff --cc version.php
@@@ -29,9 -29,9 +29,9 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2020102100.00;              // YYYYMMDD      = weekly release date of this DEV branch.
 -$version  = 2020101600.01;              // YYYYMMDD      = weekly release date of this DEV branch.
++$version  = 2020102100.01;              // YYYYMMDD      = weekly release date of this DEV branch.
                                          //         RR    = release increments - 00 in DEV branches.
                                          //           .XX = incremental changes.
 -$release  = '3.10dev+ (Build: 20201016)';// Human-friendly version name
 +$release  = '3.10dev+ (Build: 20201021)';// Human-friendly version name
  $branch   = '310';                      // This version's branch.
  $maturity = MATURITY_ALPHA;             // This version's maturity level.