Merge branch 'MDL-68683-master-fix' of git://github.com/lameze/moodle
authorAdrian Greeve <abgreeve@gmail.com>
Thu, 20 Aug 2020 01:54:48 +0000 (09:54 +0800)
committerAdrian Greeve <abgreeve@gmail.com>
Thu, 20 Aug 2020 01:54:48 +0000 (09:54 +0800)
1  2 
lib/db/upgrade.php
version.php

@@@ -2542,39 -2542,23 +2542,38 @@@ function xmldb_main_upgrade($oldversion
          upgrade_main_savepoint(true, 2020072300.01);
      }
  
-     if ($oldversion < 2020081400.01) {
-         // Delete all user evidence files from users that have been deleted.
-         $sql = "SELECT DISTINCT f.*
-                   FROM {files} f
-              LEFT JOIN {context} c ON f.contextid = c.id
-              LEFT JOIN {user} u ON c.instanceid = u.id
-                  WHERE f.component = :component
-                    AND f.filearea = :filearea
-                    AND u.deleted = 1";
-         $stalefiles = $DB->get_records_sql($sql, ['component' => 'core_competency', 'filearea' => 'userevidence']);
-         $fs = get_file_storage();
-         foreach ($stalefiles as $stalefile) {
-             $fs->get_file_instance($stalefile)->delete();
-         }
-         upgrade_main_savepoint(true, 2020081400.01);
-     }
 -    if ($oldversion < 2020081400.02) {
 +    if ($oldversion < 2021052500.01) {
 +
 +        // Define field timecreated to be added to task_adhoc.
 +        $table = new xmldb_table('task_adhoc');
 +        $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'blocking');
 +
 +        // Conditionally launch add field timecreated.
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +
 +        // Main savepoint reached.
 +        upgrade_main_savepoint(true, 2021052500.01);
 +    }
 +
++    if ($oldversion < 2021052500.02) {
+         // Delete all user evidence files from users that have been deleted.
+         $sql = "SELECT DISTINCT f.*
+                   FROM {files} f
+              LEFT JOIN {context} c ON f.contextid = c.id
+                  WHERE f.component = :component
+                    AND f.filearea = :filearea
+                    AND c.id IS NULL";
+         $stalefiles = $DB->get_records_sql($sql, ['component' => 'core_competency', 'filearea' => 'userevidence']);
+         $fs = get_file_storage();
+         foreach ($stalefiles as $stalefile) {
+             $fs->get_file_instance($stalefile)->delete();
+         }
 -        upgrade_main_savepoint(true, 2020081400.02);
++        upgrade_main_savepoint(true, 2021052500.02);
+     }
      return true;
  }
diff --cc version.php
@@@ -29,7 -29,7 +29,7 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2021052500.01;              // YYYYMMDD      = weekly release date of this DEV branch.
 -$version  = 2020081400.02;              // YYYYMMDD      = weekly release date of this DEV branch.
++$version  = 2021052500.02;              // YYYYMMDD      = weekly release date of this DEV branch.
                                          //         RR    = release increments - 00 in DEV branches.
                                          //           .XX = incremental changes.
  $release  = '4.0dev (Build: 20200814)'; // Human-friendly version name