]> git.mjollnir.org Git - moodle.git/commitdiff
mnet: restore_create_users() is now mnet-aware
authormartinlanghoff <martinlanghoff>
Tue, 16 Jan 2007 00:56:15 +0000 (00:56 +0000)
committermartinlanghoff <martinlanghoff>
Tue, 16 Jan 2007 00:56:15 +0000 (00:56 +0000)
It will now default to $CFG->mnet_localhost_id and can
handle backup files containing an mnethosturl user property
which will be mapped to mnethostid.

Additional checks are needed to avoid restoring files
with mnethosturls we cannot handle.

backup/restorelib.php

index ad62c8aaf3d3aeec2c3a6a6333666b8fa382a74a..3175bf04a4d579c3b930dbc68cb354476b884a26 100644 (file)
         //and create the necessary records (users, user_students, user_teachers
         //user_course_creators and user_admins
         if (!empty($info->users)) {
-            //For each user, take its info from backup_ids
+            // Grab mnethosts keyed by wwwroot, to map to id
+            $mnethosts = get_records('mnethost', '', '', 
+                                     'wwwroot', 'wwwroot, id');
             foreach ($info->users as $userid) {
                 $rec = backup_getid($restore->backup_unique_code,"user",$userid); 
                 $user = $rec->info;
                 //Has role teacher or student or needed
                 $is_course_user = ($is_teacher or $is_student or $is_needed);
 
+                //Calculate mnethostid
+                if (empty($user->mnethosturl) || $user->mnethosturl===$CFG->wwwroot) {
+                    $user->mnethostid = $CFG->mnet_localhost_id;
+                } else {
+                    // fast url-to-id lookups
+                    if (isset($mnethosts->{$user->mnethosturl})) {
+                        $user->mnethostid = $mnethosts->{$user->mnethosturl};
+                    } else { 
+                        // should not happen, as we check in restore_chech.php 
+                        // but handle the error if it does
+                        error("This backup file contains external Moodle Network Hosts that are not configured locally.");
+                    }
+                }
+                unset($user->mnethosturl);
+
                 //To store new ids created
                 $newid=null;
                 //check if it exists (by username) and get its id
                 $user_exists = true;
-                $user_data = get_record("user","username",addslashes($user->username));
+                $user_data = get_record("user","username",addslashes($user->username), 
+                                        'mnethostid', $user->mnethostid);
                 if (!$user_data) {
                     $user_exists = false;
                 } else {