MDL-7164, Mark Nielsen's patch for remove_course_content not calling instance_delete()

This commit is contained in:
toyomoyo
2007-03-22 02:11:51 +00:00
parent 6000365ee4
commit f38dfd49aa
+25 -2
View File
@@ -2991,8 +2991,31 @@ function remove_course_contents($courseid, $showfeedback=true) {
if ($showfeedback) {
notify($strdeleted .' block_instance');
}
require_once($CFG->libdir.'/blocklib.php');
foreach ($blocks as $block) { /// Delete any associated contexts for this block
delete_context(CONTEXT_BLOCK, $block->id);
// Block instances are rarely created. Since the block instance is gone from the above delete
// statement, calling delete_context() will generate a warning as get_context_instance could
// no longer create the context as the block is already gone.
if (record_exists('context', 'contextlevel', CONTEXT_BLOCK, 'instanceid', $block->id)) {
delete_context(CONTEXT_BLOCK, $block->id);
}
// fix for MDL-7164
// Get the block object and call instance_delete()
if (!$record = blocks_get_record($block->blockid)) {
$result = false;
continue;
}
if (!$obj = block_instance($record->name, $block)) {
$result = false;
continue;
}
// Return value ignored, in core mods this does not do anything, but just in case
// third party blocks might have stuff to clean up
// we execute this anyway
$obj->instance_delete();
}
} else {
$result = false;
@@ -3083,7 +3106,7 @@ function remove_course_contents($courseid, $showfeedback=true) {
if ($courseid != SITEID) {
delete_context(CONTEXT_COURSE, $course->id);
}
return $result;
}