Merge branch 'MDL-66551-master' of git://github.com/lameze/moodle
authorJake Dallimore <jake@moodle.com>
Thu, 5 Sep 2019 03:12:35 +0000 (11:12 +0800)
committerJake Dallimore <jake@moodle.com>
Thu, 5 Sep 2019 03:12:35 +0000 (11:12 +0800)
lib/db/upgrade.php
lib/moodlelib.php
version.php

index abb4128..1aa73b8 100644 (file)
@@ -3519,5 +3519,22 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint(true, 2019083000.02);
     }
 
+    if ($oldversion < 2019083000.04) {
+        // Delete "orphaned" subscriptions.
+        $sql = "SELECT DISTINCT es.userid
+                  FROM {event_subscriptions} es
+             LEFT JOIN {user} u ON u.id = es.userid
+                 WHERE u.deleted = 1 OR u.id IS NULL";
+        $deletedusers = $DB->get_field_sql($sql);
+        if ($deletedusers) {
+            list($sql, $params) = $DB->get_in_or_equal($deletedusers);
+
+            // Delete orphaned subscriptions.
+            $DB->execute("DELETE FROM {event_subscriptions} WHERE userid " . $sql, $params);
+        }
+
+        upgrade_main_savepoint(true, 2019083000.04);
+    }
+
     return true;
 }
index 2f23039..7643051 100644 (file)
@@ -4247,6 +4247,9 @@ function delete_user(stdClass $user) {
 
     // Now do a brute force cleanup.
 
+    // Remove user's calendar subscriptions.
+    $DB->delete_records('event_subscriptions', ['userid' => $user->id]);
+
     // Remove from all cohorts.
     $DB->delete_records('cohort_members', array('userid' => $user->id));
 
index 11b30c9..e7bdd3f 100644 (file)
@@ -29,7 +29,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2019083000.03;              // YYYYMMDD      = weekly release date of this DEV branch.
+$version  = 2019083000.04;              // YYYYMMDD      = weekly release date of this DEV branch.
                                         //         RR    = release increments - 00 in DEV branches.
                                         //           .XX = incremental changes.