Merge branch 'MDL-69751-master' of git://github.com/mihailges/moodle
authorJake Dallimore <jake@moodle.com>
Wed, 21 Oct 2020 01:59:48 +0000 (09:59 +0800)
committerJake Dallimore <jake@moodle.com>
Wed, 21 Oct 2020 02:05:16 +0000 (10:05 +0800)
1  2 
lib/db/upgrade.php
version.php

@@@ -2783,37 -2783,40 +2783,73 @@@ function xmldb_main_upgrade($oldversion
      }
  
      if ($oldversion < 2021052500.26) {
 -        upgrade_main_savepoint(true, 2021052500.26);
 +        // 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, 2021052500.26);
 +    }
 +
 +    if ($oldversion < 2021052500.27) {
 +        // 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, 2021052500.27);
 +    }
 +
++    if ($oldversion < 2021052500.29) {
+         // 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, 2021052500.29);
+     }
      return true;
  }
diff --cc version.php
@@@ -29,9 -29,9 +29,9 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2021052500.28;              // YYYYMMDD      = weekly release date of this DEV branch.
 -$version  = 2021052500.26;              // YYYYMMDD      = weekly release date of this DEV branch.
++$version  = 2021052500.29;              // YYYYMMDD      = weekly release date of this DEV branch.
                                          //         RR    = release increments - 00 in DEV branches.
                                          //           .XX = incremental changes.
 -$release  = '4.0dev (Build: 20201016)'; // Human-friendly version name
 +$release  = '4.0dev (Build: 20201021)'; // Human-friendly version name
  $branch   = '400';                      // This version's branch.
  $maturity = MATURITY_ALPHA;             // This version's maturity level.