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)
1  2 
lib/db/upgrade.php
lib/moodlelib.php
version.php

@@@ -3466,58 -3466,21 +3466,75 @@@ function xmldb_main_upgrade($oldversion
      }
  
      if ($oldversion < 2019083000.01) {
 -        upgrade_main_savepoint(true, 2019083000.01);
 +
 +        // If block_community is no longer present, remove it.
 +        if (!file_exists($CFG->dirroot . '/blocks/community/communitycourse.php')) {
 +            // Drop table that is no longer needed.
 +            $table = new xmldb_table('block_community');
 +            if ($dbman->table_exists($table)) {
 +                $dbman->drop_table($table);
 +            }
 +
 +            // Delete instances.
 +            $instances = $DB->get_records_list('block_instances', 'blockname', ['community']);
 +            $instanceids = array_keys($instances);
 +
 +            if (!empty($instanceids)) {
 +                $DB->delete_records_list('block_positions', 'blockinstanceid', $instanceids);
 +                $DB->delete_records_list('block_instances', 'id', $instanceids);
 +                list($sql, $params) = $DB->get_in_or_equal($instanceids, SQL_PARAMS_NAMED);
 +                $params['contextlevel'] = CONTEXT_BLOCK;
 +                $DB->delete_records_select('context', "contextlevel=:contextlevel AND instanceid " . $sql, $params);
 +
 +                $preferences = array();
 +                foreach ($instances as $instanceid => $instance) {
 +                    $preferences[] = 'block' . $instanceid . 'hidden';
 +                    $preferences[] = 'docked_block_instance_' . $instanceid;
 +                }
 +                $DB->delete_records_list('user_preferences', 'name', $preferences);
 +            }
 +
 +            // Delete the block from the block table.
 +            $DB->delete_records('block', array('name' => 'community'));
 +
 +            // Remove capabilities.
 +            capabilities_cleanup('block_community');
 +            // Clean config.
 +            unset_all_config_for_plugin('block_community');
 +
 +            // Remove Moodle-level community based capabilities.
 +            $capabilitiestoberemoved = ['block/community:addinstance', 'block/community:myaddinstance'];
 +            // Delete any role_capabilities for the old roles.
 +            $DB->delete_records_list('role_capabilities', 'capability', $capabilitiestoberemoved);
 +            // Delete the capability itself.
 +            $DB->delete_records_list('capabilities', 'name', $capabilitiestoberemoved);
 +        }
 +
 +        upgrade_main_savepoint(true, 2019083000.01);
 +    }
 +
 +    if ($oldversion < 2019083000.02) {
 +        // Remove unused config.
 +        unset_config('enablecoursepublishing');
 +        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;
  }
Simple merge
diff --cc version.php
@@@ -29,7 -29,7 +29,7 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2019083000.03;              // YYYYMMDD      = weekly release date of this DEV branch.
 -$version  = 2019083000.01;              // 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.