diff --git a/backup/moodle2/backup_plan_builder.class.php b/backup/moodle2/backup_plan_builder.class.php index 053d77d8f92..0342462ffe0 100644 --- a/backup/moodle2/backup_plan_builder.class.php +++ b/backup/moodle2/backup_plan_builder.class.php @@ -123,12 +123,23 @@ abstract class backup_plan_builder { // Add the activity task, responsible for outputting // all the module related information - $plan->add_task(backup_factory::get_backup_activity_task($controller->get_format(), $id)); + try { + $plan->add_task(backup_factory::get_backup_activity_task($controller->get_format(), $id)); - // For the given activity, add as many block tasks as necessary - $blockids = backup_plan_dbops::get_blockids_from_moduleid($id); - foreach ($blockids as $blockid) { - $plan->add_task(backup_factory::get_backup_block_task($controller->get_format(), $blockid, $id)); + // For the given activity, add as many block tasks as necessary + $blockids = backup_plan_dbops::get_blockids_from_moduleid($id); + foreach ($blockids as $blockid) { + try { + $plan->add_task(backup_factory::get_backup_block_task($controller->get_format(), $blockid, $id)); + } catch (backup_task_exception $e) { + $a = stdClass(); + $a->mid = $id; + $a->bid = $blockid; + $controller->log(get_string('error_block_for_module_not_found', 'backup', $a), backup::LOG_WARNING); + } + } + } catch (backup_task_exception $e) { + $controller->log(get_string('error_course_module_not_found', 'backup', $id), backup::LOG_WARNING); } } diff --git a/lang/en/backup.php b/lang/en/backup.php index 0b9bc616822..0116d50c36f 100644 --- a/lang/en/backup.php +++ b/lang/en/backup.php @@ -106,6 +106,8 @@ $string['currentstage8'] = 'Perform backup'; $string['currentstage16'] = 'Complete'; $string['dependenciesenforced'] = 'Your settings have been altered due to unmet dependencies'; $string['enterasearch'] = 'Enter a search'; +$string['error_block_for_module_not_found'] = 'Orphan block instance (id: {$a->bid}) for course module (id: {$a->mid}) found. This block will not be backed up'; +$string['error_course_module_not_found'] = 'Orphan course module (id: {$a}) found. This module will not be backed up.'; $string['errorfilenamerequired'] = 'You must enter a valid filename for this backup'; $string['errorfilenamemustbezip'] = 'The filename you enter must be a ZIP file and have the .mbz extension'; $string['errorminbackup20version'] = 'This backup file has been created with one development version of Moodle backup ({$a->backup}). Minimum required is {$a->min}. Cannot be restored.';