backup MDL-24103 Better error messages when a user attempts to restore invalid backup...
authorSam Hemelryk <sam@moodle.com>
Wed, 8 Sep 2010 07:23:27 +0000 (07:23 +0000)
committerSam Hemelryk <sam@moodle.com>
Wed, 8 Sep 2010 07:23:27 +0000 (07:23 +0000)
backup/util/ui/renderer.php
backup/util/ui/restore_ui_stage.class.php
lang/en/backup.php

index 1ee44e4..f66a88d 100644 (file)
@@ -603,6 +603,20 @@ class core_backup_renderer extends plugin_renderer_base {
         $output .= html_writer::end_tag('div');
         return $output;
     }
+
+    public function invalid_format($format) {
+        $html  = html_writer::start_tag('div', array('class'=>'invalidformat'));
+        $html .= html_writer::tag('h2', get_string('errorinvalidformat', 'backup'), array('class'=>'notifyproblem'));
+        if ($format == 'moodle1') {
+            // Moodle 1.x backups
+            $html .= html_writer::tag('div', get_string('errormoodle1formatdesc', 'backup'), array('class'=>'notifyproblem'));
+        } else {
+            // Totally unknown format
+            $html .= html_writer::tag('div', get_string('errorinvalidformatdesc', 'backup'), array('class'=>'notifyproblem'));
+        }
+        $html .= html_writer::end_tag('div');
+        return $html;
+    }
 }
 
 /**
index 6eab098..863a02f 100644 (file)
@@ -169,6 +169,13 @@ class restore_ui_stage_confirm extends restore_ui_independent_stage {
         return ($fb->extract_to_pathname("$CFG->dataroot/temp/backup/".$this->filename, "$CFG->dataroot/temp/backup/$this->filepath/"));
     }
     public function display($renderer) {
+
+        // TODO: Remove this when backup formats are better supported
+        $format = backup_general_helper::detect_backup_format($this->filepath);
+        if ($format !== 'moodle2') {
+            return $renderer->invalid_format($format);
+        }
+
         $this->details = backup_general_helper::get_backup_information($this->filepath);
         return $renderer->backup_details($this->details, new moodle_url('/backup/restore.php', array('contextid'=>$this->contextid, 'filepath'=>$this->filepath, 'stage'=>restore_ui::STAGE_DESTINATION)));
     }
@@ -233,6 +240,12 @@ class restore_ui_stage_destination extends restore_ui_independent_stage {
      */
     public function display($renderer) {
         global $DB, $USER, $PAGE;
+
+        $format = backup_general_helper::detect_backup_format($this->filepath);
+        if ($format !== 'moodle2') {
+            return $renderer->invalid_format($format);
+        }
+
         $this->details = backup_general_helper::get_backup_information($this->filepath);
         $url = new moodle_url('/backup/restore.php', array('contextid'=>$this->contextid, 'filepath'=>$this->filepath, 'stage'=>restore_ui::STAGE_SETTINGS));
         
index c20def2..94266bb 100644 (file)
@@ -80,6 +80,9 @@ $string['errorfilenamerequired'] = 'You must enter a valid filename for this bac
 $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.';
 $string['errorrestorefrontpage'] = 'Restoring over front page is not allowed.';
+$string['errorinvalidformat'] = 'Invalid backup format.';
+$string['errorinvalidformatdesc'] = 'The uploaded file is invalid or not a recognised restorable backup.';
+$string['errormoodle1formatdesc'] = 'Moodle 1.x backups are not presently restorable. This functionality is under development and will be complete shortly.';
 $string['executionsuccess'] = 'The backup file was successfully created.';
 $string['filename'] = 'Filename';
 $string['generalactivities'] = 'Include activities';