MDL-75346 core_my: Handle missing blocks on reset

If the default dashboard contained a block that was missing from disk
then "Exception - Call to a member function instance_copy() on bool"
was shown to users.  This change only shows an error with debugging
enabled which now includes the name of the missing block.
This commit is contained in:
Leon Stringer 2022-12-17 17:37:45 +00:00
parent 5019abfdd6
commit 199ce65ec0

View File

@ -121,9 +121,10 @@ function my_copy_page(
$newblockinstanceids[$originalid] = $instance->id;
$blockcontext = context_block::instance($instance->id); // Just creates the context record
$block = block_instance($instance->blockname, $instance);
if (!$block->instance_copy($originalid)) {
debugging("Unable to copy block-specific data for original block instance: $originalid
to new block instance: $instance->id", DEBUG_DEVELOPER);
if (empty($block) || !$block->instance_copy($originalid)) {
debugging("Unable to copy block-specific data for original block
instance: $originalid to new block instance: $instance->id for
block: $instance->blockname", DEBUG_DEVELOPER);
}
}