]> git.mjollnir.org Git - moodle.git/commitdiff
Now user_preferences are fully supported in backup & restore.
authorstronk7 <stronk7>
Sun, 8 Feb 2004 19:27:23 +0000 (19:27 +0000)
committerstronk7 <stronk7>
Sun, 8 Feb 2004 19:27:23 +0000 (19:27 +0000)
backup/backuplib.php
backup/restorelib.php

index 2a73219a22fc24f6006d172a9b892c0b87a166a8..d53c15a75be9b0ffada3ffcef24b23dfafd65abe 100644 (file)
 
                     //End ROLES tag
                     fwrite ($bf,end_tag("ROLES",4,true));
+                    //Check if we have user_preferences to backup
+                    if ($preferences_data = get_records("user_preferences","userid",$user->old_id)) {
+                        //Start USER_PREFERENCES tag
+                        fwrite ($bf,start_tag("USER_PREFERENCES",4,true));
+                        //Write each user_preference
+                        foreach ($preferences_data as $user_preference) {
+                            fwrite ($bf,start_tag("USER_PREFERENCE",5,true));
+                            fwrite ($bf,full_tag("NAME",6,false,$user_preference->name));
+                            fwrite ($bf,full_tag("VALUE",6,false,$user_preference->value));
+                            fwrite ($bf,end_tag("USER_PREFERENCE",5,true));
+                        }
+                        //End USER_PREFERENCES tag
+                        fwrite ($bf,end_tag("USER_PREFERENCES",4,true));
+                    }
+                    
                 }
                 //End User tag
                 fwrite ($bf,end_tag("USER",3,true));
index d39202543ba7e0a412601cb19cc63ea6de0ba8e4..80ee91027b208be4d7fabeda18fd75672061bc66 100644 (file)
                 } else {
                     $newid = $user_data->id;
                 }
-                //Flags to see if we have to create the user and roles
+                //Flags to see if we have to create the user, roles and preferences
                 $create_user = true;
                 $create_roles = true;
+                $create_preferences = true;
 
                 //If we are restoring course users and it isn't a course user
                 if ($restore->users == 1 and !$is_course_user) {
                     $status = backup_putid($restore->backup_unique_code,"user",$userid,null,'notincourse');
                     $create_user = false;
                     $create_roles = false;
+                    $create_preferences = false;
                 }
 
                 if ($user_exists and $create_user) {
                         }
                     }
                 }
+
+                //Here, if create_preferences, do it as necessary
+                if ($create_preferences) {
+                    //echo "Checking for preferences of user ".$user->username."<br>";         //Debug
+                    //Get user new id from backup_ids
+                    $data = backup_getid($restore->backup_unique_code,"user",$userid);
+                    $newid = $data->new_id;
+                    if (isset($user->user_preferences)) {
+                        //echo "Preferences exist in backup file<br>";                         //Debug
+                        foreach($user->user_preferences as $user_preference) {
+                            //echo $user_preference->name." = ".$user_preference->value."<br>";    //Debug
+                            //We check if that user_preference exists in DB
+                            if (!record_exists("user_preferences","userid",$newid,"name",$user_preference->name)) {
+                                //echo "Creating it<br>";                                              //Debug
+                                //Prepare the record and insert it
+                                $user_preference->userid = $newid;
+                                $status = insert_record("user_preferences",$user_preference);
+                            }
+                        }
+                    }
+                }
             }
         }
 
                             $this->info->tempuser->roles[$this->info->temprole->type] = $this->info->temprole;
                             unset($this->info->temprole);
                             break;
+                        case "USER_PREFERENCE":
+                            //We've finalized a user_preference, get it
+                            $this->info->tempuser->user_preferences[$this->info->tempuserpreference->name] = $this->info->tempuserpreference;
+                            unset($this->info->tempuserpreference);
+                            break;
                     }
                 }
                 if ($this->level == 7) {
                         case "TIMEACCESS":
                             $this->info->temprole->timeaccess = $this->getContents();
                             break;
+                        case "NAME":
+                            $this->info->tempuserpreference->name = $this->getContents();
+                            break;
+                        case "VALUE":
+                            $this->info->tempuserpreference->value = $this->getContents();
+                            break;
                     }
                 }
             }