allow deleting of block when original code not present

This commit is contained in:
skodak
2006-09-03 17:46:27 +00:00
parent 460a7a6271
commit e9a207595c
4 changed files with 18 additions and 16 deletions
+9 -5
View File
@@ -82,20 +82,24 @@
} else {
// Inform block it's about to be deleted
$blockobject = block_instance($block->name);
$blockobject->before_delete();
// Delete block
if (!delete_records('block', 'id', $block->id)) {
notify("Error occurred while deleting the $strblockname record from blocks table");
if ($blockobject) {
$blockobject->before_delete(); //only if we can create instance, block might have been already removed
}
// First delete instances and then block
$instances = get_records('block_instance', 'blockid', $block->id);
if(!empty($instances)) {
foreach($instances as $instance) {
blocks_delete_instance($instance);
blocks_delete_instance($instance, true);
}
}
// Delete block
if (!delete_records('block', 'id', $block->id)) {
notify("Error occurred while deleting the $strblockname record from blocks table");
}
// Then the tables themselves
if ($tables = $db->Metatables()) {
+1 -1
View File
@@ -14,7 +14,7 @@ define('BLOCK_L_MAX_WIDTH',210);
page_map_class(PAGE_ADMIN, 'page_admin');
$PAGE = page_create_object(PAGE_ADMIN, 0); // there must be some id number
$PAGE = page_create_object(PAGE_ADMIN, 0); // there must be any constant id number
$section = optional_param('section', '', PARAM_ALPHAEXT);
+1 -1
View File
@@ -2188,7 +2188,7 @@ function admin_externalpage_setup($section, $adminroot) {
page_map_class(PAGE_ADMIN, 'page_admin');
$PAGE = page_create_object(PAGE_ADMIN, 0); // there must be some id number
$PAGE = page_create_object(PAGE_ADMIN, 0); // there must be any constant id number
$PAGE->init_extra($section); // hack alert!
+7 -9
View File
@@ -22,7 +22,7 @@ require_once($CFG->libdir.'/pagelib.php');
function block_is_compatible($blockname) {
global $CFG;
$file = file($CFG->dirroot.'/blocks/'.$blockname.'/block_'.$blockname.'.php');
$file = @file($CFG->dirroot.'/blocks/'.$blockname.'/block_'.$blockname.'.php'); // ignore errors when file does not exist
if(empty($file)) {
return NULL;
}
@@ -119,7 +119,7 @@ function block_load_class($blockname) {
}
require_once($CFG->dirroot.'/blocks/moodleblock.class.php');
include_once($CFG->dirroot.'/blocks/'.$blockname.'/block_'.$blockname.'.php');
@include_once($CFG->dirroot.'/blocks/'.$blockname.'/block_'.$blockname.'.php'); // do not throw errors if block code not present
return class_exists($classname);
}
@@ -189,16 +189,14 @@ function blocks_name_allowed_in_format($name, $pageformat) {
function blocks_delete_instance($instance,$pinned=false) {
global $CFG;
// Get the block object and call instance_delete() first
// Get the block object and call instance_delete() if possible
if(!$record = blocks_get_record($instance->blockid)) {
return false;
}
if(!$obj = block_instance($record->name, $instance)) {
return false;
if(!$obj = block_instance($record->name, $instance)) {
// Return value ignored
$obj->instance_delete();
}
}
// Return value ignored
$obj->instance_delete();
if (!empty($pinned)) {
delete_records('block_pinned', 'id', $instance->id);
// And now, decrement the weight of all blocks after this one