MDL-65313 core: upgrade code to remove stale favourites for messaging
authorJake Dallimore <jake@moodle.com>
Wed, 10 Apr 2019 03:59:31 +0000 (11:59 +0800)
committerJake Dallimore <jake@moodle.com>
Mon, 6 May 2019 06:11:46 +0000 (14:11 +0800)
These were left behing when deleting a group or a course.

lib/db/upgrade.php
version.php

index 744561c..b3e24ea 100644 (file)
@@ -3301,5 +3301,21 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint(true, 2019042700.01);
     }
 
+    if ($oldversion < 2019050300.01) {
+        // Delete all stale favourite records which were left behind when a course was deleted.
+        $select = 'id IN (
+            SELECT fav.id as id
+              FROM {favourite} fav
+         LEFT JOIN {context} ctx ON (ctx.id = fav.contextid)
+             WHERE fav.component = :component
+               AND fav.itemtype = :itemtype
+               AND ctx.id IS NULL
+               )';
+        $params = ['component' => 'core_message', 'itemtype' => 'message_conversations'];
+        $DB->delete_records_select('favourite', $select, $params);
+
+        upgrade_main_savepoint(true, 2019050300.01);
+    }
+
     return true;
 }
index a7b5515..9dbdfb4 100644 (file)
@@ -29,7 +29,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2019050300.00;              // YYYYMMDD      = weekly release date of this DEV branch.
+$version  = 2019050300.01;              // YYYYMMDD      = weekly release date of this DEV branch.
                                         //         RR    = release increments - 00 in DEV branches.
                                         //           .XX = incremental changes.