mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Now user_preferences are fully supported in backup & restore.
This commit is contained in:
parent
21d1d0773b
commit
41fd7fe497
2 changed files with 51 additions and 1 deletions
|
@ -811,6 +811,22 @@
|
||||||
|
|
||||||
//End ROLES tag
|
//End ROLES tag
|
||||||
fwrite ($bf,end_tag("ROLES",4,true));
|
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
|
//End User tag
|
||||||
fwrite ($bf,end_tag("USER",3,true));
|
fwrite ($bf,end_tag("USER",3,true));
|
||||||
|
|
|
@ -532,9 +532,10 @@
|
||||||
} else {
|
} else {
|
||||||
$newid = $user_data->id;
|
$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_user = true;
|
||||||
$create_roles = true;
|
$create_roles = true;
|
||||||
|
$create_preferences = true;
|
||||||
|
|
||||||
//If we are restoring course users and it isn't a course user
|
//If we are restoring course users and it isn't a course user
|
||||||
if ($restore->users == 1 and !$is_course_user) {
|
if ($restore->users == 1 and !$is_course_user) {
|
||||||
|
@ -542,6 +543,7 @@
|
||||||
$status = backup_putid($restore->backup_unique_code,"user",$userid,null,'notincourse');
|
$status = backup_putid($restore->backup_unique_code,"user",$userid,null,'notincourse');
|
||||||
$create_user = false;
|
$create_user = false;
|
||||||
$create_roles = false;
|
$create_roles = false;
|
||||||
|
$create_preferences = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user_exists and $create_user) {
|
if ($user_exists and $create_user) {
|
||||||
|
@ -638,6 +640,27 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1724,6 +1747,11 @@
|
||||||
$this->info->tempuser->roles[$this->info->temprole->type] = $this->info->temprole;
|
$this->info->tempuser->roles[$this->info->temprole->type] = $this->info->temprole;
|
||||||
unset($this->info->temprole);
|
unset($this->info->temprole);
|
||||||
break;
|
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) {
|
if ($this->level == 7) {
|
||||||
|
@ -1755,6 +1783,12 @@
|
||||||
case "TIMEACCESS":
|
case "TIMEACCESS":
|
||||||
$this->info->temprole->timeaccess = $this->getContents();
|
$this->info->temprole->timeaccess = $this->getContents();
|
||||||
break;
|
break;
|
||||||
|
case "NAME":
|
||||||
|
$this->info->tempuserpreference->name = $this->getContents();
|
||||||
|
break;
|
||||||
|
case "VALUE":
|
||||||
|
$this->info->tempuserpreference->value = $this->getContents();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue