MDL-32233 core_course_duplicate_course: Fixed integrator review details described...
authorJuan Leyva <juanleyvadelgado@gmail.com>
Wed, 16 May 2012 10:10:09 +0000 (12:10 +0200)
committerJuan Leyva <juanleyvadelgado@gmail.com>
Wed, 16 May 2012 10:10:09 +0000 (12:10 +0200)
course/externallib.php

index 559e2db..cf9be4b 100644 (file)
@@ -805,15 +805,20 @@ class core_course_external extends external_api {
 
         $bc->execute_plan();
         $results = $bc->get_results();
-        $file = $results['backup_destination'];
+
+        if (!empty($results['backup_destination'])) {
+            $file = $results['backup_destination'];
+        } else {
+            $file = null;
+        }
+
         $bc->destroy();
 
         // Restore the backup immediately.
 
-        // In a backup mode different than import, we need to unzip the file because the backup temp directory is deleted.
-        if (!empty($backupsettings['users'])) {
-            check_dir_exists($CFG->tempdir . '/backup');
-            $file->extract_to_pathname(get_file_packer(), $CFG->tempdir . '/backup/' . $backupid);
+        // Check if we need to unzip the file because the backup temp dir does not contains backup files.
+        if ($file and !file_exists($backupbasepath . "/moodle_backup.xml")) {
+            $file->extract_to_pathname(get_file_packer(), $backupbasepath);
         }
 
         // Create new course.
@@ -867,6 +872,10 @@ class core_course_external extends external_api {
             fulldelete($backupbasepath);
         }
 
+        if ($file) {
+            $file->delete();
+        }
+
         return array('id' => $course->id, 'shortname' => $course->shortname);
     }