]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8605 fixed user image restore code
authorskodak <skodak>
Sat, 20 Oct 2007 20:57:06 +0000 (20:57 +0000)
committerskodak <skodak>
Sat, 20 Oct 2007 20:57:06 +0000 (20:57 +0000)
backup/restorelib.php

index f41434de2f82a30b22f95aabb4115d559c5f5a04..abe69fdae5c49990638522d2d10cee258ec6b032 100644 (file)
                     // relink the descriptions
                     $user->description = stripslashes(backup_todb($user->description));
 
+                    if (!empty($CFG->disableuserimages)) {
+                        $user->picture = 0;
+                    }
+
                     //We need to analyse the AUTH field to recode it:
                     //   - if the field isn't set, we are in a pre 1.4 backup and we'll
                     //     use manual
             foreach ($list as $dir) {
                 // If there are directories in this folder, we are in the new user hierarchy
                 if ($newlist = list_directories("$rootdir/$dir")) {
-                    foreach ($newlist as $userid) {
-                        $userlist[$userid] = "$rootdir/$dir/$userid";
+                    foreach ($newlist as $olduserid) {
+                        $userlist[$olduserid] = "$rootdir/$dir/$olduserid";
                     }
                 } else {
-                    $userlist[$userid] = "$rootdir/$dir";
+                    $userlist[$dir] = "$rootdir/$dir";
                 }
             }
 
-            foreach ($userlist as $userid => $backup_location) { 
+            foreach ($userlist as $olduserid => $backup_location) { 
                 //Look for dir like username in backup_ids
-                $data = get_record ("backup_ids","backup_code",$restore->backup_unique_code, "table_name","user", "old_id",$userid);
-
                 //If that user exists in backup_ids
-                if ($data) {
+                if ($user = backup_getid($restore->backup_unique_code,"user",$olduserid)) {
                     //Only if user has been created now or if it existed previously, but he hasn't got an image (see bug 1123)
-                    $newuserdir = make_user_directory($userid, true); // Doesn't create the folder, just returns the location
+                    $newuserdir = make_user_directory($user->new_id, true); // Doesn't create the folder, just returns the location
 
-                    if ((strpos($data->info,"new") !== false) or (!check_dir_exists($newuserdir))) {
-                        //Copy the old_dir to its new location (and name) !! Only if destination doesn't exists
-                        if (!file_exists($newuserdir)) {
-                            make_user_directory($userid); // Creates the folder
+                    // restore images if new user or image does not exist yet
+                    if (!empty($user->new) or !check_dir_exists($newuserdir)) {
+                        if (make_user_directory($user->new_id)) { // Creates the folder
                             $status = backup_copy_file($backup_location, $newuserdir, true);
                             $counter ++;
                         }