From 493f5d4851de5fbd29262143396943cb33437978 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 27 Sep 2016 18:07:50 +0100 Subject: [PATCH] MDL-56136 restore: better error handling copying file at start --- backup/restorefile.php | 8 ++++++-- lang/en/backup.php | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/backup/restorefile.php b/backup/restorefile.php index 411aeb607d7..e310387320b 100644 --- a/backup/restorefile.php +++ b/backup/restorefile.php @@ -93,7 +93,9 @@ if ($action == 'choosebackupfile') { // If it's some weird other kind of file then use old code. $filename = restore_controller::get_tempdir_name($courseid, $USER->id); $pathname = $tmpdir . '/' . $filename; - $fileinfo->copy_to_pathname($pathname); + if (!$fileinfo->copy_to_pathname($pathname)) { + throw new restore_ui_exception('errorcopyingbackupfile', null, $pathname); + } $restore_url = new moodle_url('/backup/restore.php', array( 'contextid' => $contextid, 'filename' => $filename)); } @@ -115,7 +117,9 @@ $data = $form->get_data(); if ($data && has_capability('moodle/restore:uploadfile', $context)) { $filename = restore_controller::get_tempdir_name($courseid, $USER->id); $pathname = $tmpdir . '/' . $filename; - $form->save_file('backupfile', $pathname); + if (!$form->save_file('backupfile', $pathname)) { + throw new restore_ui_exception('errorcopyingbackupfile', null, $pathname); + } $restore_url = new moodle_url('/backup/restore.php', array('contextid'=>$contextid, 'filename'=>$filename)); redirect($restore_url); die; diff --git a/lang/en/backup.php b/lang/en/backup.php index 3f75c53b049..bfee1caf6c8 100644 --- a/lang/en/backup.php +++ b/lang/en/backup.php @@ -116,6 +116,7 @@ $string['currentstage16'] = 'Complete'; $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['errorcopyingbackupfile'] = "Failed to copy the backup file to the temporary folder before restoring."; $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.';