From d836aa4b4fbcce3ed078852c1da384a9a2a5d9fe Mon Sep 17 00:00:00 2001 From: poltawski Date: Sat, 22 Aug 2009 11:24:39 +0000 Subject: [PATCH] lib/blocklib: MDL-20146 - Don't mask errors as a way to ignore missing code files 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 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/blocklib.php b/lib/blocklib.php index 06ac5dce6c..064af2314f 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -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); } -- 2.39.5