From: martinlanghoff Date: Tue, 16 Jan 2007 00:56:15 +0000 (+0000) Subject: mnet: restore_create_users() is now mnet-aware X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=da586c3778aa16f8bf093d8aae986950a84aaae2;p=moodle.git mnet: restore_create_users() is now mnet-aware 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. --- diff --git a/backup/restorelib.php b/backup/restorelib.php index ad62c8aaf3..3175bf04a4 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -1451,7 +1451,9 @@ //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; @@ -1476,11 +1478,27 @@ //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 {