MDL-23752 backup - export/import mode. Fixed various details.
[moodle.git] / backup / import.php
index 0106e70..0cc71fb 100644 (file)
@@ -59,7 +59,7 @@ require_capability('moodle/backup:backuptargetimport', $importcontext);
 $backupid = optional_param('backup', false, PARAM_ALPHANUM);
 if (!($bc = backup_ui::load_controller($backupid))) {
     $bc = new backup_controller(backup::TYPE_1COURSE, $importcourse->id, backup::FORMAT_MOODLE,
 $backupid = optional_param('backup', false, PARAM_ALPHANUM);
 if (!($bc = backup_ui::load_controller($backupid))) {
     $bc = new backup_controller(backup::TYPE_1COURSE, $importcourse->id, backup::FORMAT_MOODLE,
-                            backup::INTERACTIVE_YES, backup::MODE_GENERAL, $USER->id);
+                            backup::INTERACTIVE_YES, backup::MODE_IMPORT, $USER->id);
     $bc->get_plan()->get_setting('users')->set_status(backup_setting::LOCKED_BY_CONFIG);
     $settings = $bc->get_plan()->get_settings();
 
     $bc->get_plan()->get_setting('users')->set_status(backup_setting::LOCKED_BY_CONFIG);
     $settings = $bc->get_plan()->get_settings();
 
@@ -90,23 +90,18 @@ if ($backup->get_stage() == backup_ui::STAGE_CONFIRMATION) {
 if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
     // First execute the backup
     $backup->execute();
 if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
     // First execute the backup
     $backup->execute();
-    $results = $backup->get_controller()->get_results();
-    
-    // Check whether the backup directory still exists and if it doesn't extract the
-    // backup file so that we have it
+
+    // Check whether the backup directory still exists. If missing, something
+    // went really wrong in backup, throw error. Note that backup::MODE_IMPORT
+    // backups don't store resulting files ever
     $tempdestination = $CFG->dataroot . '/temp/backup/' . $backupid;
     if (!file_exists($tempdestination) || !is_dir($tempdestination)) {
     $tempdestination = $CFG->dataroot . '/temp/backup/' . $backupid;
     if (!file_exists($tempdestination) || !is_dir($tempdestination)) {
-        $file = $results['backup_destination'];
-        $file->extract_to_pathname(get_file_packer('application/zip'), $tempdestination);
-    }
-    if (!empty($results['backup_destination'])) {
-        // Delete the backup file, we only want the directory
-        $results['backup_destination']->delete();
+        print_error('unknownbackupexporterror'); // shouldn't happen ever
     }
 
     // Prepare the restore controller. We don't need a UI here as we will just use what
     // ever the restore has (the user has just chosen).
     }
 
     // Prepare the restore controller. We don't need a UI here as we will just use what
     // ever the restore has (the user has just chosen).
-    $rc = new restore_controller($backupid, $course->id, backup::INTERACTIVE_YES, backup::MODE_GENERAL, $USER->id, $restoretarget);
+    $rc = new restore_controller($backupid, $course->id, backup::INTERACTIVE_YES, backup::MODE_IMPORT, $USER->id, $restoretarget);
     // Convert the backup if required.... it should NEVER happed
     if ($rc->get_status() == backup::STATUS_REQUIRE_CONV) {
         $rc->convert();
     // Convert the backup if required.... it should NEVER happed
     if ($rc->get_status() == backup::STATUS_REQUIRE_CONV) {
         $rc->convert();
@@ -161,4 +156,4 @@ if ($backup->enforce_changed_dependencies()) {
 }
 echo $renderer->progress_bar($backup->get_progress_bar());
 echo $backup->display();
 }
 echo $renderer->progress_bar($backup->get_progress_bar());
 echo $backup->display();
-echo $OUTPUT->footer();
\ No newline at end of file
+echo $OUTPUT->footer();