function webscheme_restore_mods($mod, $restore) { global $CFG; $status = true; //Get record from backup_ids $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id); if ($data) { //Now get completed xmlized object $info = $data->info; // (STOLEN FROM CHOICE) if necessary, write to restorelog and adjust date/time fields if ($restore->course_startdateoffset) { restore_log_date_changes('Webscheme', $restore, $info['MOD']['#'], array('TIMEOPEN', 'TIMECLOSE')); } //traverse_xmlize($info); //Debug //print_object ($GLOBALS['traverse_array']); //Debug //$GLOBALS['traverse_array']=""; //Debug //Now, build the WEBSCHEME record structure $webscheme->course = $restore->course_id; $webscheme->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $webscheme->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']); $webscheme->introformat = backup_todb($info['MOD']['#']['INTROFORMAT']['0']['#']); $webscheme->timecreated = $info['MOD']['#']['TIMECREATED']['0']['#']; $webscheme->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#']; $ws_settings = $info['MOD']['#']['WS_SETTINGS']['0']['#']; $ws_settings = backup_todb(html_entity_decode($ws_settings)); $webscheme->ws_settings = $ws_settings; $ws_events = $info['MOD']['#']['WS_EVENTS']['0']['#']; $ws_events = backup_todb(html_entity_decode($ws_events)); $webscheme->ws_events = $ws_events; $ws_initexpr = $info['MOD']['#']['WS_INITEXPR']['0']['#']; $ws_initexpr = backup_todb(html_entity_decode($ws_initexpr)); $webscheme->ws_initexpr = $ws_initexpr; $ws_loadurls = $info['MOD']['#']['WS_LOADURLS']['0']['#']; $ws_loadurls = backup_todb(html_entity_decode($ws_loadurls)); $webscheme->ws_loadurls = $ws_loadurls; $ws_html = $info['MOD']['#']['WS_HTML']['0']['#']; $ws_html = backup_todb(html_entity_decode($ws_html)); $webscheme->ws_html = $ws_html; //The structure is equal to the db, so insert the webscheme // ah? Do we need to addslashes or anything? $newid = insert_record("webscheme", $webscheme); //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "webscheme") . " \"" . format_string($webscheme->name, true) . "\"</li>"; } backup_flush(300); if ($newid) { //We have the newid, update backup_ids backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid); } else { $status = false; } } else { $status = false; } return $status; }
function wwassignment_restore_mods($mod, $restore) { global $CFG; $status = true; //error_log("mod id ".$mod->id); // if ($mod->id == "66666") { // $wwlinkdata = backup_getid($restore->backup_unique_code,"wwassignment_bridge","wwassignment_bridge"); // error_log("wwlink data ".print_r($wwlinkdata, true )); // return $status; // } //Get record from backup_ids $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id); if ($data) { //Now get completed xmlized object $info = $data->info; //if necessary, write to restorelog and adjust date/time fields if ($restore->course_startdateoffset) { //restore_log_date_changes('Wwassignment', $restore, $info['MOD']['#'], array('TIMEDUE', 'TIMEAVAILABLE')); } //traverse_xmlize($info); //Debug //print_object ($GLOBALS['traverse_array']); //Debug //$GLOBALS['traverse_array']=""; //Debug //Now, build the ASSIGNMENT record structure $wwassignment->course = $restore->course_id; $wwassignment->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $wwassignment->description = backup_todb($info['MOD']['#']['DESCRIPTION']['0']['#']); $wwassignment->webwork_set = backup_todb($info['MOD']['#']['WEBWORK_SET']['0']['#']); $wwassignment->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); //The structure is equal to the db, so insert the assignment $newid = insert_record("wwassignment", $wwassignment); //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "wwassignment") . " \"" . format_string(stripslashes($wwassignment->name), true) . "\"</li>"; } backup_flush(300); if ($newid) { //We have the newid, update backup_ids backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid); } else { $status = false; } } else { $status = false; } //error_log("mod id is ".print_r($mod,true)); return $status; }
function restore($old_question_id, $new_question_id, $info, $restore) { global $DB; $status = true; //Get the truefalse array if (array_key_exists('TRUEFALSE', $info['#'])) { $truefalses = $info['#']['TRUEFALSE']; } else { $truefalses = array(); } //Iterate over truefalse for ($i = 0; $i < sizeof($truefalses); $i++) { $tru_info = $truefalses[$i]; //Now, build the question_truefalse record structure $truefalse = new stdClass(); $truefalse->question = $new_question_id; $truefalse->trueanswer = stripslashes(backup_todb($tru_info['#']['TRUEANSWER']['0']['#'])); $truefalse->falseanswer = stripslashes(backup_todb($tru_info['#']['FALSEANSWER']['0']['#'])); ////We have to recode the trueanswer field $answer = backup_getid($restore->backup_unique_code, "question_answers", $truefalse->trueanswer); if ($answer) { $truefalse->trueanswer = $answer->new_id; } ////We have to recode the falseanswer field $answer = backup_getid($restore->backup_unique_code, "question_answers", $truefalse->falseanswer); if ($answer) { $truefalse->falseanswer = $answer->new_id; } //The structure is equal to the db, so insert the question_truefalse $newid = $DB->insert_record("question_truefalse", $truefalse); //Do some output if (($i + 1) % 50 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 1000 == 0) { echo "<br />"; } } backup_flush(300); } if (!$newid) { $status = false; } } return $status; }
function adobeconnect_pages_restore_mods($adobeconnectid, $info, $restore) { global $CFG; $status = true; //Get the lesson_elements array $meetgroups = $info['MOD']['#']['MEETINGGROUPS']['0']['#']['MEETINGGROUP']; //Iterate over lesson pages (they are held in their logical order) $prevpageid = 0; for ($i = 0; $i < sizeof($meetgroups); $i++) { $meetgroup_info = $meetgroups[$i]; //traverse_xmlize($ele_info); //Debug //print_object ($GLOBALS['traverse_array']); //Debug //$GLOBALS['traverse_array']=""; //Debug //Now, build the lesson_pages record structure $oldid = backup_todb($meetgroup_info['#']['ID']['0']['#']); $meeting = new stdClass(); $meeting->instanceid = $adobeconnectid; $meeting->meetingscoid = backup_todb($meetgroup_info['#']['MEETINGSCOID']['0']['#']); $meeting->groupid = backup_todb($meetgroup_info['#']['GROUPID']['0']['#']); //We have to recode the groupid field $group = restore_group_getid($restore, $meeting->groupid); if ($group) { $meeting->groupid = $group->new_id; } //The structure is equal to the db, so insert the certificate_issue $newid = insert_record("adobeconnect_meeting_groups", $meeting); //Do some output if (($i + 1) % 10 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 200 == 0) { echo "<br/>"; } } backup_flush(300); } if ($newid) { //We have the newid, update backup_ids (restore logs will use it!!) backup_putid($restore->backup_unique_code, "adobeconnect_meeting_groups", $oldid, $newid); } else { $status = false; } } return $status; }
/** * restores a complete module * @param object $mod * @param object $restore * @uses $CFG */ function poodllpairwork_restore_mods($mod, $restore) { global $CFG; $status = true; //Get record from backup_ids $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id); if ($data) { //Now get completed xmlized object $info = $data->info; //traverse_xmlize($info); //Debug //print_object ($GLOBALS['traverse_array']); //Debug //$GLOBALS['traverse_array']=""; //Debug //Now, build the poodllpairwork record structure $poodllpairwork->course = $restore->course_id; $poodllpairwork->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $poodllpairwork->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']); $poodllpairwork->introa = backup_todb($info['MOD']['#']['INTROA']['0']['#']); $poodllpairwork->introb = backup_todb($info['MOD']['#']['INTROB']['0']['#']); $poodllpairwork->sessiontype = backup_todb($info['MOD']['#']['SESSIONTYPE']['0']['#']); $poodllpairwork->introformat = backup_todb($info['MOD']['#']['INTROFORMAT']['0']['#']); $poodllpairwork->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']); $poodllpairwork->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); //The structure is equal to the db, so insert the poodllpairwork $newid = insert_record('poodllpairwork', $poodllpairwork); //Do some output echo '<ul><li>' . get_string('modulename', 'poodllpairwork') . " \"" . $poodllpairwork->name . "\"<br>"; backup_flush(300); if ($newid) { //We have the newid, update backup_ids backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid); //Now restore files $status = $status && poodllpairwork_restore_files($mod->id, $newid, $restore); } else { $status = false; } //Finalize ul echo '</ul>'; } else { $status = false; } return $status; }
function bigbluebutton_restore_mods($mod, $restore) { global $CFG; $status = true; //Get record from backup_ids $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id); if ($data) { //Now get completed xmlized object $info = $data->info; //traverse_xmlize($info); //Debug //print_object ($GLOBALS['traverse_array']); //Debug //$GLOBALS['traverse_array']=""; //Debug //Now, build the LABEL record structure $bigbluebutton->course = $restore->course_id; $bigbluebutton->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $bigbluebutton->moderatorpass = backup_todb($info['MOD']['#']['MODERATORPASS']['0']['#']); $bigbluebutton->viewerpass = backup_todb($info['MOD']['#']['VIEWERPASS']['0']['#']); $bigbluebutton->wait = backup_todb($info['MOD']['#']['WAIT']['0']['#']); $bigbluebutton->meetingid = backup_todb($info['MOD']['#']['MEETINGID']['0']['#']); $bigbluebutton->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); //The structure is equal to the db, so insert the bigbluebutton $newid = insert_record("bigbluebutton", $bigbluebutton); //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "bigbluebutton") . " \"" . format_string(stripslashes($bigbluebutton->name), true) . "\"</li>"; } backup_flush(300); if ($newid) { //We have the newid, update backup_ids backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid); } else { $status = false; } } else { $status = false; } return $status; }
function label_decode_content_links_caller($restore) { global $CFG, $DB; $status = true; if ($labels = $DB->get_records('label', array('course' => $restore->course_id), '', "id,content")) { $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($labels as $label) { //Increment counter $i++; $content = $label->intro; $result = restore_decode_content_links_worker($content, $restore); if ($result != $content) { //Update record $label->intro = $result; $status = $DB->update_record("label", $label); if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } //Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } return $status; }
function skype_decode_content_links_caller($restore) { global $CFG; $status = true; if ($skypes = get_records_sql("SELECT l.id, l.participants\n FROM {$CFG->prefix}skype l\n WHERE l.course = {$restore->course_id}")) { $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($skypes as $skype) { //Increment counter $i++; $participants = $skype->participants; $result = restore_decode_content_links_worker($participants, $restore); if ($result != $participants) { //Update record $skype->participants = addslashes($result); $status = update_record("skype", $skype); if ($CFG->debug > 7) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } //Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } return $status; }
function wwassignment_restore_mods($mod, $restore) { global $CFG; $status = true; //Get record from backup_ids $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id); if ($data) { //Now get completed xmlized object $info = $data->info; //traverse_xmlize($info); //Debug //print_object ($GLOBALS['traverse_array']); //Debug //$GLOBALS['traverse_array']=""; //Debug //Now, build the QUIZ record structure $wwassignment = new stdClass(); $wwassignment->course = $restore->course_id; $wwassignment->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $wwassignment->description = backup_todb($info['MOD']['#']['DESCRIPTION']['0']['#']); $wwassignment->webwork_set = backup_todb($info['MOD']['#']['WEBWORK_SET']['0']['#']); //The structure is equal to the db, so insert the quiz $newid = insert_record("wwassignment", $wwassignment); //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "wwassignment") . " \"" . format_string(stripslashes($wwassignment->name), true) . "\"</li>"; } backup_flush(300); if ($newid) { //We have the newid, update backup_ids backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid); } else { $status = false; } } else { $status = false; } return $status; }
function label_decode_content_links_caller($restore) { global $CFG; $status = true; if ($labels = get_records_sql("SELECT l.id, l.content\n FROM {$CFG->prefix}label l\n WHERE l.course = {$restore->course_id}")) { $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($labels as $label) { //Increment counter $i++; $content = $label->content; $result = restore_decode_content_links_worker($content, $restore); if ($result != $content) { //Update record $label->content = addslashes($result); $status = update_record("label", $label); if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } //Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } return $status; }
function backup_copy_user_files($preferences) { global $CFG; $status = true; //First we check that "user_files" exists and create it if necessary //in temp/backup/$backup_code dir $status = check_and_create_user_files_dir($preferences->backup_unique_code); //now get a list of users that we need for this backup. $backup_users = get_recordset_select("backup_ids", "backup_code='{$preferences->backup_unique_code}' AND table_name='user'", "", "id, old_id"); while ($user = rs_fetch_next_record($backup_users)) { //If this user's directory exists, copy it $userdir = make_user_directory($user->old_id, true); if (check_dir_exists($userdir)) { //first remove dirroot so we can split out the folders. $parts = explode('/', str_replace($CFG->dataroot . '/user/', '', $userdir)); $status = true; if (is_array($parts)) { $group = $parts[0]; $userid = $parts[1]; // Create group dir first $status = check_dir_exists("{$CFG->dataroot}/temp/backup/{$preferences->backup_unique_code}/user_files/" . $group, true); } $status = $status && backup_copy_file($userdir, "{$CFG->dataroot}/temp/backup/{$preferences->backup_unique_code}/user_files/{$group}/{$user->old_id}"); } //Do some output backup_flush(30); } rs_close($backup_users); return $status; }
/** * Restores the data in the question * * This is used in question/restorelib.php */ function restore($old_question_id, $new_question_id, $info, $restore) { $status = true; //Get the webworks array $webworks = $info['#']['WEBWORK']; //Iterate over webworks for ($i = 0; $i < sizeof($webworks); $i++) { $webwork_info = $webworks[$i]; //Now, build the question_webwork record structure $webwork = new stdClass(); $webwork->question = $new_question_id; $webwork->codecheck = backup_todb($webwork_info['#']['CODECHECK']['0']['#']); $webwork->code = backup_todb($webwork_info['#']['CODE']['0']['#']); $webwork->grading = backup_todb($webwork_info['#']['GRADING']['0']['#']); //The structure is equal to the db, so insert the question_shortanswer $newid = insert_record("question_webwork", $webwork); //Do some output if (($i + 1) % 50 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 1000 == 0) { echo "<br />"; } } backup_flush(300); } if (!$newid) { $status = false; } } return $status; }
function restore($old_question_id, $new_question_id, $info, $restore) { $status = true; //Get the calculated-s array $calculateds = $info['#']['CALCULATED']; //Iterate over calculateds for ($i = 0; $i < sizeof($calculateds); $i++) { $cal_info = $calculateds[$i]; //traverse_xmlize($cal_info); //Debug //print_object ($GLOBALS['traverse_array']); //Debug //$GLOBALS['traverse_array']=""; //Debug //Now, build the question_calculated record structure $calculated->question = $new_question_id; $calculated->answer = backup_todb($cal_info['#']['ANSWER']['0']['#']); $calculated->tolerance = backup_todb($cal_info['#']['TOLERANCE']['0']['#']); $calculated->tolerancetype = backup_todb($cal_info['#']['TOLERANCETYPE']['0']['#']); $calculated->correctanswerlength = backup_todb($cal_info['#']['CORRECTANSWERLENGTH']['0']['#']); $calculated->correctanswerformat = backup_todb($cal_info['#']['CORRECTANSWERFORMAT']['0']['#']); ////We have to recode the answer field $answer = backup_getid($restore->backup_unique_code, "question_answers", $calculated->answer); if ($answer) { $calculated->answer = $answer->new_id; } //The structure is equal to the db, so insert the question_calculated $newid = insert_record("question_calculated", $calculated); //Do some output if (($i + 1) % 50 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 1000 == 0) { echo "<br />"; } } backup_flush(300); } //Now restore numerical_units $status = question_restore_numerical_units($old_question_id, $new_question_id, $cal_info, $restore); //Now restore dataset_definitions if ($status && $newid) { $status = question_restore_dataset_definitions($old_question_id, $new_question_id, $cal_info, $restore); } if (!$newid) { $status = false; } } return $status; }
function endElementUsers($parser, $tagName) { global $CFG; //Check if we are into USERS zone if ($this->tree[3] == "USERS") { //if (trim($this->content)) //Debug // echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug //echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n"; //Debug //Dependig of different combinations, do different things if ($this->level == 4) { switch ($tagName) { case "USER": //Increment counter $this->counter++; //Save to db, only save if record not already exist // if there already is an new_id for this entry, just use that new_id? $newuser = backup_getid($this->preferences->backup_unique_code, "user", $this->info->tempuser->id); if (isset($newuser->new_id)) { $newid = $newuser->new_id; } else { $newid = null; } backup_putid($this->preferences->backup_unique_code, "user", $this->info->tempuser->id, $newid, $this->info->tempuser); //Do some output if ($this->counter % 10 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if ($this->counter % 200 == 0) { echo "<br />"; } } backup_flush(300); } //Delete temp obejct unset($this->info->tempuser); break; } } if ($this->level == 5) { switch ($tagName) { case "ID": $this->info->users[$this->getContents()] = $this->getContents(); $this->info->tempuser->id = $this->getContents(); break; case "AUTH": $this->info->tempuser->auth = $this->getContents(); break; case "CONFIRMED": $this->info->tempuser->confirmed = $this->getContents(); break; case "POLICYAGREED": $this->info->tempuser->policyagreed = $this->getContents(); break; case "DELETED": $this->info->tempuser->deleted = $this->getContents(); break; case "USERNAME": $this->info->tempuser->username = $this->getContents(); break; case "PASSWORD": $this->info->tempuser->password = $this->getContents(); break; case "IDNUMBER": $this->info->tempuser->idnumber = $this->getContents(); break; case "FIRSTNAME": $this->info->tempuser->firstname = $this->getContents(); break; case "LASTNAME": $this->info->tempuser->lastname = $this->getContents(); break; case "EMAIL": $this->info->tempuser->email = $this->getContents(); break; case "EMAILSTOP": $this->info->tempuser->emailstop = $this->getContents(); break; case "ICQ": $this->info->tempuser->icq = $this->getContents(); break; case "SKYPE": $this->info->tempuser->skype = $this->getContents(); break; case "AIM": $this->info->tempuser->aim = $this->getContents(); break; case "YAHOO": $this->info->tempuser->yahoo = $this->getContents(); break; case "MSN": $this->info->tempuser->msn = $this->getContents(); break; case "PHONE1": $this->info->tempuser->phone1 = $this->getContents(); break; case "PHONE2": $this->info->tempuser->phone2 = $this->getContents(); break; case "INSTITUTION": $this->info->tempuser->institution = $this->getContents(); break; case "DEPARTMENT": $this->info->tempuser->department = $this->getContents(); break; case "ADDRESS": $this->info->tempuser->address = $this->getContents(); break; case "CITY": $this->info->tempuser->city = $this->getContents(); break; case "COUNTRY": $this->info->tempuser->country = $this->getContents(); break; case "LANG": $this->info->tempuser->lang = $this->getContents(); break; case "THEME": $this->info->tempuser->theme = $this->getContents(); break; case "TIMEZONE": $this->info->tempuser->timezone = $this->getContents(); break; case "FIRSTACCESS": $this->info->tempuser->firstaccess = $this->getContents(); break; case "LASTACCESS": $this->info->tempuser->lastaccess = $this->getContents(); break; case "LASTLOGIN": $this->info->tempuser->lastlogin = $this->getContents(); break; case "CURRENTLOGIN": $this->info->tempuser->currentlogin = $this->getContents(); break; case "LASTIP": $this->info->tempuser->lastip = $this->getContents(); break; case "SECRET": $this->info->tempuser->secret = $this->getContents(); break; case "PICTURE": $this->info->tempuser->picture = $this->getContents(); break; case "URL": $this->info->tempuser->url = $this->getContents(); break; case "DESCRIPTION": $this->info->tempuser->description = $this->getContents(); break; case "MAILFORMAT": $this->info->tempuser->mailformat = $this->getContents(); break; case "MAILDIGEST": $this->info->tempuser->maildigest = $this->getContents(); break; case "MAILDISPLAY": $this->info->tempuser->maildisplay = $this->getContents(); break; case "HTMLEDITOR": $this->info->tempuser->htmleditor = $this->getContents(); break; case "AJAX": $this->info->tempuser->ajax = $this->getContents(); break; case "AUTOSUBSCRIBE": $this->info->tempuser->autosubscribe = $this->getContents(); break; case "TRACKFORUMS": $this->info->tempuser->trackforums = $this->getContents(); break; case "MNETHOSTURL": $this->info->tempuser->mnethosturl = $this->getContents(); break; case "TIMEMODIFIED": $this->info->tempuser->timemodified = $this->getContents(); break; default: break; } } if ($this->level == 6 && $this->tree[5] != "ROLES_ASSIGNMENTS" && $this->tree[5] != "ROLES_OVERRIDES") { switch ($tagName) { case "ROLE": //We've finalized a role, get it $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; case "USER_CUSTOM_PROFILE_FIELD": //We've finalized a user_custom_profile_field, get it $this->info->tempuser->user_custom_profile_fields[] = $this->info->tempusercustomprofilefield; unset($this->info->tempusercustomprofilefield); break; case "USER_TAG": //We've finalized a user_tag, get it $this->info->tempuser->user_tags[] = $this->info->tempusertag; unset($this->info->tempusertag); break; default: break; } } if ($this->level == 7 && $this->tree[5] != "ROLES_ASSIGNMENTS" && $this->tree[5] != "ROLES_OVERRIDES") { /// If we are reading roles if ($this->tree[6] == 'ROLE') { switch ($tagName) { case "TYPE": $this->info->temprole->type = $this->getContents(); break; case "AUTHORITY": $this->info->temprole->authority = $this->getContents(); break; case "TEA_ROLE": $this->info->temprole->tea_role = $this->getContents(); break; case "EDITALL": $this->info->temprole->editall = $this->getContents(); break; case "TIMESTART": $this->info->temprole->timestart = $this->getContents(); break; case "TIMEEND": $this->info->temprole->timeend = $this->getContents(); break; case "TIMEMODIFIED": $this->info->temprole->timemodified = $this->getContents(); break; case "TIMESTART": $this->info->temprole->timestart = $this->getContents(); break; case "TIMEEND": $this->info->temprole->timeend = $this->getContents(); break; case "TIME": $this->info->temprole->time = $this->getContents(); break; case "TIMEACCESS": $this->info->temprole->timeaccess = $this->getContents(); break; case "ENROL": $this->info->temprole->enrol = $this->getContents(); break; default: break; } /// If we are reading user_preferences } else { if ($this->tree[6] == 'USER_PREFERENCE') { switch ($tagName) { case "NAME": $this->info->tempuserpreference->name = $this->getContents(); break; case "VALUE": $this->info->tempuserpreference->value = $this->getContents(); break; default: break; } /// If we are reading user_custom_profile_fields } else { if ($this->tree[6] == 'USER_CUSTOM_PROFILE_FIELD') { switch ($tagName) { case "FIELD_NAME": $this->info->tempusercustomprofilefield->field_name = $this->getContents(); break; case "FIELD_TYPE": $this->info->tempusercustomprofilefield->field_type = $this->getContents(); break; case "FIELD_DATA": $this->info->tempusercustomprofilefield->field_data = $this->getContents(); break; default: break; } /// If we are reading user_tags } else { if ($this->tree[6] == 'USER_TAG') { switch ($tagName) { case "NAME": $this->info->tempusertag->name = $this->getContents(); break; case "RAWNAME": $this->info->tempusertag->rawname = $this->getContents(); break; default: break; } } } } } } if ($this->tree[5] == "ROLES_ASSIGNMENTS") { if ($this->level == 7) { switch ($tagName) { case "NAME": $this->info->tempname = $this->getContents(); break; case "SHORTNAME": $this->info->tempshortname = $this->getContents(); break; case "ID": $this->info->tempid = $this->getContents(); // temp roleid break; } } if ($this->level == 9) { switch ($tagName) { case "USERID": $this->info->tempuser->roleassignments[$this->info->tempid]->name = $this->info->tempname; $this->info->tempuser->roleassignments[$this->info->tempid]->shortname = $this->info->tempshortname; $this->info->tempuserid = $this->getContents(); $this->info->tempuser->roleassignments[$this->info->tempid]->assignments[$this->info->tempuserid]->userid = $this->getContents(); break; case "HIDDEN": $this->info->tempuser->roleassignments[$this->info->tempid]->assignments[$this->info->tempuserid]->hidden = $this->getContents(); break; case "TIMESTART": $this->info->tempuser->roleassignments[$this->info->tempid]->assignments[$this->info->tempuserid]->timestart = $this->getContents(); break; case "TIMEEND": $this->info->tempuser->roleassignments[$this->info->tempid]->assignments[$this->info->tempuserid]->timeend = $this->getContents(); break; case "TIMEMODIFIED": $this->info->tempuser->roleassignments[$this->info->tempid]->assignments[$this->info->tempuserid]->timemodified = $this->getContents(); break; case "MODIFIERID": $this->info->tempuser->roleassignments[$this->info->tempid]->assignments[$this->info->tempuserid]->modifierid = $this->getContents(); break; case "ENROL": $this->info->tempuser->roleassignments[$this->info->tempid]->assignments[$this->info->tempuserid]->enrol = $this->getContents(); break; case "SORTORDER": $this->info->tempuser->roleassignments[$this->info->tempid]->assignments[$this->info->tempuserid]->sortorder = $this->getContents(); break; } } } /// ends role_assignments if ($this->tree[5] == "ROLES_OVERRIDES") { if ($this->level == 7) { switch ($tagName) { case "NAME": $this->info->tempname = $this->getContents(); break; case "SHORTNAME": $this->info->tempshortname = $this->getContents(); break; case "ID": $this->info->tempid = $this->getContents(); // temp roleid break; } } if ($this->level == 9) { switch ($tagName) { case "NAME": $this->info->tempuser->roleoverrides[$this->info->tempid]->name = $this->info->tempname; $this->info->tempuser->roleoverrides[$this->info->tempid]->shortname = $this->info->tempshortname; $this->info->tempname = $this->getContents(); // change to name of capability $this->info->tempuser->roleoverrides[$this->info->tempid]->overrides[$this->info->tempname]->name = $this->getContents(); break; case "PERMISSION": $this->info->tempuser->roleoverrides[$this->info->tempid]->overrides[$this->info->tempname]->permission = $this->getContents(); break; case "TIMEMODIFIED": $this->info->tempuser->roleoverrides[$this->info->tempid]->overrides[$this->info->tempname]->timemodified = $this->getContents(); break; case "MODIFIERID": $this->info->tempuser->roleoverrides[$this->info->tempid]->overrides[$this->info->tempname]->modifierid = $this->getContents(); break; } } } /// ends role_overrides } // closes if this->tree[3]=="users" //Stop parsing if todo = USERS and tagName = USERS (en of the tag, of course) //Speed up a lot (avoid parse all) if ($tagName == "USERS" and $this->level == 3) { $this->finished = true; $this->counter = 0; } //Clear things $this->tree[$this->level] = ""; $this->level--; $this->content = ""; }
function econsole_decode_content_links_caller($restore) { global $CFG; $status = true; if ($econsoles = get_records_sql("SELECT e.id, e.content, e.url1, e.url2, e.url3, e.url4, e.url5, e.url6 \r\n FROM {$CFG->prefix}econsole e\r\n WHERE e.course = {$restore->course_id}")) { //Iterate over each econsole->intro $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($econsoles as $econsole) { //Increment counter $i++; $content1 = $econsole->content; $content2 = $econsole->url1; $content3 = $econsole->url2; $content4 = $econsole->url3; $content5 = $econsole->url4; $content6 = $econsole->url5; $content7 = $econsole->url6; $result1 = restore_decode_content_links_worker($content1, $restore); $result2 = restore_decode_content_links_worker($content2, $restore); $result3 = restore_decode_content_links_worker($content3, $restore); $result4 = restore_decode_content_links_worker($content4, $restore); $result5 = restore_decode_content_links_worker($content5, $restore); $result6 = restore_decode_content_links_worker($content6, $restore); $result7 = restore_decode_content_links_worker($content7, $restore); if ($result1 != $content1 || $result2 != $content2 || $result3 != $content3 || $result4 != $content4 || $result5 != $content5 || $result6 != $content6 || $result7 != $content7) { //Update record $econsole->content = addslashes($result1); $econsole->url1 = addslashes($result2); $econsole->url2 = addslashes($result3); $econsole->url3 = addslashes($result4); $econsole->url4 = addslashes($result5); $econsole->url5 = addslashes($result6); $econsole->url6 = addslashes($result7); $status = update_record("econsole", $econsole); if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content1) . '<br />changed to<br />' . s($result1) . '<hr /><br />'; echo '<br /><hr />' . s($content2) . '<br />changed to<br />' . s($result2) . '<hr /><br />'; echo '<br /><hr />' . s($content3) . '<br />changed to<br />' . s($result3) . '<hr /><br />'; echo '<br /><hr />' . s($content4) . '<br />changed to<br />' . s($result4) . '<hr /><br />'; echo '<br /><hr />' . s($content5) . '<br />changed to<br />' . s($result5) . '<hr /><br />'; echo '<br /><hr />' . s($content6) . '<br />changed to<br />' . s($result6) . '<hr /><br />'; echo '<br /><hr />' . s($content7) . '<br />changed to<br />' . s($result7) . '<hr /><br />'; } } } //Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } return $status; }
function forum_decode_content_links_caller($restore) { global $CFG, $DB, $DB; $status = true; //Process every POST (message) in the course if ($posts = $DB->get_records_sql("SELECT p.id, p.message\n FROM {forum_posts} p,\n {forum_discussions} d\n WHERE d.course = ? AND\n p.discussion = d.id", array($restore->course_id))) { //Iterate over each post->message $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($posts as $post) { //Increment counter $i++; $content = $post->message; $result = restore_decode_content_links_worker($content, $restore); if ($result != $content) { //Update record $post->message = $result; $status = $DB->update_record("forum_posts", $post); if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } //Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } //Process every FORUM (intro) in the course if ($forums = $DB->get_records('forum', array('course' => $restore->course_id), '', "id,intro")) { //Iterate over each forum->intro $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($forums as $forum) { //Increment counter $i++; $content = $forum->intro; $result = restore_decode_content_links_worker($content, $restore); if ($result != $content) { //Update record $forum->intro = $result; $status = $DB->update_record("forum", $forum); if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } //Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } return $status; }
function mail_decode_content_links_caller($restore) { global $CFG; $status = true; //Process every Mail in the course if ($mails = get_records_sql("SELECT m.id, m.summary\r\n FROM {$CFG->prefix}mail m\r\n WHERE m.course = {$restore->course_id}")) { //Iterate over each forum->intro $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($mails as $mail) { //Increment counter $i++; $content_summary = $mail->summary; $result_summary = restore_decode_content_links_worker($content_summary, $restore); if ($result_summary != $content_summary) { //Update record $mail->summary = addslashes($result_summary); $status = update_record("mail", $mail); if ($CFG->debug > 7) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content_summary) . '<br />changed to<br />' . s($result_summary) . '<hr /><br />'; } } } //Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } return $status; }
function wiki_decode_content_links_caller($restore) { global $CFG, $DB; $status = true; //Process every wiki PAGE in the course if ($pages = $DB->get_records_sql("SELECT p.id, p.content\n FROM {wiki_pages} p, {wiki} w\n WHERE w.course = ? AND\n p.wiki = w.id", array($restore->course_id))) { //Iterate over each post->message $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($pages as $page) { //Increment counter $i++; $content = $page->definition; $result = restore_decode_content_links_worker($content, $restore); if ($result != $content) { //Update record $page->content = $result; $status = $DB->update_record("wiki_pages", $page); if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } //Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } //Process every wiki (summary) in the course if ($wikis = $DB->get_records('wiki', array('course' => $restore->course_id), '', "id,summary")) { //Iterate over each wiki->summary $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($wikis as $wiki) { //Increment counter $i++; $content = $wiki->summary; $result = restore_decode_content_links_worker($content, $restore); if ($result != $content) { //Update record $wiki->summary = $result; $status = $DB->update_record("wiki", $wiki); if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } //Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } return $status; }
function restore($old_question_id, $new_question_id, $info, $restore) { global $DB; $status = true; //Get the multichoices array $multichoices = $info['#']['MULTICHOICE']; //Iterate over multichoices for ($i = 0; $i < sizeof($multichoices); $i++) { $mul_info = $multichoices[$i]; //Now, build the question_multichoice record structure $multichoice = new stdClass(); $multichoice->question = $new_question_id; $multichoice->layout = backup_todb($mul_info['#']['LAYOUT']['0']['#']); $multichoice->answers = stripslashes(backup_todb($mul_info['#']['ANSWERS']['0']['#'])); $multichoice->single = backup_todb($mul_info['#']['SINGLE']['0']['#']); $multichoice->shuffleanswers = isset($mul_info['#']['SHUFFLEANSWERS']['0']['#']) ? backup_todb($mul_info['#']['SHUFFLEANSWERS']['0']['#']) : ''; if (array_key_exists("CORRECTFEEDBACK", $mul_info['#'])) { $multichoice->correctfeedback = backup_todb($mul_info['#']['CORRECTFEEDBACK']['0']['#']); } else { $multichoice->correctfeedback = ''; } if (array_key_exists("PARTIALLYCORRECTFEEDBACK", $mul_info['#'])) { $multichoice->partiallycorrectfeedback = backup_todb($mul_info['#']['PARTIALLYCORRECTFEEDBACK']['0']['#']); } else { $multichoice->partiallycorrectfeedback = ''; } if (array_key_exists("INCORRECTFEEDBACK", $mul_info['#'])) { $multichoice->incorrectfeedback = backup_todb($mul_info['#']['INCORRECTFEEDBACK']['0']['#']); } else { $multichoice->incorrectfeedback = ''; } if (array_key_exists("ANSWERNUMBERING", $mul_info['#'])) { $multichoice->answernumbering = backup_todb($mul_info['#']['ANSWERNUMBERING']['0']['#']); } else { $multichoice->answernumbering = 'abc'; } //We have to recode the answers field (a list of answers id) //Extracts answer id from sequence $answers_field = ""; $in_first = true; /* $tok = strtok($multichoice->answers,","); while ($tok) { //Get the answer from reader_backup_ids $answer = backup_getid($restore->backup_unique_code,"question_answers",$tok); if ($answer) { if ($in_first) { $answers_field .= $answer->new_id; $in_first = false; } else { $answers_field .= ",".$answer->new_id; } } //check for next $tok = strtok(","); } */ $tok = explode(",", $multichoice->answers); while (list($key, $value) = each($tok)) { if (!empty($value)) { //Get the answer from reader_backup_ids $answer = backup_getid($restore->backup_unique_code, "question", $value); if ($answer) { if ($in_first) { $answer_field .= $answer->new_id; $in_first = false; } else { $answer_field .= "," . $answer->new_id; } } } } //We have the answers field recoded to its new ids $multichoice->answers = $answers_field; //The structure is equal to the db, so insert the question_shortanswer $newid = $DB->insert_record("question_multichoice", $multichoice); //Do some output if (($i + 1) % 50 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 1000 == 0) { echo "<br />"; } } backup_flush(300); } if (!$newid) { $status = false; } } return $status; }
function restore_map($old_question_id, $new_question_id, $info, $restore) { $status = true; //Get the multianswers array $multianswers = $info['#']['MULTIANSWERS']['0']['#']['MULTIANSWER']; //Iterate over multianswers for ($i = 0; $i < sizeof($multianswers); $i++) { $mul_info = $multianswers[$i]; //We need this later $oldid = backup_todb($mul_info['#']['ID']['0']['#']); //Now, build the question_multianswer record structure $multianswer->question = $new_question_id; $multianswer->answers = backup_todb($mul_info['#']['ANSWERS']['0']['#']); $multianswer->positionkey = backup_todb($mul_info['#']['POSITIONKEY']['0']['#']); $multianswer->answertype = backup_todb($mul_info['#']['ANSWERTYPE']['0']['#']); $multianswer->norm = backup_todb($mul_info['#']['NORM']['0']['#']); //If we are in this method is because the question exists in DB, so its //multianswer must exist too. //Now, we are going to look for that multianswer in DB and to create the //mappings in backup_ids to use them later where restoring states (user level). //Get the multianswer from DB (by question and positionkey) $db_multianswer = get_record("question_multianswer", "question", $new_question_id, "positionkey", $multianswer->positionkey); //Do some output if (($i + 1) % 50 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 1000 == 0) { echo "<br />"; } } backup_flush(300); } //We have the database multianswer, so update backup_ids if ($db_multianswer) { //We have the newid, update backup_ids backup_putid($restore->backup_unique_code, "question_multianswer", $oldid, $db_multianswer->id); } else { $status = false; } } return $status; }
function restore($old_question_id, $new_question_id, $info, $restore) { $status = true; //Get the randomsamatchs array $randomsamatchs = $info['#']['RANDOMSAMATCH']; //Iterate over randomsamatchs for ($i = 0; $i < sizeof($randomsamatchs); $i++) { $ran_info = $randomsamatchs[$i]; //Now, build the question_randomsamatch record structure $randomsamatch->question = $new_question_id; $randomsamatch->choose = backup_todb($ran_info['#']['CHOOSE']['0']['#']); //The structure is equal to the db, so insert the question_randomsamatch $newid = insert_record("question_randomsamatch", $randomsamatch); //Do some output if (($i + 1) % 50 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 1000 == 0) { echo "<br />"; } } backup_flush(300); } if (!$newid) { $status = false; } } return $status; }
function restore($old_question_id, $new_question_id, $info, $restore) { $status = true; //Get the shortanswers array $shortanswers = $info['#']['SHORTANSWER']; //Iterate over shortanswers for ($i = 0; $i < sizeof($shortanswers); $i++) { $sho_info = $shortanswers[$i]; //Now, build the question_shortanswer record structure $shortanswer = new stdClass(); $shortanswer->question = $new_question_id; $shortanswer->answers = backup_todb($sho_info['#']['ANSWERS']['0']['#']); $shortanswer->usecase = backup_todb($sho_info['#']['USECASE']['0']['#']); //We have to recode the answers field (a list of answers id) //Extracts answer id from sequence $answers_field = ""; $in_first = true; $tok = strtok($shortanswer->answers, ","); while ($tok) { //Get the answer from backup_ids $answer = backup_getid($restore->backup_unique_code, "question_answers", $tok); if ($answer) { if ($in_first) { $answers_field .= $answer->new_id; $in_first = false; } else { $answers_field .= "," . $answer->new_id; } } //check for next $tok = strtok(","); } //We have the answers field recoded to its new ids $shortanswer->answers = $answers_field; //The structure is equal to the db, so insert the question_shortanswer $newid = insert_record("question_shortanswer", $shortanswer); //Do some output if (($i + 1) % 50 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 1000 == 0) { echo "<br />"; } } backup_flush(300); } if (!$newid) { $status = false; } } return $status; }
/** * Restores the data in a backup file to produce the original question. * * This method is used by question/restorelib.php to restore questions saved in * a backup file to the database. It reads the file directly and writes the information * straight into the database. * * @param $old_question_id the original ID number of the question being restored * @param $new_question_id the new ID number of the question being restored * @param $info the XML parse tree containing all the restore information * @param $restore information about the current restore in progress * * @return bool true if the backup was successful, false if it failed. */ function restore($old_question_id, $new_question_id, $info, $restore) { // Set the devault return value, $status, to be true $status = true; // Get the array of algebra questions $algebraqs = $info['#']['ALGEBRA']; // Iterate over the algebra questions in the backup data for ($i = 0; $i < sizeof($algebraqs); $i++) { $alg_info = $algebraqs[$i]; // Create an empty class to store the question's database record $algebra = new stdClass(); // Fill the algebra specific variables for this object $algebra->questionid = $new_question_id; $algebra->compareby = backup_todb($alg_info['#']['COMPAREBY']['0']['#']); $algebra->variables = backup_todb($alg_info['#']['VARIABLES']['0']['#']); $algebra->nchecks = backup_todb($alg_info['#']['NCHECKS']['0']['#']); $algebra->tolerance = backup_todb($alg_info['#']['TOLERANCE']['0']['#']); $algebra->allowedfuncs = backup_todb($alg_info['#']['ALLOWEDFUNCS']['0']['#']); $algebra->disallow = backup_todb($alg_info['#']['DISALLOW']['0']['#']); $algebra->answerprefix = backup_todb($alg_info['#']['ANSWERPREFIX']['0']['#']); // Create an array to store the new variable IDs $newvarids = array(); // Restore the variables for this question $status = $status && $this->restore_variables($old_question_id, $new_question_id, $alg_info, $restore, $newvarids); // Convert the new variable IDs into a string to place in the question's data structure $algebra->variables = implode(',', $newvarids); // The structure is now equal to the db, so insert the question_algebra object // and check the the database insert call worked if (!insert_record('question_algebra', $algebra)) { echo get_string('qtype_algebra', 'restoreqdbfailed'), "\n"; $status = false; } // Generate output so that the user can see questions being restored if (($i + 1) % 50 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 1000 == 0) { echo "<br />"; } } backup_flush(300); } } return $status; }
function backup_question($bf, $preferences, $category, $level = 4) { global $CFG, $QTYPES; $status = true; // We'll fetch the questions sorted by parent so that questions with no parents // (these are the ones which could be parents themselves) are backed up first. This // is important for the recoding of the parent field during the restore process // Only select questions with ids in backup_ids table $questions = get_records_sql("SELECT q.* FROM {$CFG->prefix}backup_ids bk, {$CFG->prefix}question q " . "WHERE q.category= {$category} AND " . "bk.old_id=q.id AND " . "bk.backup_code = {$preferences->backup_unique_code} " . "ORDER BY parent ASC, id"); //If there are questions if ($questions) { //Write start tag $status = $status && fwrite($bf, start_tag("QUESTIONS", $level, true)); $counter = 0; //Iterate over each question foreach ($questions as $question) { //Start question $status = $status && fwrite($bf, start_tag("QUESTION", $level + 1, true)); //Print question contents fwrite($bf, full_tag("ID", $level + 2, false, $question->id)); fwrite($bf, full_tag("PARENT", $level + 2, false, $question->parent)); fwrite($bf, full_tag("NAME", $level + 2, false, $question->name)); fwrite($bf, full_tag("QUESTIONTEXT", $level + 2, false, $question->questiontext)); fwrite($bf, full_tag("QUESTIONTEXTFORMAT", $level + 2, false, $question->questiontextformat)); fwrite($bf, full_tag("IMAGE", $level + 2, false, $question->image)); fwrite($bf, full_tag("GENERALFEEDBACK", $level + 2, false, $question->generalfeedback)); fwrite($bf, full_tag("DEFAULTGRADE", $level + 2, false, $question->defaultgrade)); fwrite($bf, full_tag("PENALTY", $level + 2, false, $question->penalty)); fwrite($bf, full_tag("QTYPE", $level + 2, false, $question->qtype)); fwrite($bf, full_tag("LENGTH", $level + 2, false, $question->length)); fwrite($bf, full_tag("STAMP", $level + 2, false, $question->stamp)); fwrite($bf, full_tag("VERSION", $level + 2, false, $question->version)); fwrite($bf, full_tag("HIDDEN", $level + 2, false, $question->hidden)); fwrite($bf, full_tag("TIMECREATED", $level + 2, false, $question->timecreated)); fwrite($bf, full_tag("TIMEMODIFIED", $level + 2, false, $question->timemodified)); fwrite($bf, full_tag("CREATEDBY", $level + 2, false, $question->createdby)); fwrite($bf, full_tag("MODIFIEDBY", $level + 2, false, $question->modifiedby)); // Backup question type specific data $status = $status && $QTYPES[$question->qtype]->backup($bf, $preferences, $question->id, $level + 2); //End question $status = $status && fwrite($bf, end_tag("QUESTION", $level + 1, true)); //Do some output $counter++; if ($counter % 10 == 0) { echo "."; if ($counter % 200 == 0) { echo "<br />"; } backup_flush(300); } } //Write end tag $status = $status && fwrite($bf, end_tag("QUESTIONS", $level, true)); } return $status; }
function backup_question($bf, $preferences, $category, $level = 4) { global $CFG, $QTYPES, $DB; $status = true; // We'll fetch the questions sorted by parent so that questions with no parents // (these are the ones which could be parents themselves) are backed up first. This // is important for the recoding of the parent field during the restore process // Only select questions with ids in backup_ids table $questions = $DB->get_records_sql("SELECT q.* FROM {backup_ids} bk, {question} q\n WHERE q.category= ? AND\n bk.old_id=q.id AND\n bk.backup_code = ?\n ORDER BY parent ASC, id", array($category, $preferences->backup_unique_code)); //If there are questions if ($questions) { //Write start tag $status = $status && fwrite($bf, start_tag("QUESTIONS", $level, true)); $counter = 0; //Iterate over each question foreach ($questions as $question) { // Deal with missing question types - they need to be included becuase // user data or quizzes may refer to them. if (!array_key_exists($question->qtype, $QTYPES)) { $question->qtype = 'missingtype'; $question->questiontext = '<p>' . get_string('warningmissingtype', 'quiz') . '</p>' . $question->questiontext; } //Start question $status = $status && fwrite($bf, start_tag("QUESTION", $level + 1, true)); //Print question contents fwrite($bf, full_tag("ID", $level + 2, false, $question->id)); fwrite($bf, full_tag("PARENT", $level + 2, false, $question->parent)); fwrite($bf, full_tag("NAME", $level + 2, false, $question->name)); fwrite($bf, full_tag("QUESTIONTEXT", $level + 2, false, $question->questiontext)); fwrite($bf, full_tag("QUESTIONTEXTFORMAT", $level + 2, false, $question->questiontextformat)); fwrite($bf, full_tag("IMAGE", $level + 2, false, $question->image)); fwrite($bf, full_tag("GENERALFEEDBACK", $level + 2, false, $question->generalfeedback)); fwrite($bf, full_tag("DEFAULTGRADE", $level + 2, false, $question->defaultgrade)); fwrite($bf, full_tag("PENALTY", $level + 2, false, $question->penalty)); fwrite($bf, full_tag("QTYPE", $level + 2, false, $question->qtype)); fwrite($bf, full_tag("LENGTH", $level + 2, false, $question->length)); fwrite($bf, full_tag("STAMP", $level + 2, false, $question->stamp)); fwrite($bf, full_tag("VERSION", $level + 2, false, $question->version)); fwrite($bf, full_tag("HIDDEN", $level + 2, false, $question->hidden)); fwrite($bf, full_tag("TIMECREATED", $level + 2, false, $question->timecreated)); fwrite($bf, full_tag("TIMEMODIFIED", $level + 2, false, $question->timemodified)); fwrite($bf, full_tag("CREATEDBY", $level + 2, false, $question->createdby)); fwrite($bf, full_tag("MODIFIEDBY", $level + 2, false, $question->modifiedby)); // Backup question type specific data $status = $status && $QTYPES[$question->qtype]->backup($bf, $preferences, $question->id, $level + 2); //End question $status = $status && fwrite($bf, end_tag("QUESTION", $level + 1, true)); //Do some output $counter++; if ($counter % 10 == 0) { echo "."; if ($counter % 200 == 0) { echo "<br />"; } backup_flush(300); } } //Write end tag $status = $status && fwrite($bf, end_tag("QUESTIONS", $level, true)); } return $status; }
function assignment_restore_wiki2markdown($restore) { global $CFG; $status = true; //Convert assignment->description if ($records = get_records_sql("SELECT a.id, a.description, a.format\n FROM {$CFG->prefix}assignment a,\n {$CFG->prefix}backup_ids b\n WHERE a.course = {$restore->course_id} AND\n a.format = " . FORMAT_WIKI . " AND\n b.backup_code = {$restore->backup_unique_code} AND\n b.table_name = 'assignment' AND\n b.new_id = a.id")) { foreach ($records as $record) { //Rebuild wiki links $record->description = restore_decode_wiki_content($record->description, $restore); //Convert to Markdown $wtm = new WikiToMarkdown(); $record->description = $wtm->convert($record->description, $restore->course_id); $record->format = FORMAT_MARKDOWN; $status = update_record('assignment', addslashes_object($record)); //Do some output $i++; if (($i + 1) % 1 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 20 == 0) { echo "<br />"; } } backup_flush(300); } } } return $status; }
function exercise_grades_restore_mods($new_exercise_id, $new_assessment_id, $info, $restore) { global $CFG; $status = true; //Get the grades array (optional) if (isset($info['#']['GRADES']['0']['#']['GRADE'])) { $grades = $info['#']['GRADES']['0']['#']['GRADE']; //Iterate over grades for ($i = 0; $i < sizeof($grades); $i++) { $gra_info = $grades[$i]; //traverse_xmlize($gra_info); //Debug //print_object ($GLOBALS['traverse_array']); //Debug //$GLOBALS['traverse_array']=""; //Debug //Now, build the exercise_GRADES record structure $grade->exerciseid = $new_exercise_id; $grade->assessmentid = $new_assessment_id; $grade->elementno = backup_todb($gra_info['#']['ELEMENTNO']['0']['#']); $grade->feedback = backup_todb($gra_info['#']['FEEDBACK']['0']['#']); $grade->grade = backup_todb($gra_info['#']['GRADE_VALUE']['0']['#']); //The structure is equal to the db, so insert the exercise_grade $newid = insert_record("exercise_grades", $grade); //Do some output if (($i + 1) % 50 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 1000 == 0) { echo "<br />"; } } backup_flush(300); } if (!$newid) { $status = false; } } } return $status; }
/** * Decode links in question type specific tables. * @return bool success or failure. */ function decode_content_links_caller($questionids, $restore, &$i) { $status = true; // Decode links in the question_multichoice table. if ($multichoices = get_records_list('question_multichoice', 'question', implode(',', $questionids), '', 'id, correctfeedback, partiallycorrectfeedback, incorrectfeedback')) { foreach ($multichoices as $multichoice) { $correctfeedback = restore_decode_content_links_worker($multichoice->correctfeedback, $restore); $partiallycorrectfeedback = restore_decode_content_links_worker($multichoice->partiallycorrectfeedback, $restore); $incorrectfeedback = restore_decode_content_links_worker($multichoice->incorrectfeedback, $restore); if ($correctfeedback != $multichoice->correctfeedback || $partiallycorrectfeedback != $multichoice->partiallycorrectfeedback || $incorrectfeedback != $multichoice->incorrectfeedback) { $subquestion->correctfeedback = addslashes($correctfeedback); $subquestion->partiallycorrectfeedback = addslashes($partiallycorrectfeedback); $subquestion->incorrectfeedback = addslashes($incorrectfeedback); if (!update_record('question_multichoice', $multichoice)) { $status = false; } } // Do some output. if (++$i % 5 == 0 && !defined('RESTORE_SILENTLY')) { echo "."; if ($i % 100 == 0) { echo "<br />"; } backup_flush(300); } } } return $status; }
/** * This function makes all the necessary calls to xxxx_decode_content_links() * function in each module, passing them the desired contents to be decoded * from backup format to destination site/course in order to mantain inter-activities * working in the backup/restore process. It's called from restore_decode_content_links() * function in restore process * * @param object $restore the preferences used in restore * @return boolean status of the execution */ function data_decode_content_links_caller($restore) { global $CFG; $status = true; /// Process every DATA (intro, all HTML templates) in the course /// Supported fields for main table: $supportedfields = array('intro', 'singletemplate', 'listtemplate', 'listtemplateheader', 'addtemplate', 'rsstemplate', 'rsstitletemplate'); if ($datas = get_records_sql("SELECT d.id, " . implode(',', $supportedfields) . "\n FROM {$CFG->prefix}data d\n WHERE d.course = {$restore->course_id}")) { /// Iterate over each data $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($datas as $data) { /// Increment counter $i++; /// Make a new copy of the data object with nothing in, to use if /// changes are necessary (allows us to do update_record without /// worrying about every single field being included and needing /// slashes). $newdata = new stdClass(); $newdata->id = $data->id; /// Loop through handling each supported field $changed = false; foreach ($supportedfields as $field) { $result = restore_decode_content_links_worker($data->{$field}, $restore); if ($result != $data->{$field}) { $newdata->{$field} = addslashes($result); $changed = true; if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($data->{$field}) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } } /// Update record if any field changed if ($changed) { $status = update_record("data", $newdata); } /// Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } /// Process every COMMENT (content) in the course if ($comments = get_records_sql("SELECT dc.id, dc.content\n FROM {$CFG->prefix}data d,\n {$CFG->prefix}data_records dr,\n {$CFG->prefix}data_comments dc\n WHERE d.course = {$restore->course_id}\n AND dr.dataid = d.id\n AND dc.recordid = dr.id")) { /// Iterate over each data_comments->content $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($comments as $comment) { /// Increment counter $i++; $content = $comment->content; $result = restore_decode_content_links_worker($content, $restore); if ($result != $content) { /// Update record $comment->content = addslashes($result); $status = update_record("data_comments", $comment); if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } /// Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } /// Process every CONTENT (content, content1, content2, content3, content4) in the course if ($contents = get_records_sql("SELECT dc.id, dc.content, dc.content1, dc.content2, dc.content3, dc.content4\n FROM {$CFG->prefix}data d,\n {$CFG->prefix}data_records dr,\n {$CFG->prefix}data_content dc\n WHERE d.course = {$restore->course_id}\n AND dr.dataid = d.id\n AND dc.recordid = dr.id")) { /// Iterate over each data_content->content, content1, content2, content3 and content4 $i = 0; //Counter to send some output to the browser to avoid timeouts foreach ($contents as $cnt) { /// Increment counter $i++; $content = $cnt->content; $content1 = $cnt->content1; $content2 = $cnt->content2; $content3 = $cnt->content3; $content4 = $cnt->content4; $result = restore_decode_content_links_worker($content, $restore); $result1 = restore_decode_content_links_worker($content1, $restore); $result2 = restore_decode_content_links_worker($content2, $restore); $result3 = restore_decode_content_links_worker($content3, $restore); $result4 = restore_decode_content_links_worker($content4, $restore); if ($result != $content || $result1 != $content1 || $result2 != $content2 || $result3 != $content3 || $result4 != $content4) { /// Unset fields to update only the necessary ones unset($cnt->content); unset($cnt->content1); unset($cnt->content2); unset($cnt->content3); unset($cnt->content4); /// Conditionally set the fields if ($result != $content) { $cnt->content = addslashes($result); } if ($result1 != $content1) { $cnt->content1 = addslashes($result1); } if ($result2 != $content2) { $cnt->content2 = addslashes($result2); } if ($result3 != $content3) { $cnt->content3 = addslashes($result3); } if ($result4 != $content4) { $cnt->content4 = addslashes($result4); } /// Update record with the changed fields $status = update_record("data_content", $cnt); if (debugging()) { if (!defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } } } /// Do some output if (($i + 1) % 5 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 100 == 0) { echo "<br />"; } } backup_flush(300); } } } return $status; }
function quiz_restore_wiki2markdown($restore) { global $CFG; $status = true; //Convert question->questiontext if ($records = get_records_sql("SELECT q.id, q.questiontext, q.questiontextformat\n FROM {$CFG->prefix}question q,\n {$CFG->prefix}backup_ids b\n WHERE b.backup_code = {$restore->backup_unique_code} AND\n b.table_name = 'question' AND\n q.id = b.new_id AND\n q.questiontextformat = " . FORMAT_WIKI)) { $i = 0; foreach ($records as $record) { //Rebuild wiki links $record->questiontext = restore_decode_wiki_content($record->questiontext, $restore); //Convert to Markdown $wtm = new WikiToMarkdown(); $record->questiontext = $wtm->convert($record->questiontext, $restore->course_id); $record->questiontextformat = FORMAT_MARKDOWN; $status = update_record('question', addslashes_object($record)); //Do some output $i++; if (($i + 1) % 1 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 20 == 0) { echo "<br />"; } } backup_flush(300); } } } return $status; }