Skip to content

Commit

Permalink
Merge branch 'MDL-30192_21' of git://github.com/stronk7/moodle into M…
Browse files Browse the repository at this point in the history
…OODLE_21_STABLE
  • Loading branch information
Sam Hemelryk committed Nov 23, 2011
2 parents aa1d8c5 + 6498060 commit f99bd07
Showing 1 changed file with 43 additions and 39 deletions.
82 changes: 43 additions & 39 deletions backup/util/dbops/restore_dbops.class.php
Expand Up @@ -824,54 +824,58 @@ public static function create_included_users($basepath, $restoreid, $userfiles,
$newuserid = $DB->insert_record('user', $user); $newuserid = $DB->insert_record('user', $user);
self::set_backup_ids_record($restoreid, 'user', $recuser->itemid, $newuserid); self::set_backup_ids_record($restoreid, 'user', $recuser->itemid, $newuserid);
// Let's create the user context and annotate it (we need it for sure at least for files) // Let's create the user context and annotate it (we need it for sure at least for files)
$newuserctxid = get_context_instance(CONTEXT_USER, $newuserid)->id; // but for deleted users that don't have a context anymore (MDL-30192). We are done for them
self::set_backup_ids_record($restoreid, 'context', $recuser->parentitemid, $newuserctxid); // and nothing else (custom fields, prefs, tags, files...) will be created.

if (empty($user->deleted)) {
// Process custom fields $newuserctxid = $user->deleted ? 0 : get_context_instance(CONTEXT_USER, $newuserid)->id;
if (isset($user->custom_fields)) { // if present in backup self::set_backup_ids_record($restoreid, 'context', $recuser->parentitemid, $newuserctxid);
foreach($user->custom_fields['custom_field'] as $udata) {
$udata = (object)$udata; // Process custom fields
// If the profile field has data and the profile shortname-datatype is defined in server if (isset($user->custom_fields)) { // if present in backup
if ($udata->field_data) { foreach($user->custom_fields['custom_field'] as $udata) {
if ($field = $DB->get_record('user_info_field', array('shortname'=>$udata->field_name, 'datatype'=>$udata->field_type))) { $udata = (object)$udata;
/// Insert the user_custom_profile_field // If the profile field has data and the profile shortname-datatype is defined in server
$rec = new stdClass(); if ($udata->field_data) {
$rec->userid = $newuserid; if ($field = $DB->get_record('user_info_field', array('shortname'=>$udata->field_name, 'datatype'=>$udata->field_type))) {
$rec->fieldid = $field->id; /// Insert the user_custom_profile_field
$rec->data = $udata->field_data; $rec = new stdClass();
$DB->insert_record('user_info_data', $rec); $rec->userid = $newuserid;
$rec->fieldid = $field->id;
$rec->data = $udata->field_data;
$DB->insert_record('user_info_data', $rec);
}
} }
} }
} }
}


// Process tags // Process tags
if (!empty($CFG->usetags) && isset($user->tags)) { // if enabled in server and present in backup if (!empty($CFG->usetags) && isset($user->tags)) { // if enabled in server and present in backup
$tags = array(); $tags = array();
foreach($user->tags['tag'] as $usertag) { foreach($user->tags['tag'] as $usertag) {
$usertag = (object)$usertag; $usertag = (object)$usertag;
$tags[] = $usertag->rawname; $tags[] = $usertag->rawname;
}
tag_set('user', $newuserid, $tags);
} }
tag_set('user', $newuserid, $tags);
}


// Process preferences // Process preferences
if (isset($user->preferences)) { // if present in backup if (isset($user->preferences)) { // if present in backup
foreach($user->preferences['preference'] as $preference) { foreach($user->preferences['preference'] as $preference) {
$preference = (object)$preference; $preference = (object)$preference;
// Prepare the record and insert it // Prepare the record and insert it
$preference->userid = $newuserid; $preference->userid = $newuserid;
$status = $DB->insert_record('user_preferences', $preference); $status = $DB->insert_record('user_preferences', $preference);
}
} }
}


// Create user files in pool (profile, icon, private) by context // Create user files in pool (profile, icon, private) by context
restore_dbops::send_files_to_pool($basepath, $restoreid, 'user', 'icon', $recuser->parentitemid, $userid); restore_dbops::send_files_to_pool($basepath, $restoreid, 'user', 'icon', $recuser->parentitemid, $userid);
restore_dbops::send_files_to_pool($basepath, $restoreid, 'user', 'profile', $recuser->parentitemid, $userid); restore_dbops::send_files_to_pool($basepath, $restoreid, 'user', 'profile', $recuser->parentitemid, $userid);
if ($userfiles) { // private files only if enabled in settings if ($userfiles) { // private files only if enabled in settings
restore_dbops::send_files_to_pool($basepath, $restoreid, 'user', 'private', $recuser->parentitemid, $userid); restore_dbops::send_files_to_pool($basepath, $restoreid, 'user', 'private', $recuser->parentitemid, $userid);
} }


}
} }
$rs->close(); $rs->close();
} }
Expand Down

0 comments on commit f99bd07

Please sign in to comment.