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 restore($old_question_id, $new_question_id, $info, $restore) { global $DB; $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 = new stdClass(); $multianswer->question = $new_question_id; $multianswer->sequence = backup_todb($mul_info['#']['SEQUENCE']['0']['#']); //We have to recode the sequence field (a list of question ids) //Extracts question id from sequence $sequence_field = ""; $in_first = true; //$tok = strtok($multianswer->sequence,","); $tok = explode(",", $multianswer->sequence); while (list($key, $value) = each($tok)) { if (!empty($value)) { //Get the answer from reader_backup_ids $question = backup_getid($restore->backup_unique_code, "question", $value); if ($question) { if ($in_first) { $sequence_field .= $question->new_id; $in_first = false; } else { $sequence_field .= "," . $question->new_id; } } } } //We have the answers field recoded to its new ids $multianswer->sequence = $sequence_field; //The structure is equal to the db, so insert the question_multianswer $newid = $DB->insert_record("question_multianswer", $multianswer); //Save ids in reader_backup_ids if ($newid) { backup_putid($restore->backup_unique_code, "question_multianswer", $oldid, $newid); } //Do some output if (($i + 1) % 50 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if (($i + 1) % 1000 == 0) { echo "<br />"; } } backup_flush(300); } } return $status; }
protected function restore_hook($restore, $lock) { if (!empty($lock['id'])) { $item = backup_getid($restore->backup_unique_code, 'grade_items', $lock['id']); if ($item and !empty($item->new_id)) { $lock['id'] = $item->new_id; return $lock; } } return false; }
protected function restore_hook($restore, $lock) { if (!empty($lock['cmid'])) { // Get the new course module ID $cmid = backup_getid($restore->backup_unique_code, 'course_modules', $lock['cmid']); if ($cmid and !empty($cmid->new_id)) { $lock['cmid'] = $cmid->new_id; return $lock; } } return false; }
function textanalysis_restore_mods($mod, $restore) { global $CFG, $oldidarray; $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 // if necessary, write to restorelog and adjust date/time fields if ($restore->course_startdateoffset) { restore_log_date_changes('textanalysis', $restore, $info['MOD']['#'], array('TEXTANALYSISTIME')); } //Now, build the textanalysis record structure $textanalysis->course = $restore->course_id; $textanalysis->teacher = backup_todb($info['MOD']['#']['TEACHER']['0']['#']); $textanalysis->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $textanalysis->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']); $textanalysis->type = backup_todb($info['MOD']['#']['TYPE']['0']['#']); $textanalysis->time = backup_todb($info['MOD']['#']['TIME']['0']['#']); $user = backup_getid($restore->backup_unique_code, "user", $textanalysis->teacher); if ($user) { $textanalysis->teacher = $user->new_id; } //The structure is equal to the db, so insert the textanalysis $newid = insert_record("textanalysis", $textanalysis); //Do some output //if (!defined('RESTORE_SILENTLY')) { // echo "<li>".get_string("modulename","textanalysis")." \"".format_string(stripslashes($textanalysis->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); //Now check if want to restore user data and do it. if (restore_userdata_selected($restore, 'textanalysis', $mod->id)) { //Restore textanalysis_messages } } else { $status = false; } } else { $status = false; } 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; }
/** * 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; }
public static function restore_data($data, $restore) { $status = false; foreach ($data as $datum) { switch ($datum->name) { case 'moduleid': // Relink module ID $newid = backup_getid($restore->backup_unique_code, 'course_modules', $datum->value); if (isset($newid->new_id)) { $datum->value = $newid->new_id; $status = update_record('pagemenu_link_data', $datum); } break; default: debugging('Deleting unknown data type: ' . $datum->name); // Not recognized delete_records('pagemenu_link_data', 'id', $datum->id); break; } } 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 write_role_assignments_xml($bf, $preferences, $context, $startlevel) { /// write role_assign code here fwrite($bf, start_tag("ROLES_ASSIGNMENTS", $startlevel, true)); if ($roles = get_roles_with_assignment_on_context($context)) { foreach ($roles as $role) { /// Skip non-selected roles if (!isset($preferences->backuproleassignments[$role->id])) { continue; } fwrite($bf, start_tag("ROLE", $startlevel + 1, true)); fwrite($bf, full_tag("ID", $startlevel + 2, false, $role->id)); fwrite($bf, full_tag("NAME", $startlevel + 2, false, $role->name)); fwrite($bf, full_tag("SHORTNAME", $startlevel + 2, false, $role->shortname)); fwrite($bf, start_tag("ASSIGNMENTS", $startlevel + 2, true)); if ($assignments = get_users_from_role_on_context($role, $context)) { foreach ($assignments as $assignment) { /// Role assignments are only sent to backup if the user is one target user if (backup_getid($preferences->backup_unique_code, 'user', $assignment->userid)) { fwrite($bf, start_tag("ASSIGNMENT", $startlevel + 3, true)); fwrite($bf, full_tag("USERID", $startlevel + 4, false, $assignment->userid)); fwrite($bf, full_tag("HIDDEN", $startlevel + 4, false, $assignment->hidden)); fwrite($bf, full_tag("TIMESTART", $startlevel + 4, false, $assignment->timestart)); fwrite($bf, full_tag("TIMEEND", $startlevel + 4, false, $assignment->timeend)); fwrite($bf, full_tag("TIMEMODIFIED", $startlevel + 4, false, $assignment->timemodified)); if (!isset($assignment->modifierid)) { $assignment->modifierid = 0; } fwrite($bf, full_tag("MODIFIERID", $startlevel + 4, false, $assignment->modifierid)); fwrite($bf, full_tag("ENROL", $startlevel + 4, false, $assignment->enrol)); fwrite($bf, full_tag("SORTORDER", $startlevel + 4, false, $assignment->sortorder)); fwrite($bf, end_tag("ASSIGNMENT", $startlevel + 3, true)); } } } fwrite($bf, end_tag("ASSIGNMENTS", $startlevel + 2, true)); fwrite($bf, end_tag("ROLE", $startlevel + 1, true)); } } fwrite($bf, end_tag("ROLES_ASSIGNMENTS", $startlevel, true)); }
/** * Return content decoded to support interactivities linking. * This is called automatically from * {@link restore_decode_content_links_worker()} function * in the restore process. * * @param string $content Content to be dencoded * @param object $restore Restore preferences object * @return string The dencoded content **/ function learning_decode_format_content_links($content, $restore) { global $CFG; $searchstring = '/\\$@(COURSEFORMATFRONTPAGE)\\*([0-9]+)@\\$/'; preg_match_all($searchstring, $content, $foundset); if ($foundset[0]) { // iterate of $foundset[2] and $foundset[3] they are the old_ids foreach ($foundset[2] as $key => $old_id) { $rec = backup_getid($restore->backup_unique_code, 'format_page', $old_id); $searchstring = '/\\$@(COURSEFORMATFRONTPAGE)\\*(' . $old_id . ')@\\$/'; if (!empty($rec->new_id)) { $content = preg_replace($searchstring, $CFG->wwwroot . '/index.php?page=' . $rec->new_id, $content); } else { // it's a link to an external site so leave alone $content = preg_replace($searchstring, $restore->original_wwwroot . '/index.php?page=' . $old_id, $content); } } } $searchstring = '/\\$@(COURSEFORMATPAGE)\\*([0-9]+)\\*([0-9]+)@\\$/'; preg_match_all($searchstring, $content, $foundset); if ($foundset[0]) { // iterate of $foundset[2] and $foundset[3] they are the old_ids foreach ($foundset[2] as $key => $old_id) { $old_id2 = $foundset[3][$key]; $rec = backup_getid($restore->backup_unique_code, 'course', $old_id); $rec2 = backup_getid($restore->backup_unique_code, 'format_page', $old_id2); $searchstring = '/\\$@(COURSEFORMATPAGE)\\*(' . $old_id . ')\\*(' . $old_id2 . ')@\\$/'; if (!empty($rec->new_id) && !empty($rec2->new_id)) { $content = preg_replace($searchstring, $CFG->wwwroot . '/course/view.php?id=' . $rec->new_id . '&page=' . $rec2->new_id, $content); } else { // it's a link to an external site so leave alone $content = preg_replace($searchstring, $restore->original_wwwroot . '/course/view.php?id=' . $old_id . '&page=' . $old_id2, $content); } } } $searchstring = '/\\$@(COURSEFORMATMANAGEMENU)\\*([0-9]+)@\\$/'; preg_match_all($searchstring, $content, $foundset); if ($foundset[0]) { // iterate of $foundset[2] and $foundset[3] they are the old_ids foreach ($foundset[2] as $key => $old_id) { $rec = backup_getid($restore->backup_unique_code, 'course', $old_id); $searchstring = '/\\$@(COURSEFORMATMANAGEMENU)\\*(' . $old_id . ')@\\$/'; if (!empty($rec->new_id)) { $content = preg_replace($searchstring, $CFG->wwwroot . '/course/format/page/managemenu.php?id=' . $rec->new_id, $content); } else { // it's a link to an external site so leave alone $content = preg_replace($searchstring, $restore->original_wwwroot . '/course/format/page/managemenu.php?id=' . $old_id, $content); } } } return $content; }
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 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 restore_recode_answer($state, $restore) { // The answer looks like 'randomXX-ANSWER', where XX is // the id of the used question and ANSWER the actual // response to that question. // However, there may still be old-style states around, // which store the id of the wrapped question in the // state of the random question and store the response // in a separate state for the wrapped question global $QTYPES, $DB; $answer_field = ""; if (ereg('^random([0-9]+)-(.*)$', $state->answer, $answerregs)) { // Recode the question id in $answerregs[1] // Get the question from backup_ids if (!($wrapped = backup_getid($restore->backup_unique_code, "question", $answerregs[1]))) { echo 'Could not recode question in random-' . $answerregs[1] . '<br />'; return $answer_field; } // Get the question type for recursion if (!($wrappedquestion->qtype = $DB->get_field('question', 'qtype', array('id' => $wrapped->new_id)))) { echo 'Could not get qtype while recoding question random-' . $answerregs[1] . '<br />'; return $answer_field; } $newstate = $state; $newstate->question = $wrapped->new_id; $newstate->answer = $answerregs[2]; $answer_field = 'random' . $wrapped->new_id . '-'; // Recode the answer field in $answerregs[2] depending on // the qtype of question with id $answerregs[1] $answer_field .= $QTYPES[$wrappedquestion->qtype]->restore_recode_answer($newstate, $restore); } else { // Handle old-style states $answer_link = backup_getid($restore->backup_unique_code, "question", $state->answer); if ($answer_link) { $answer_field = $answer_link->new_id; } } return $answer_field; }
function hotpot_decode_content_link($scriptname, $paramname, $paramvalue, &$restore) { global $CFG; $table = ''; switch ($paramname) { case 'id': switch ($scriptname) { case 'index': $table = 'course'; break; case 'report': case 'review': case 'view': $table = 'course_modules'; break; case 'attempt': $table = 'hotpot_attempts'; break; } break; case 'hp': case 'hotpotid': $table = 'hotpot'; break; } $new_id = 0; if ($table) { if ($rec = backup_getid($restore->backup_unique_code, $table, $paramvalue)) { $new_id = $rec->new_id; } } return "{$CFG->wwwroot}/mod/hotpot/{$scriptname}.php?{$paramname}={$new_id}"; }
function wiki_decode_content_links($content, $restore) { global $CFG; $result = $content; //Link to the list of wikis $searchstring = '/\\$@(WIKIINDEX)\\*([0-9]+)@\\$/'; //We look for it preg_match_all($searchstring, $content, $foundset); //If found, then we are going to look for its new id (in backup tables) if ($foundset[0]) { //print_object($foundset); //Debug //Iterate over foundset[2]. They are the old_ids foreach ($foundset[2] as $old_id) { //We get the needed variables here (course id) $rec = backup_getid($restore->backup_unique_code, "course", $old_id); //Personalize the searchstring $searchstring = '/\\$@(WIKIINDEX)\\*(' . $old_id . ')@\\$/'; //If it is a link to this course, update the link to its new location if ($rec->new_id) { //Now replace it $result = preg_replace($searchstring, $CFG->wwwroot . '/mod/wiki/index.php?id=' . $rec->new_id, $result); } else { //It's a foreign link so leave it as original $result = preg_replace($searchstring, $restore->original_wwwroot . '/mod/wiki/index.php?id=' . $old_id, $result); } } } //Link to wiki view by moduleid $searchstring = '/\\$@(WIKIVIEWBYID)\\*([0-9]+)@\\$/'; //We look for it preg_match_all($searchstring, $result, $foundset); //If found, then we are going to look for its new id (in backup tables) if ($foundset[0]) { //print_object($foundset); //Debug //Iterate over foundset[2]. They are the old_ids foreach ($foundset[2] as $old_id) { //We get the needed variables here (course_modules id) $rec = backup_getid($restore->backup_unique_code, "course_modules", $old_id); //Personalize the searchstring $searchstring = '/\\$@(WIKIVIEWBYID)\\*(' . $old_id . ')@\\$/'; //If it is a link to this course, update the link to its new location if ($rec->new_id) { //Now replace it $result = preg_replace($searchstring, $CFG->wwwroot . '/mod/wiki/view.php?id=' . $rec->new_id, $result); } else { //It's a foreign link so leave it as original $result = preg_replace($searchstring, $restore->original_wwwroot . '/mod/wiki/view.php?id=' . $old_id, $result); } } } return $result; }
function forum_decode_content_links($content, $restore) { global $CFG; $result = $content; //Link to the list of forums $searchstring = '/\\$@(FORUMINDEX)\\*([0-9]+)@\\$/'; //We look for it preg_match_all($searchstring, $content, $foundset); //If found, then we are going to look for its new id (in backup tables) if ($foundset[0]) { //print_object($foundset); //Debug //Iterate over foundset[2]. They are the old_ids foreach ($foundset[2] as $old_id) { //We get the needed variables here (course id) $rec = backup_getid($restore->backup_unique_code, "course", $old_id); //Personalize the searchstring $searchstring = '/\\$@(FORUMINDEX)\\*(' . $old_id . ')@\\$/'; //If it is a link to this course, update the link to its new location if ($rec->new_id) { //Now replace it $result = preg_replace($searchstring, $CFG->wwwroot . '/mod/forum/index.php?id=' . $rec->new_id, $result); } else { //It's a foreign link so leave it as original $result = preg_replace($searchstring, $restore->original_wwwroot . '/mod/forum/index.php?id=' . $old_id, $result); } } } //Link to forum view by moduleid $searchstring = '/\\$@(FORUMVIEWBYID)\\*([0-9]+)@\\$/'; //We look for it preg_match_all($searchstring, $result, $foundset); //If found, then we are going to look for its new id (in backup tables) if ($foundset[0]) { //print_object($foundset); //Debug //Iterate over foundset[2]. They are the old_ids foreach ($foundset[2] as $old_id) { //We get the needed variables here (course_modules id) $rec = backup_getid($restore->backup_unique_code, "course_modules", $old_id); //Personalize the searchstring $searchstring = '/\\$@(FORUMVIEWBYID)\\*(' . $old_id . ')@\\$/'; //If it is a link to this course, update the link to its new location if ($rec->new_id) { //Now replace it $result = preg_replace($searchstring, $CFG->wwwroot . '/mod/forum/view.php?id=' . $rec->new_id, $result); } else { //It's a foreign link so leave it as original $result = preg_replace($searchstring, $restore->original_wwwroot . '/mod/forum/view.php?id=' . $old_id, $result); } } } //Link to forum view by forumid $searchstring = '/\\$@(FORUMVIEWBYF)\\*([0-9]+)@\\$/'; //We look for it preg_match_all($searchstring, $result, $foundset); //If found, then we are going to look for its new id (in backup tables) if ($foundset[0]) { //print_object($foundset); //Debug //Iterate over foundset[2]. They are the old_ids foreach ($foundset[2] as $old_id) { //We get the needed variables here (forum id) $rec = backup_getid($restore->backup_unique_code, "forum", $old_id); //Personalize the searchstring $searchstring = '/\\$@(FORUMVIEWBYF)\\*(' . $old_id . ')@\\$/'; //If it is a link to this course, update the link to its new location if ($rec->new_id) { //Now replace it $result = preg_replace($searchstring, $CFG->wwwroot . '/mod/forum/view.php?f=' . $rec->new_id, $result); } else { //It's a foreign link so leave it as original $result = preg_replace($searchstring, $restore->original_wwwroot . '/mod/forum/view.php?f=' . $old_id, $result); } } } //Link to forum discussion by discussionid $searchstring = '/\\$@(FORUMDISCUSSIONVIEW)\\*([0-9]+)@\\$/'; //We look for it preg_match_all($searchstring, $result, $foundset); //If found, then we are going to look for its new id (in backup tables) if ($foundset[0]) { //print_object($foundset); //Debug //Iterate over foundset[2]. They are the old_ids foreach ($foundset[2] as $old_id) { //We get the needed variables here (discussion id) $rec = backup_getid($restore->backup_unique_code, "forum_discussions", $old_id); //Personalize the searchstring $searchstring = '/\\$@(FORUMDISCUSSIONVIEW)\\*(' . $old_id . ')@\\$/'; //If it is a link to this course, update the link to its new location if ($rec->new_id) { //Now replace it $result = preg_replace($searchstring, $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $rec->new_id, $result); } else { //It's a foreign link so leave it as original $result = preg_replace($searchstring, $restore->original_wwwroot . '/mod/forum/discuss.php?d=' . $old_id, $result); } } } //Link to forum discussion with parent syntax $searchstring = '/\\$@(FORUMDISCUSSIONVIEWPARENT)\\*([0-9]+)\\*([0-9]+)@\\$/'; //We look for it preg_match_all($searchstring, $result, $foundset); //If found, then we are going to look for its new id (in backup tables) if ($foundset[0]) { //print_object($foundset); //Debug //Iterate over foundset[2] and foundset[3]. They are the old_ids foreach ($foundset[2] as $key => $old_id) { $old_id2 = $foundset[3][$key]; //We get the needed variables here (discussion id and post id) $rec = backup_getid($restore->backup_unique_code, "forum_discussions", $old_id); $rec2 = backup_getid($restore->backup_unique_code, "forum_posts", $old_id2); //Personalize the searchstring $searchstring = '/\\$@(FORUMDISCUSSIONVIEWPARENT)\\*(' . $old_id . ')\\*(' . $old_id2 . ')@\\$/'; //If it is a link to this course, update the link to its new location if ($rec->new_id && $rec2->new_id) { //Now replace it $result = preg_replace($searchstring, $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $rec->new_id . '&parent=' . $rec2->new_id, $result); } else { //It's a foreign link so leave it as original $result = preg_replace($searchstring, $restore->original_wwwroot . '/mod/forum/discuss.php?d=' . $old_id . '&parent=' . $old_id2, $result); } } } //Link to forum discussion with relative syntax $searchstring = '/\\$@(FORUMDISCUSSIONVIEWINSIDE)\\*([0-9]+)\\*([0-9]+)@\\$/'; //We look for it preg_match_all($searchstring, $result, $foundset); //If found, then we are going to look for its new id (in backup tables) if ($foundset[0]) { //print_object($foundset); //Debug //Iterate over foundset[2] and foundset[3]. They are the old_ids foreach ($foundset[2] as $key => $old_id) { $old_id2 = $foundset[3][$key]; //We get the needed variables here (discussion id and post id) $rec = backup_getid($restore->backup_unique_code, "forum_discussions", $old_id); $rec2 = backup_getid($restore->backup_unique_code, "forum_posts", $old_id2); //Personalize the searchstring $searchstring = '/\\$@(FORUMDISCUSSIONVIEWINSIDE)\\*(' . $old_id . ')\\*(' . $old_id2 . ')@\\$/'; //If it is a link to this course, update the link to its new location if ($rec->new_id && $rec2->new_id) { //Now replace it $result = preg_replace($searchstring, $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $rec->new_id . '#' . $rec2->new_id, $result); } else { //It's a foreign link so leave it as original $result = preg_replace($searchstring, $restore->original_wwwroot . '/mod/forum/discuss.php?d=' . $old_id . '#' . $old_id2, $result); } } } return $result; }
function restore_recode_answer($state, $restore) { //The answer is a comma separated list of hypen separated sequence number and answers. We may have to recode the answers $answer_field = ""; $in_first = true; $tok = strtok($state->answer, ","); while ($tok) { //Extract the multianswer_id and the answer $exploded = explode("-", $tok); $seqnum = $exploded[0]; $answer = $exploded[1]; // $sequence is an ordered array of the question ids. if (!($sequence = get_field('question_multianswer', 'sequence', 'question', $state->question))) { print_error('missingoption', 'question', '', $state->question); } $sequence = explode(',', $sequence); // The id of the current question. $wrappedquestionid = $sequence[$seqnum - 1]; // now we can find the question if (!($wrappedquestion = get_record('question', 'id', $wrappedquestionid))) { notify("Can't find the subquestion {$wrappedquestionid} that is used as part {$seqnum} in cloze question {$state->question}"); } // For multichoice question we need to recode the answer if ($answer and $wrappedquestion->qtype == 'multichoice') { //The answer is an answer_id, look for it in backup_ids if (!($ans = backup_getid($restore->backup_unique_code, "question_answers", $answer))) { echo 'Could not recode cloze multichoice answer ' . $answer . '<br />'; } $answer = $ans->new_id; } //build the new answer field for each pair if ($in_first) { $answer_field .= $seqnum . "-" . $answer; $in_first = false; } else { $answer_field .= "," . $seqnum . "-" . $answer; } //check for next $tok = strtok(","); } return $answer_field; }
function restore_recode_answer($state, $restore) { $pos = strpos($state->answer, ':'); $order = array(); $responses = array(); if (false === $pos) { // No order of answers is given, so use the default if ($state->answer) { $responses = explode(',', $state->answer); } } else { $order = explode(',', substr($state->answer, 0, $pos)); if ($responsestring = substr($state->answer, $pos + 1)) { $responses = explode(',', $responsestring); } } if ($order) { foreach ($order as $key => $oldansid) { $answer = backup_getid($restore->backup_unique_code, "question_answers", $oldansid); if ($answer) { $order[$key] = $answer->new_id; } else { echo 'Could not recode multichoice answer id ' . $oldansid . ' for state ' . $state->oldid . '<br />'; } } } if ($responses) { foreach ($responses as $key => $oldansid) { $answer = backup_getid($restore->backup_unique_code, "question_answers", $oldansid); if ($answer) { $responses[$key] = $answer->new_id; } else { echo 'Could not recode multichoice response answer id ' . $oldansid . ' for state ' . $state->oldid . '<br />'; } } } return implode(',', $order) . ':' . implode(',', $responses); }
function exercise_assessments_restore($new_exercise_id, $new_submission_id, $info, $restore) { global $CFG; $status = true; //Get the assessments array (optional) if (isset($info['#']['ASSESSMENTS']['0']['#']['ASSESSMENT'])) { $assessments = $info['#']['ASSESSMENTS']['0']['#']['ASSESSMENT']; //Iterate over assessments for ($i = 0; $i < sizeof($assessments); $i++) { $ass_info = $assessments[$i]; //traverse_xmlize($ass_info); //Debug //print_object ($GLOBALS['traverse_array']); //Debug //$GLOBALS['traverse_array']=""; //Debug //We'll need this later!! $oldid = backup_todb($ass_info['#']['ID']['0']['#']); $olduserid = backup_todb($ass_info['#']['USERID']['0']['#']); //Now, build the exercise_ASSESSMENTS record structure $assessment->exerciseid = $new_exercise_id; $assessment->submissionid = $new_submission_id; $assessment->userid = backup_todb($ass_info['#']['USERID']['0']['#']); $assessment->timecreated = backup_todb($ass_info['#']['TIMECREATED']['0']['#']); $assessment->timegraded = backup_todb($ass_info['#']['TIMEGRADED']['0']['#']); $assessment->grade = backup_todb($ass_info['#']['GRADE']['0']['#']); $assessment->gradinggrade = backup_todb($ass_info['#']['GRADINGGRADE']['0']['#']); $assessment->mailed = backup_todb($ass_info['#']['MAILED']['0']['#']); $assessment->generalcomment = backup_todb($ass_info['#']['GENERALCOMMENT']['0']['#']); $assessment->teachercomment = backup_todb($ass_info['#']['TEACHERCOMMENT']['0']['#']); //We have to recode the userid field $user = backup_getid($restore->backup_unique_code, "user", $olduserid); if ($user) { $assessment->userid = $user->new_id; } //The structure is equal to the db, so insert the exercise_assessment $newid = insert_record("exercise_assessments", $assessment); //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) { //We have the newid, update backup_ids backup_putid($restore->backup_unique_code, "exercise_assessments", $oldid, $newid); //Now we need to restore exercise_grades (user level table) if ($status) { $status = exercise_grades_restore_mods($new_exercise_id, $newid, $ass_info, $restore); } } else { $status = false; } } } return $status; }
function quiz_restore_pre15_logs($restore, $log) { $status = false; //Depending of the action, we recode different things switch ($log->action) { case "add": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "view.php?id=" . $log->cmid; $log->info = $mod->new_id; $status = true; } } break; case "update": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "view.php?id=" . $log->cmid; $log->info = $mod->new_id; $status = true; } } break; case "view": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "view.php?id=" . $log->cmid; $log->info = $mod->new_id; $status = true; } } break; case "view all": $log->url = "index.php?id=" . $log->course; $status = true; break; case "report": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "report.php?id=" . $log->cmid; $log->info = $mod->new_id; $status = true; } } break; case "attempt": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { //Extract the attempt id from the url field $attid = substr(strrchr($log->url, "="), 1); //Get the new_id of the attempt (to recode the url field) $att = backup_getid($restore->backup_unique_code, "quiz_attempts", $attid); if ($att) { $log->url = "review.php?id=" . $log->cmid . "&attempt=" . $att->new_id; $log->info = $mod->new_id; $status = true; } } } break; case "submit": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { //Extract the attempt id from the url field $attid = substr(strrchr($log->url, "="), 1); //Get the new_id of the attempt (to recode the url field) $att = backup_getid($restore->backup_unique_code, "quiz_attempts", $attid); if ($att) { $log->url = "review.php?id=" . $log->cmid . "&attempt=" . $att->new_id; $log->info = $mod->new_id; $status = true; } } } break; case "review": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { //Extract the attempt id from the url field $attid = substr(strrchr($log->url, "="), 1); //Get the new_id of the attempt (to recode the url field) $att = backup_getid($restore->backup_unique_code, "quiz_attempts", $attid); if ($att) { $log->url = "review.php?id=" . $log->cmid . "&attempt=" . $att->new_id; $log->info = $mod->new_id; $status = true; } } } break; case "editquestions": if ($log->cmid) { //Get the new_id of the module (to recode the url field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "view.php?id=" . $log->cmid; $log->info = $mod->new_id; $status = true; } } break; default: if (!defined('RESTORE_SILENTLY')) { echo "action (" . $log->module . "-" . $log->action . ") unknow. Not restored<br />"; //Debug } break; } if ($status) { $status = $log; } return $status; }
function restore_recode_answer($state, $restore) { //answer may be empty if ($state->answer) { $answer = backup_getid($restore->backup_unique_code, "question_answers", $state->answer); if ($answer) { return $answer->new_id; } else { echo 'Could not recode truefalse answer id ' . $state->answer . ' for state ' . $state->oldid . '<br />'; } } }
function hotpot_restore_logs($restore, $log) { // assume the worst $status = false; switch ($log->action) { case "add": case "update": case "view": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "view.php?id=" . $log->cmid; $log->info = $mod->new_id; $status = true; } } break; case "view all": $log->url = "index.php?id=" . $log->course; $status = true; break; case "report": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "report.php?id=" . $log->cmid; $log->info = $mod->new_id; $status = true; } } break; case "attempt": case "submit": case "review": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { //Extract the attempt id from the url field $attemptid = substr(strrchr($log->url, "="), 1); //Get the new_id of the attempt (to recode the url field) $attempt = backup_getid($restore->backup_unique_code, "hotpot_attempts", $attemptid); if ($attempt) { $log->url = "review.php?id=" . $log->cmid . "&attempt=" . $attempt->new_id; $log->info = $mod->new_id; $status = true; } } } break; default: // Oops, unknown $log->action if (!defined('RESTORE_SILENTLY')) { print "<p>action (" . $log->module . "-" . $log->action . ") unknown. Not restored</p>"; } break; } // end switch return $status ? $log : false; }
function assignment_restore_logs($restore, $log) { $status = false; //Depending of the action, we recode different things switch ($log->action) { case "add": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "view.php?id=" . $log->cmid; $log->info = $mod->new_id; $status = true; } } break; case "update": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "view.php?id=" . $log->cmid; $log->info = $mod->new_id; $status = true; } } break; case "view": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "view.php?id=" . $log->cmid; $log->info = $mod->new_id; $status = true; } } break; case "view all": $log->url = "index.php?id=" . $log->course; $status = true; break; case "upload": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "view.php?a=" . $mod->new_id; $log->info = $mod->new_id; $status = true; } } break; case "view submission": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "submissions.php?id=" . $mod->new_id; $log->info = $mod->new_id; $status = true; } } break; case "update grades": if ($log->cmid) { //Extract the assignment id from the url field $assid = substr(strrchr($log->url, "="), 1); //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $assid); if ($mod) { $log->url = "submissions.php?id=" . $mod->new_id; $status = true; } } break; default: if (!defined('RESTORE_SILENTLY')) { echo "action (" . $log->module . "-" . $log->action . ") unknown. Not restored<br />"; //Debug } break; } if ($status) { $status = $log; } return $status; }
function mail_restore_logs($restore, $log) { $status = false; //Depending of the action, we recode different things switch ($log->action) { case "add": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "view.php?id=" . $log->cmid; $log->info = $mod->new_id; $status = true; } } break; case "update": if ($log->cmid) { //Get the new_id of the module (to recode the info field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "view.php?id=" . $log->cmid; $log->info = $mod->new_id; $status = true; } } break; case "view": if ($log->cmid) { //Get the new_id of the page (to recode the url field) $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info); if ($mod) { $log->url = "view.php?id=" . $log->cmid; $log->info = $mod->new_id; $status = true; } } break; default: if (!defined('RESTORE_SILENTLY')) { echo "action (" . $log->module . "-" . $log->action . ") unknown. Not restored<br>"; //Debug } break; } if ($status) { $status = $log; } return $status; }
$restoreq->mods['quiz']->instances[$reader_backup_ids->old_id]->restore = 1; $restoreq->mods['quiz']->instances[$reader_backup_ids->old_id]->userinfo = 0; $restoreq->mods['quiz']->instances[$reader_backup_ids->old_id]->restored_as_course_module = $reader_backup_ids->new_id; $restoreq->course_startdateoffset = -1900800; $restoreq->restore_restorecatto = 3; $restoreq->rolesmapping = array(3 => 3, 4 => 4); print_string('process_addquestion', 'reader', $quizzestoadd_['title']); echo $OUTPUT->box_start('generalbox'); restore_create_questions($restoreq, $xml_file); echo $OUTPUT->box_end(); //Add questions to quiz $quizzesneeds = explode(',', $xmlarray['MOODLE_BACKUP']['#']['COURSE']['0']['#']['MODULES']['0']['#']['MOD']['0']['#']['QUESTIONS']['0']['#']); $questiondata = array(); foreach ($quizzesneeds as $quizzesneed) { if ($quizzesneed != 0) { $questionnewid = backup_getid($restoreq->backup_unique_code, 'question', $quizzesneed); if (!empty($questionnewid->new_id)) { $questiondata[$quizzesneed] = $questionnewid->new_id; } } } $questiongradedata = array(); foreach ($xmlarray['MOODLE_BACKUP']['#']['COURSE']['0']['#']['MODULES']['0']['#']['MOD']['0']['#']['QUESTION_INSTANCES']['0']['#']['QUESTION_INSTANCE'] as $findgrade) { $questiongradedata[$findgrade['#']['QUESTION']['0']['#']] = $findgrade['#']['GRADE']['0']['#']; } $DB->set_field('quiz', 'questions', implode(',', $questiondata) . ',0', array('id' => $quizbook[$quizzestoadd_['id']])); foreach ($questiondata as $key => $value) { $grade = new stdClass(); $grade->quiz = $quizbook[$quizzestoadd_['id']]; $grade->question = $value; $grade->grade = $questiongradedata[$key];
/** * Executed after block instance has been created, we use it to recode * the glossary config setting to point to the new (restored) one */ function after_restore($restore) { /// We need to transform the glossary->id from the original one to the restored one if ($rec = backup_getid($restore->backup_unique_code, 'glossary', $this->config->glossary)) { $this->config->glossary = $rec->new_id; $this->instance_config_commit(); } }
/** * セクションのリストア * * @param object $restore * @param string $xml_file * @return bool */ function project_restore_section(&$restore, $xml_file) { global $CFG, $db; $status = true; // $restoreのsectionパラメーターのチェック if (empty($restore->section)) { return false; } // セクションを取得 if (!($section = get_course_section($restore->section, $restore->course_id))) { error("Section data was incorrect (can't find it)"); } //Check it exists if (!file_exists($xml_file)) { $status = false; } //Get info from xml if ($status) { $info = restore_read_xml_sections($xml_file); } //Put the info in the DB, recoding ids and saving the in backup tables $sequence = ""; if ($info) { //For each, section, save it to db foreach ($info->sections as $key => $sect) { $sequence = ""; $update_rec = new object(); $update_rec->id = $section->id; $update_rec->course = $restore->course_id; $update_rec->section = $restore->section; $update_rec->summary = backup_todb($sect->summary); $update_rec->visible = $sect->visible; $update_rec->sequence = ""; $status = update_record('course_sections', $update_rec); $newid = $update_rec->id; if ($newid) { //save old and new section id backup_putid($restore->backup_unique_code, "course_sections", $key, $newid); } else { $status = false; } //If all is OK, go with associated mods if ($status) { //If we have mods in the section if (!empty($sect->mods)) { //For each mod inside section foreach ($sect->mods as $keym => $mod) { // Yu: This part is called repeatedly for every instance, // so it is necessary to set the granular flag and check isset() // when the first instance of this type of mod is processed. //if (!isset($restore->mods[$mod->type]->granular) && isset($restore->mods[$mod->type]->instances) && is_array($restore->mods[$mod->type]->instances)) { if (!isset($restore->mods[$mod->type]->granular)) { if (isset($restore->mods[$mod->type]->instances) && is_array($restore->mods[$mod->type]->instances)) { // This defines whether we want to restore specific // instances of the modules (granular restore), or // whether we don't care and just want to restore // all module instances (non-granular). $restore->mods[$mod->type]->granular = true; } else { $restore->mods[$mod->type]->granular = false; } } //Check if we've to restore this module (and instance) if (!empty($restore->mods[$mod->type]->restore)) { if (empty($restore->mods[$mod->type]->granular) || array_key_exists($mod->instance, $restore->mods[$mod->type]->instances) && !empty($restore->mods[$mod->type]->instances[$mod->instance]->restore)) { //Get the module id from modules $module = get_record("modules", "name", $mod->type); if ($module) { $course_module = new object(); $course_module->course = $restore->course_id; $course_module->module = $module->id; $course_module->section = $newid; $course_module->added = $mod->added; $course_module->score = $mod->score; $course_module->indent = $mod->indent; $course_module->visible = $mod->visible; $course_module->groupmode = $mod->groupmode; if ($mod->groupingid and $grouping = backup_getid($restore->backup_unique_code, "groupings", $mod->groupingid)) { $course_module->groupingid = $grouping->new_id; } else { $course_module->groupingid = 0; } $course_module->groupmembersonly = $mod->groupmembersonly; $course_module->instance = 0; //NOTE: The instance (new) is calculated and updated in db in the // final step of the restore. We don't know it yet. //print_object($course_module); //Debug //Save it to db $newidmod = insert_record("course_modules", $course_module); if ($newidmod) { //save old and new module id //In the info field, we save the original instance of the module //to use it later backup_putid($restore->backup_unique_code, "course_modules", $keym, $newidmod, $mod->instance); $restore->mods[$mod->type]->instances[$mod->instance]->restored_as_course_module = $newidmod; } else { $status = false; } //Now, calculate the sequence field if ($status) { if ($sequence) { $sequence .= "," . $newidmod; } else { $sequence = $newidmod; } } } else { $status = false; } } } } } } //If all is OK, update sequence field in course_sections if ($status) { if (isset($sequence)) { $update_rec = new object(); $update_rec->id = $newid; $update_rec->sequence = $sequence; $status = update_record("course_sections", $update_rec); } } } } else { $status = false; } return $status; }
/** * Returns a content decoded to support interactivities linking. Every module * should have its own. They are called automatically from * xxxx_decode_content_links_caller() function in each module * in the restore process. * * @param string $content the content to be decoded * @param object $restore the preferences used in restore * @return string the decoded string */ function data_decode_content_links($content, $restore) { global $CFG; $result = $content; /// Link to the list of datas $searchstring = '/\\$@(DATAINDEX)\\*([0-9]+)@\\$/'; /// We look for it preg_match_all($searchstring, $content, $foundset); /// If found, then we are going to look for its new id (in backup tables) if ($foundset[0]) { /// print_object($foundset); //Debug /// Iterate over foundset[2]. They are the old_ids foreach ($foundset[2] as $old_id) { /// We get the needed variables here (course id) $rec = backup_getid($restore->backup_unique_code, "course", $old_id); /// Personalize the searchstring $searchstring = '/\\$@(DATAINDEX)\\*(' . $old_id . ')@\\$/'; /// If it is a link to this course, update the link to its new location if ($rec->new_id) { /// Now replace it $result = preg_replace($searchstring, $CFG->wwwroot . '/mod/data/index.php?id=' . $rec->new_id, $result); } else { /// It's a foreign link so leave it as original $result = preg_replace($searchstring, $restore->original_wwwroot . '/mod/data/index.php?id=' . $old_id, $result); } } } /// Link to data view by moduleid $searchstring = '/\\$@(DATAVIEWBYID)\\*([0-9]+)@\\$/'; /// We look for it preg_match_all($searchstring, $result, $foundset); /// If found, then we are going to look for its new id (in backup tables) if ($foundset[0]) { /// print_object($foundset); //Debug /// Iterate over foundset[2]. They are the old_ids foreach ($foundset[2] as $old_id) { /// We get the needed variables here (course_modules id) $rec = backup_getid($restore->backup_unique_code, "course_modules", $old_id); /// Personalize the searchstring $searchstring = '/\\$@(DATAVIEWBYID)\\*(' . $old_id . ')@\\$/'; /// If it is a link to this course, update the link to its new location if ($rec->new_id) { /// Now replace it $result = preg_replace($searchstring, $CFG->wwwroot . '/mod/data/view.php?id=' . $rec->new_id, $result); } else { /// It's a foreign link so leave it as original $result = preg_replace($searchstring, $restore->original_wwwroot . '/mod/data/view.php?id=' . $old_id, $result); } } } /// Link to data view by dataid $searchstring = '/\\$@(DATAVIEWBYD)\\*([0-9]+)@\\$/'; /// We look for it preg_match_all($searchstring, $result, $foundset); /// If found, then we are going to look for its new id (in backup tables) if ($foundset[0]) { /// print_object($foundset); //Debug /// Iterate over foundset[2]. They are the old_ids foreach ($foundset[2] as $old_id) { /// We get the needed variables here (data id) $rec = backup_getid($restore->backup_unique_code, "data", $old_id); /// Personalize the searchstring $searchstring = '/\\$@(DATAVIEWBYD)\\*(' . $old_id . ')@\\$/'; /// If it is a link to this course, update the link to its new location if ($rec->new_id) { /// Now replace it $result = preg_replace($searchstring, $CFG->wwwroot . '/mod/data/view.php?d=' . $rec->new_id, $result); } else { /// It's a foreign link so leave it as original $result = preg_replace($searchstring, $restore->original_wwwroot . '/mod/data/view.php?d=' . $old_id, $result); } } } /// Link to data record (element) $searchstring = '/\\$@(DATAVIEWRECORD)\\*([0-9]+)\\*([0-9]+)@\\$/'; /// We look for it preg_match_all($searchstring, $result, $foundset); /// If found, then we are going to look for its new id (in backup tables) if ($foundset[0]) { /// print_object($foundset); //Debug /// Iterate over foundset[2] and foundset[3]. They are the old_ids foreach ($foundset[2] as $key => $old_id) { $old_id2 = $foundset[3][$key]; /// We get the needed variables here (data id and record id) $rec = backup_getid($restore->backup_unique_code, "data", $old_id); $rec2 = backup_getid($restore->backup_unique_code, "data_records", $old_id2); /// Personalize the searchstring $searchstring = '/\\$@(DATAVIEWRECORD)\\*(' . $old_id . ')\\*(' . $old_id2 . ')@\\$/'; /// If it is a link to this course, update the link to its new location if ($rec->new_id && $rec2->new_id) { /// Now replace it $result = preg_replace($searchstring, $CFG->wwwroot . '/mod/data/view.php?d=' . $rec->new_id . '&rid=' . $rec2->new_id, $result); } else { /// It's a foreign link so leave it as original $result = preg_replace($searchstring, $restore->original_wwwroot . '/mod/data/view.php?d=' . $old_id . '&rid=' . $old_id2, $result); } } } return $result; }
function quiz_recode_layout($layout, $restore) { //Recodes the quiz layout (a list of questions id and pagebreaks) //Extracts question id from sequence if ($questionids = explode(',', $layout)) { foreach ($questionids as $id => $questionid) { if ($questionid) { // If it is zero then this is a pagebreak, don't translate $newq = backup_getid($restore->backup_unique_code, "question", $questionid); $questionids[$id] = $newq->new_id; } } } return implode(',', $questionids); }