mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-30327 standardise block deletion process
This commit is contained in:
parent
fe41ba7489
commit
544832790d
@ -98,33 +98,7 @@
|
||||
exit;
|
||||
|
||||
} else {
|
||||
// Inform block it's about to be deleted
|
||||
if (file_exists("$CFG->dirroot/blocks/$block->name/block_$block->name.php")) {
|
||||
$blockobject = block_instance($block->name);
|
||||
if ($blockobject) {
|
||||
$blockobject->before_delete(); //only if we can create instance, block might have been already removed
|
||||
}
|
||||
}
|
||||
|
||||
// First delete instances and then block
|
||||
$instances = $DB->get_records('block_instances', array('blockname' => $block->name));
|
||||
if(!empty($instances)) {
|
||||
foreach($instances as $instance) {
|
||||
blocks_delete_instance($instance);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete block
|
||||
$DB->delete_records('block', array('id'=>$block->id));
|
||||
|
||||
drop_plugin_tables($block->name, "$CFG->dirroot/blocks/$block->name/db/install.xml", false); // old obsoleted table names
|
||||
drop_plugin_tables('block_'.$block->name, "$CFG->dirroot/blocks/$block->name/db/install.xml", false);
|
||||
|
||||
// Delete the capabilities that were defined by this block
|
||||
capabilities_cleanup('block/'.$block->name);
|
||||
|
||||
// Remove event handlers and dequeue pending events
|
||||
events_uninstall('block/'.$block->name);
|
||||
uninstall_plugin('block', $block->name);
|
||||
|
||||
$a->block = $strblockname;
|
||||
$a->directory = $CFG->dirroot.'/blocks/'.$block->name;
|
||||
|
@ -245,6 +245,26 @@ function uninstall_plugin($type, $name) {
|
||||
set_config('enrol_plugins_enabled', implode(',', $enabledenrols));
|
||||
}
|
||||
}
|
||||
|
||||
} else if ($type === 'block') {
|
||||
if ($block = $DB->get_record('block', array('name'=>$name))) {
|
||||
// Inform block it's about to be deleted
|
||||
if (file_exists("$CFG->dirroot/blocks/$block->name/block_$block->name.php")) {
|
||||
$blockobject = block_instance($block->name);
|
||||
if ($blockobject) {
|
||||
$blockobject->before_delete(); //only if we can create instance, block might have been already removed
|
||||
}
|
||||
}
|
||||
|
||||
// First delete instances and related contexts
|
||||
$instances = $DB->get_records('block_instances', array('blockname' => $block->name));
|
||||
foreach($instances as $instance) {
|
||||
blocks_delete_instance($instance);
|
||||
}
|
||||
|
||||
// Delete block
|
||||
$DB->delete_records('block', array('id'=>$block->id));
|
||||
}
|
||||
}
|
||||
|
||||
// perform clean-up task common for all the plugin/subplugin types
|
||||
@ -271,7 +291,11 @@ function uninstall_plugin($type, $name) {
|
||||
|
||||
// delete the plugin tables
|
||||
$xmldbfilepath = $plugindirectory . '/db/install.xml';
|
||||
drop_plugin_tables($pluginname, $xmldbfilepath, false);
|
||||
drop_plugin_tables($component, $xmldbfilepath, false);
|
||||
if ($type === 'mod' or $type === 'block') {
|
||||
// non-frankenstyle table prefixes
|
||||
drop_plugin_tables($name, $xmldbfilepath, false);
|
||||
}
|
||||
|
||||
// delete the capabilities that were defined by this module
|
||||
capabilities_cleanup($component);
|
||||
|
Loading…
x
Reference in New Issue
Block a user