From 7b5f67f77fbed8f4876edab00df21d39d9bad7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Thu, 21 Jun 2012 15:22:38 +0200 Subject: [PATCH] MDL-33430 Notify user about file aliases failures at the final stage of the restore --- backup/moodle2/restore_stepslib.php | 24 +++++++++++++++++++++++ backup/util/ui/restore_ui_stage.class.php | 14 +++++++++++++ lang/en/backup.php | 6 ++++++ theme/base/style/core.css | 2 ++ 4 files changed, 46 insertions(+) diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 91048d80286..adb3cd6b968 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -3353,6 +3353,7 @@ class restore_process_file_aliases_queue extends restore_execution_step { $reason = ' ('.$reason.')'; } $this->log('unable to restore alias'.$reason, backup::LOG_WARNING, $filedesc, 1); + $this->add_result_item('file_aliases_restore_failures', $filedesc); } /** @@ -3391,6 +3392,29 @@ class restore_process_file_aliases_queue extends restore_execution_step { return $filedesc; } + + /** + * Append a value to the given resultset + * + * @param string $name name of the result containing a list of values + * @param mixed $value value to add as another item in that result + */ + private function add_result_item($name, $value) { + + $results = $this->task->get_results(); + + if (isset($results[$name])) { + if (!is_array($results[$name])) { + throw new coding_exception('Unable to append a result item into a non-array structure.'); + } + $current = $results[$name]; + $current[] = $value; + $this->task->add_result(array($name => $current)); + + } else { + $this->task->add_result(array($name => array($value))); + } + } } diff --git a/backup/util/ui/restore_ui_stage.class.php b/backup/util/ui/restore_ui_stage.class.php index c8ecc9eab50..7e920695502 100644 --- a/backup/util/ui/restore_ui_stage.class.php +++ b/backup/util/ui/restore_ui_stage.class.php @@ -757,6 +757,20 @@ class restore_ui_stage_complete extends restore_ui_stage_process { public function display(core_backup_renderer $renderer) { $html = ''; + if (!empty($this->results['file_aliases_restore_failures'])) { + $html .= $renderer->box_start('generalbox filealiasesfailures'); + $html .= $renderer->heading_with_help(get_string('filealiasesrestorefailures', 'core_backup'), + 'filealiasesrestorefailures', 'core_backup'); + $html .= $renderer->container(get_string('filealiasesrestorefailuresinfo', 'core_backup')); + $html .= $renderer->container_start('aliaseslist'); + $html .= html_writer::start_tag('ul'); + foreach ($this->results['file_aliases_restore_failures'] as $alias) { + $html .= html_writer::tag('li', s($alias)); + } + $html .= html_writer::end_tag('ul'); + $html .= $renderer->container_end(); + $html .= $renderer->box_end(); + } $html .= $renderer->box_start(); $html .= $renderer->notification(get_string('restoreexecutionsuccess', 'backup'), 'notifysuccess'); $html .= $renderer->continue_button(new moodle_url('/course/view.php', array( diff --git a/lang/en/backup.php b/lang/en/backup.php index fa809254ddb..5fde19e8722 100644 --- a/lang/en/backup.php +++ b/lang/en/backup.php @@ -117,6 +117,12 @@ $string['errorinvalidformat'] = 'Unknown backup format'; $string['errorinvalidformatinfo'] = 'The selected file is not a valid Moodle backup file and can\'t be restored.'; $string['executionsuccess'] = 'The backup file was successfully created.'; $string['filename'] = 'Filename'; +$string['filealiasesrestorefailures'] = 'Aliases restore failures'; +$string['filealiasesrestorefailuresinfo'] = 'Some aliases included in the backup file could not be restored. The following list contains their expected location and the source file they were referring to at the original site.'; +$string['filealiasesrestorefailures_help'] = 'Aliases are symbolic links to other files, including those stored in external repositories. In some cases, Moodle cannot restore them - for example when restoring the backup at another site or when the referenced file does not exist. + +More details and the actual reason of the failure can be found in the restore log file.'; +$string['filealiasesrestorefailures_link'] = 'restore/filealiases'; $string['filereferencesincluded'] = 'File references to external contents included in backup package, they won\'t work on other sites.'; $string['filereferencessamesite'] = 'Backup is from the same site, file references can be restored'; $string['filereferencesnotsamesite'] = 'Backup is from other site, file references cannot be restored'; diff --git a/theme/base/style/core.css b/theme/base/style/core.css index 28153ca9439..efa27f86456 100644 --- a/theme/base/style/core.css +++ b/theme/base/style/core.css @@ -461,6 +461,8 @@ body.tag .managelink {padding: 5px;} .path-backup .backup_progress .backup_stage.backup_stage_current {font-weight:bold;color:inherit;} .path-backup .backup_progress .backup_stage.backup_stage_next {} .path-backup .backup_progress span.backup_stage.backup_stage_complete {color:inherit;} +#page-backup-restore .filealiasesfailures {background-color:#ffd3d9} +#page-backup-restore .filealiasesfailures .aliaseslist {width:90%;margin:0.8em auto;background-color:white;border:1px dotted #666;} /** * Web Service