From 9e56dd25d3fa210562b6d14998d52d3d174744b1 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Wed, 30 Jan 2008 01:10:57 +0000 Subject: [PATCH] Now user profile fileds and user tags are included in backups. Part of MDL-6856 ; merged from 19_STABLE --- backup/backuplib.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/backup/backuplib.php b/backup/backuplib.php index 3b366a4d8e..7a1d5d9f70 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -1147,6 +1147,7 @@ function backup_user_info ($bf,$preferences) { global $CFG; + require_once ($CFG->dirroot.'/tag/lib.php'); $status = true; @@ -1249,6 +1250,43 @@ //End ROLES tag fwrite ($bf,end_tag("ROLES",4,true)); + //Check if we have custom profile fields to backup + if ($cpfields = get_records_sql("SELECT uif.shortname, uif.datatype, uid.data + FROM {$CFG->prefix}user_info_field uif, + {$CFG->prefix}user_info_data uid + WHERE uif.id = uid.fieldid + AND uid.userid = $user->id")) { + //Start USER_CUSTOM_PROFILE_FIELDS tag + fwrite ($bf,start_tag("USER_CUSTOM_PROFILE_FIELDS",4,true)); + //Write custom profile fields + foreach ($cpfields as $cpfield) { + fwrite ($bf,start_tag("USER_CUSTOM_PROFILE_FIELD",5,true)); + fwrite ($bf,full_tag("FIELD_NAME",6,false,$cpfield->shortname)); + fwrite ($bf,full_tag("FIELD_TYPE",6,false,$cpfield->datatype)); + fwrite ($bf,full_tag("FIELD_DATA",6,false,$cpfield->data)); + fwrite ($bf,end_tag("USER_CUSTOM_PROFILE_FIELD",5,true)); + } + //End USER_CUSTOM_PROFILE_FIELDS tag + fwrite ($bf,end_tag("USER_CUSTOM_PROFILE_FIELDS",4,true)); + } + + //Check if we have user tags to backup + if (!empty($CFG->usetags)) { + if ($tags = get_item_tags('user', $user->id)) { //This return them ordered by default + //Start USER_TAGS tag + fwrite ($bf,start_tag("USER_TAGS",4,true)); + //Write user tags fields + foreach ($tags as $tag) { + fwrite ($bf,start_tag("USER_TAG",5,true)); + fwrite ($bf,full_tag("NAME",6,false,$tag->name)); + fwrite ($bf,full_tag("RAWNAME",6,false,$tag->rawname)); + fwrite ($bf,end_tag("USER_TAG",5,true)); + } + //End USER_TAGS tag + fwrite ($bf,end_tag("USER_TAGS",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 -- 2.39.5