From: defacer Date: Mon, 17 Jan 2005 14:26:17 +0000 (+0000) Subject: Fix for bug 2377: X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3cacefda86239f9e05d9f776b15bbfe01d25145f;p=moodle.git Fix for bug 2377: Make it more difficult for instances with invalid blockid to be added to mdl_block_instance. This could result in warnings, although nothing more serious than that. Credits to Eloy and especially Dan Marsden for reporting and providing info. --- diff --git a/lib/blocklib.php b/lib/blocklib.php index 6fc517e025..7ee9305589 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -445,8 +445,8 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid) // Add a new instance of this block, if allowed $block = blocks_get_record($blockid); - if(!$block->visible) { - // Only allow adding if the block is enabled + if(empty($block) || !$block->visible) { + // Only allow adding if the block exists and is enabled return false; } @@ -589,8 +589,12 @@ function blocks_repopulate_page($page) { $newinstance->weight = $weight; $newinstance->visible = 1; $newinstance->configdata = ''; - insert_record('block_instance', $newinstance); - ++$weight; + + if(!empty($newinstance->blockid)) { + // Only add block if it was recognized + insert_record('block_instance', $newinstance); + ++$weight; + } } }