]> git.mjollnir.org Git - moodle.git/commitdiff
Fix for bug 2377:
authordefacer <defacer>
Mon, 17 Jan 2005 14:26:17 +0000 (14:26 +0000)
committerdefacer <defacer>
Mon, 17 Jan 2005 14:26:17 +0000 (14:26 +0000)
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.

lib/blocklib.php

index 6fc517e0252781b8a6f629c65072e6cbc8eb748e..7ee9305589e58a59676ada0617c471072632b128 100644 (file)
@@ -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;
+            }
         }
     }