From 6ba026e55d1675a50753e20632aa70fb64d5d0fb Mon Sep 17 00:00:00 2001
From: Penny Leach <penny@mjollnir.org>
Date: Tue, 27 Oct 2009 13:58:44 +0100
Subject: [PATCH] Reworked handling of new courses slightly based on Eloy's feedback

---
 backup/lib.php        |   11 +++++++++--
 backup/restorelib.php |    8 +-------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/backup/lib.php b/backup/lib.php
index 6abe5a5..9298747 100644
--- a/backup/lib.php
+++ b/backup/lib.php
@@ -797,11 +797,18 @@
                 }
             }
         }
-        if (!$courseid = restore_execute($restore,$restore->info,$restore->course_header,$errorstr)) {
+        if (!$status = restore_execute($restore,$restore->info,$restore->course_header,$errorstr)) {
             mtrace($debuginfo.'Failed restore_execute (error was '.$errorstr.')');
             return false;
         }
-        return $courseid;
+        // now get out the new courseid and return that
+        if ($restore->restoreto = RESTORETO_NEW_COURSE) {
+            if (!empty($SESSION->restore->course_id)) {
+                return $SESSION->restore->course_id;
+            }
+            return false;
+        }
+        return true;
     }
 
     /**
diff --git a/backup/restorelib.php b/backup/restorelib.php
index 3fc5c43..9ad1976 100644
--- a/backup/restorelib.php
+++ b/backup/restorelib.php
@@ -685,7 +685,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
 
     //This function create a new course record.
     //When finished, course_header contains the id of the new course
-    function restore_create_new_course(&$restore,&$course_header) {
+    function restore_create_new_course($restore,&$course_header) {
 
         global $CFG, $SESSION;
 
@@ -854,7 +854,6 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
                 backup_putid ($restore->backup_unique_code,"course",$course_header->course_id,$newid);
                 //Replace old course_id in course_header
                 $course_header->course_id = $newid;
-                $restore->course_id = $newid;
                 $SESSION->restore->course_id = $newid;
                 return $newid;
             } else {
@@ -7939,8 +7938,6 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
                     $errorstr = "Error while creating the new empty course.";
                     return false;
                 }
-            } else {
-                $newcourseid = $status;
             }
 
             //Print course fullname and shortname and category
@@ -8666,9 +8663,6 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             echo "</table>";
         }
 
-        if (!empty($newcourseid)) {
-            $status = $newcourseid;
-        }
         return $status;
     }
     //Create, open and write header of the html log file
-- 
1.6.5

