From f3a3e234488f9b076de38f2b578aa9628967f7cf Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Tue, 29 Aug 2017 13:02:26 +0530 Subject: [PATCH] MDL-57115 blocks: Cleanup block_messages instances and other configs --- blocks/upgrade.txt | 1 + lib/classes/plugin_manager.php | 4 ++-- lib/db/upgrade.php | 36 ++++++++++++++++++++++++++++++++++ version.php | 2 +- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/blocks/upgrade.txt b/blocks/upgrade.txt index 6b8fc564aea..7ef8f0abd0c 100644 --- a/blocks/upgrade.txt +++ b/blocks/upgrade.txt @@ -9,6 +9,7 @@ information provided here is intended especially for developers. * Blocks can now be included in Moodle global search, with some limitations (at present, the search works only for blocks located directly on course pages or site home page). See the HTML block for an example. +* Block block_messages is no longer a part of core. === 3.3 === diff --git a/lib/classes/plugin_manager.php b/lib/classes/plugin_manager.php index 197b2418b0b..75b98b47f1f 100644 --- a/lib/classes/plugin_manager.php +++ b/lib/classes/plugin_manager.php @@ -1647,7 +1647,7 @@ class core_plugin_manager { $plugins = array( 'qformat' => array('blackboard', 'learnwise'), 'auth' => array('radius', 'fc', 'nntp', 'pam', 'pop3', 'imap'), - 'block' => array('course_overview'), + 'block' => array('course_overview', 'messages'), 'enrol' => array('authorize'), 'report' => array('search'), 'repository' => array('alfresco'), @@ -1715,7 +1715,7 @@ class core_plugin_manager { 'calendar_upcoming', 'comments', 'community', 'completionstatus', 'course_list', 'course_summary', 'feedback', 'globalsearch', 'glossary_random', 'html', - 'login', 'lp', 'mentees', 'messages', 'mnet_hosts', 'myoverview', 'myprofile', + 'login', 'lp', 'mentees', 'mnet_hosts', 'myoverview', 'myprofile', 'navigation', 'news_items', 'online_users', 'participants', 'private_files', 'quiz_results', 'recent_activity', 'rss_client', 'search_forums', 'section_links', diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 945b3bf79fe..a9ff5fee003 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2436,5 +2436,41 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2017082800.00); } + if ($oldversion < 2017091000.00) { + + if (!file_exists($CFG->dirroot . '/blocks/messages/block_messages.php')) { + + // Delete instances. + $instances = $DB->get_records_list('block_instances', 'blockname', ['messages']); + $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' => 'messages')); + + // Remove capabilities. + capabilities_cleanup('block_messages'); + + // Clean config. + unset_all_config_for_plugin('block_messages'); + } + + upgrade_main_savepoint(true, 2017091000.00); + } + return true; } diff --git a/version.php b/version.php index 5460083f927..3082e5beb31 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2017090700.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2017091000.00; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes.