]> git.mjollnir.org Git - moodle.git/commitdiff
lib/blocklib: MDL-20146 - Don't mask errors as a way to ignore missing code files
authorpoltawski <poltawski>
Sat, 22 Aug 2009 11:24:39 +0000 (11:24 +0000)
committerpoltawski <poltawski>
Sat, 22 Aug 2009 11:24:39 +0000 (11:24 +0000)
Instead of simply ignoring all errors from blocks, allow the errors to be
exposed and test if the file exists. The previous solution makes it very
hard to debug problems with blocks and gives the 'white screen of death' even
with debugging set as high as it can go.

Also ensure that blocks without code are not added to the list of instances,
as I assume was the intended behaviour.

lib/blocklib.php

index 06ac5dce6c5fb9993a96b476958f4b08d78525a4..064af2314f769d17416edc0d367022290d2680f8 100644 (file)
@@ -753,7 +753,9 @@ class block_manager {
     protected function create_block_instances($birecords) {
         $results = array();
         foreach ($birecords as $record) {
-            $results[] = block_instance($record->blockname, $record, $this->page);
+            if ($blockobject = block_instance($record->blockname, $record, $this->page)) {
+                $results[] = $blockobject;
+            }
         }
         return $results;
     }
@@ -1296,8 +1298,15 @@ function block_load_class($blockname) {
         return true;
     }
 
-    require_once($CFG->dirroot.'/blocks/moodleblock.class.php');
-    @include_once($CFG->dirroot.'/blocks/'.$blockname.'/block_'.$blockname.'.php'); // do not throw errors if block code not present
+    $blockpath = $CFG->dirroot.'/blocks/'.$blockname.'/block_'.$blockname.'.php';
+
+    if (file_exists($blockpath)) {
+        require_once($CFG->dirroot.'/blocks/moodleblock.class.php');
+        include_once($blockpath);
+    }else{
+        debugging("$blockname code does not exist in $blockpath", DEBUG_DEVELOPER);
+        return false;
+    }
 
     return class_exists($classname);
 }