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.
This commit is contained in:
poltawski 2009-08-22 11:24:39 +00:00
parent 88b49294ec
commit d836aa4b4f

View 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);
}