MDL-68683 competencies: fix query to delete stale files
authorSimey Lameze <simey@moodle.com>
Thu, 20 Aug 2020 00:54:05 +0000 (08:54 +0800)
committerSimey Lameze <simey@moodle.com>
Thu, 20 Aug 2020 00:59:25 +0000 (08:59 +0800)
lib/db/upgrade.php
version.php

index 44348f0..90ade41 100644 (file)
@@ -2542,15 +2542,14 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint(true, 2020072300.01);
     }
 
-    if ($oldversion < 2020081400.01) {
+    if ($oldversion < 2020081400.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
-             LEFT JOIN {user} u ON c.instanceid = u.id
                  WHERE f.component = :component
                    AND f.filearea = :filearea
-                   AND u.deleted = 1";
+                   AND c.id IS NULL";
         $stalefiles = $DB->get_records_sql($sql, ['component' => 'core_competency', 'filearea' => 'userevidence']);
 
         $fs = get_file_storage();
@@ -2558,7 +2557,7 @@ function xmldb_main_upgrade($oldversion) {
             $fs->get_file_instance($stalefile)->delete();
         }
 
-        upgrade_main_savepoint(true, 2020081400.01);
+        upgrade_main_savepoint(true, 2020081400.02);
     }
 
     return true;
index fcd47b7..44b293a 100644 (file)
@@ -29,7 +29,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2020081400.01;              // YYYYMMDD      = weekly release date of this DEV branch.
+$version  = 2020081400.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