mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-28346 Backup: Restore does not fail when a file is missing
This commit is contained in:
parent
05e521c9bc
commit
3b232aeffb
@ -818,10 +818,13 @@ abstract class restore_dbops {
|
||||
* @param int|null $olditemid
|
||||
* @param int|null $forcenewcontextid explicit value for the new contextid (skip mapping)
|
||||
* @param bool $skipparentitemidctxmatch
|
||||
* @return array of result object
|
||||
*/
|
||||
public static function send_files_to_pool($basepath, $restoreid, $component, $filearea, $oldcontextid, $dfltuserid, $itemname = null, $olditemid = null, $forcenewcontextid = null, $skipparentitemidctxmatch = false) {
|
||||
global $DB;
|
||||
|
||||
$results = array();
|
||||
|
||||
if ($forcenewcontextid) {
|
||||
// Some components can have "forced" new contexts (example: questions can end belonging to non-standard context mappings,
|
||||
// with questions originally at system/coursecat context in source being restored to course context in target). So we need
|
||||
@ -901,8 +904,14 @@ abstract class restore_dbops {
|
||||
// this is a regular file, it must be present in the backup pool
|
||||
$backuppath = $basepath . backup_file_manager::get_backup_content_file_location($file->contenthash);
|
||||
|
||||
// The file is not found in the backup.
|
||||
if (!file_exists($backuppath)) {
|
||||
throw new restore_dbops_exception('file_not_found_in_pool', $file);
|
||||
$result = new stdClass();
|
||||
$result->code = 'file_missing_in_backup';
|
||||
$result->message = sprintf('missing file %s%s in backup', $file->filepath, $file->filename);
|
||||
$result->level = backup::LOG_WARNING;
|
||||
$results[] = $result;
|
||||
continue;
|
||||
}
|
||||
|
||||
// create the file in the filepool if it does not exist yet
|
||||
@ -959,6 +968,7 @@ abstract class restore_dbops {
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -218,8 +218,14 @@ abstract class restore_structure_step extends restore_step {
|
||||
*/
|
||||
public function add_related_files($component, $filearea, $mappingitemname, $filesctxid = null, $olditemid = null) {
|
||||
$filesctxid = is_null($filesctxid) ? $this->task->get_old_contextid() : $filesctxid;
|
||||
restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), $component,
|
||||
$filearea, $filesctxid, $this->task->get_userid(), $mappingitemname, $olditemid);
|
||||
$results = restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), $component,
|
||||
$filearea, $filesctxid, $this->task->get_userid(), $mappingitemname, $olditemid);
|
||||
$resultstoadd = array();
|
||||
foreach ($results as $result) {
|
||||
$this->log($result->message, $result->level);
|
||||
$resultstoadd[$result->code] = true;
|
||||
}
|
||||
$this->task->add_result($resultstoadd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -772,6 +772,9 @@ class restore_ui_stage_complete extends restore_ui_stage_process {
|
||||
$html .= $renderer->box_end();
|
||||
}
|
||||
$html .= $renderer->box_start();
|
||||
if (array_key_exists('file_missing_in_backup', $this->results)) {
|
||||
$html .= $renderer->notification(get_string('restorefileweremissing', 'backup'), 'notifyproblem');
|
||||
}
|
||||
$html .= $renderer->notification(get_string('restoreexecutionsuccess', 'backup'), 'notifysuccess');
|
||||
$html .= $renderer->continue_button(new moodle_url('/course/view.php', array(
|
||||
'id' => $this->get_ui()->get_controller()->get_courseid())), 'get');
|
||||
|
@ -177,6 +177,7 @@ $string['restoreactivity'] = 'Restore activity';
|
||||
$string['restorecourse'] = 'Restore course';
|
||||
$string['restorecoursesettings'] = 'Course settings';
|
||||
$string['restoreexecutionsuccess'] = 'The course was restored successfully, clicking the continue button below will take you to view the course you restored.';
|
||||
$string['restorefileweremissing'] = 'Some files could not be restored because they were missing in the backup.';
|
||||
$string['restorenewcoursefullname'] = 'New course name';
|
||||
$string['restorenewcourseshortname'] = 'New course short name';
|
||||
$string['restorenewcoursestartdate'] = 'New start date';
|
||||
|
Loading…
x
Reference in New Issue
Block a user