function lightboxgallery_restore_metadata($galleryid, $info, $restore) { $status = true; if (isset($info['MOD']['#']['IMAGEMETAS']['0']['#']['IMAGEMETA'])) { $imagemetas = $info['MOD']['#']['IMAGEMETAS']['0']['#']['IMAGEMETA']; } else { $imagemetas = array(); } for ($i = 0; $i < sizeof($imagemetas); $i++) { $sub_info = $imagemetas[$i]; $oldid = backup_todb($sub_info['#']['ID']['0']['#']); $record = new object(); $record->gallery = $galleryid; $record->image = backup_todb($sub_info['#']['IMAGE']['0']['#']); $record->metatype = backup_todb($sub_info['#']['METATYPE']['0']['#']); $record->description = backup_todb($sub_info['#']['DESCRIPTION']['0']['#']); $newid = insert_record('lightboxgallery_image_meta', $record); if (($i + 1) % 50 == 0) { if (!defined('RESTORE_SILENTLY')) { echo '.'; if (($i + 1) % 1000 == 0) { echo '<br />'; } } backup_flush(300); } if ($newid) { backup_putid($restore->backup_unique_code, 'lightboxgallery_image_meta', $oldid, $newid); } else { $status = false; } } return $status; }
function label_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 $label->course = $restore->course_id; $label->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $label->content = backup_todb($info['MOD']['#']['CONTENT']['0']['#']); $label->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#']; //The structure is equal to the db, so insert the label $newid = insert_record("label", $label); //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "label") . " \"" . format_string(stripslashes($label->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 diplome_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; //Now, build the ACCOUNTING record structure $diplome->course = $restore->course_id; $diplome->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $diplome->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']); $diplome->introformat = backup_todb($info['MOD']['#']['INTROFORMAT']['0']['#']); $diplome->timecreated = time(); $diplome->timemodified = time(); //The structure is equal to the db, so insert the label $newid = insert_record("diplome", $diplome); //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "diplome") . " \"" . format_string(stripslashes($diplome->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 tab_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 tab record structure $tab->course = $restore->course_id; $tab->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $tab->tab1 = backup_todb($info['MOD']['#']['TAB1']['0']['#']); $tab->tab2 = backup_todb($info['MOD']['#']['TAB2']['0']['#']); $tab->tab3 = backup_todb($info['MOD']['#']['TAB3']['0']['#']); $tab->tab4 = backup_todb($info['MOD']['#']['TAB4']['0']['#']); $tab->tab5 = backup_todb($info['MOD']['#']['TAB5']['0']['#']); $tab->tab6 = backup_todb($info['MOD']['#']['TAB6']['0']['#']); $tab->tab7 = backup_todb($info['MOD']['#']['TAB7']['0']['#']); $tab->tab8 = backup_todb($info['MOD']['#']['TAB8']['0']['#']); $tab->tab9 = backup_todb($info['MOD']['#']['TAB9']['0']['#']); $tab->tab0 = backup_todb($info['MOD']['#']['TAB0']['0']['#']); $tab->tab1content = backup_todb($info['MOD']['#']['TAB1CONTENT']['0']['#']); $tab->tab2content = backup_todb($info['MOD']['#']['TAB2CONTENT']['0']['#']); $tab->tab3content = backup_todb($info['MOD']['#']['TAB3CONTENT']['0']['#']); $tab->tab4content = backup_todb($info['MOD']['#']['TAB4CONTENT']['0']['#']); $tab->tab5content = backup_todb($info['MOD']['#']['TAB5CONTENT']['0']['#']); $tab->tab6content = backup_todb($info['MOD']['#']['TAB6CONTENT']['0']['#']); $tab->tab7content = backup_todb($info['MOD']['#']['TAB7CONTENT']['0']['#']); $tab->tab8content = backup_todb($info['MOD']['#']['TAB8CONTENT']['0']['#']); $tab->tab9content = backup_todb($info['MOD']['#']['TAB9CONTENT']['0']['#']); $tab->tab0content = backup_todb($info['MOD']['#']['TAB0CONTENT']['0']['#']); $tab->css = backup_todb($info['MOD']['#']['CSS']['0']['#']); $tab->menucss = backup_todb($info['MOD']['#']['MENUCSS']['0']['#']); $tab->displaymenu = backup_todb($info['MOD']['#']['DISPLAYMENU']['0']['#']); $tab->menuname = backup_todb($info['MOD']['#']['MENUNAME']['0']['#']); $tab->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#']; //The structure is equal to the db, so insert the tab $newid = insert_record("tab", $tab); //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "tab") . " \"" . format_string(stripslashes($tab->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 voiceauthoring_restore_mods($mod, $restore) { global $CFG; $status = true; //Get record from backup_ids $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id); $userdata = restore_userdata_selected($restore, "voiceauthoring", $mod->id); if ($data) { //Now get completed xmlized object $info = $data->info; //add logs //Now, build the voiceauthoring record structure $resource = get_record("voiceauthoring_resources", "fromrid", $info['MOD']['#']['RID']['0']['#'], "course", $restore->course_id); if (empty($resource)) { $resourceCopy = voicetools_api_copy_resource($info['MOD']['#']['RID']['0']['#'], null, "0"); if ($resourceCopy === false) { return false; //error to copy the resource } $resourceId = $resourceCopy->getRid(); voiceauthoring_createResourceFromResource($info['MOD']['#']['RID']['0']['#'], $resourceId, $restore->course_id); } if ($userdata === false) { $mid = $resource->mid + 1; $resource->mid = $resource->mid + 1; update_record("voiceauthoring_resources", $resource); $name = str_replace(backup_todb($info['MOD']['#']['MID']['0']['#']), $mid, backup_todb($info['MOD']['#']['NAME']['0']['#'])); } else { $mid = backup_todb(backup_todb($info['MOD']['#']['MID']['0']['#'])); $name = backup_todb($info['MOD']['#']['NAME']['0']['#']); } $voiceauthoring->course = backup_todb($restore->course_id); $voiceauthoring->rid = backup_todb($resourceId); $voiceauthoring->mid = $mid; $voiceauthoring->name = str_replace(backup_todb($info['MOD']['#']['RID']['0']['#']), $resourceId, $name); $voiceauthoring->activityname = backup_todb($info['MOD']['#']['ACTIVITY_NAME']['0']['#']); $voiceauthoring->section = backup_todb($info['MOD']['#']['SECTION']['0']['#']); $voiceauthoring->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); $voiceauthoring->isfirst = 1; //The structure is equal to the db, so insert the voiceauthoring $newid = insert_record("voiceauthoring", $voiceauthoring); //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "voiceauthoring") . " \"" . format_string(stripslashes(stripslashes($voiceauthoring->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 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 insert_category_ids($course, $backup_unique_code, $instances = null) { global $CFG; include_once "{$CFG->dirroot}/mod/quiz/lib.php"; //Create missing categories and reasign orphaned questions. fix_orphaned_questions($course); // First, all categories from this course. $status = execute_sql("INSERT INTO {$CFG->prefix}backup_ids\n (backup_code, table_name, old_id, info)\n SELECT '{$backup_unique_code}', 'question_categories', qc.id, ''\n FROM {$CFG->prefix}question_categories qc\n WHERE qc.course = {$course}", false); // Then published categories from other courses used by the quizzes we are backing up. $from = "{$CFG->prefix}quiz quiz,"; $where = "AND quiz.course = '{$course}'\n AND qqi.quiz = quiz.id"; if (!empty($instances) && is_array($instances) && count($instances)) { $from = ''; $where = 'AND qqi.quiz IN (' . implode(',', array_keys($instances)) . ')'; } $categories = get_records_sql("\n SELECT id, parent, 0 AS childrendone\n FROM {$CFG->prefix}question_categories\n WHERE course <> {$course}\n AND id IN (\n SELECT DISTINCT question.category \n FROM {$CFG->prefix}question question,\n {$from}\n {$CFG->prefix}quiz_question_instances qqi\n WHERE qqi.question = question.id\n {$where}\n )", false); if (!$categories) { $categories = array(); } // Add the parent categories, of these categories up to the top of the category tree. foreach ($categories as $category) { while ($category->parent != 0) { if (array_key_exists($category->parent, $categories)) { // Parent category already on the list. break; } $currentid = $category->id; $category = get_record('question_categories', 'id', $category->parent, '', '', '', '', 'id, parent, 0 AS childrendone'); if ($category) { $categories[$category->id] = $category; } else { // Parent not found: this indicates an error, but just fix it. set_field('question_categories', 'parent', 0, 'id', $currentid); break; } } } // Now we look for categories from other courses containing random questions // in our quiz that select from the category and its subcategories. That implies // those subcategories also need to be backed up. (The categories themselves // and their parents will already have been included.) $categorieswithrandom = get_records_sql("\n SELECT DISTINCT question.category AS id\n FROM {$CFG->prefix}quiz_question_instances qqi,\n {$from}\n {$CFG->prefix}question question\n WHERE question.id = qqi.question\n AND question.qtype = '" . RANDOM . "'\n AND question.questiontext = '1'\n {$where}\n "); if ($categorieswithrandom) { foreach ($categorieswithrandom as $category) { $status = quiz_backup_add_sub_categories($categories, $category->id); } } // Finally, add all these extra categories to the backup_ids table. foreach ($categories as $category) { $status = $status && backup_putid($backup_unique_code, 'question_categories', $category->id, 0); } return $status; }
function voiceemail_restore_mods($mod, $restore) { global $CFG; $status = true; //Get record from backup_ids $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id); $userdata = restore_userdata_selected($restore, "voiceemail", $mod->id); if ($data) { //Now get completed xmlized object $info = $data->info; //add logs //Now, build the voiceemail record structure if ($userdata === true) { $copyOptions = "0"; //top message } else { $copyOptions = "2"; //top message } $oldResource = get_record("voiceemail_resources", "id", $info['MOD']['#']['RID']['0']['#']); $resourceId = $oldResource->rid; $resource = voicetools_api_copy_resource($resourceId, null, $copyOptions); if ($resource === false) { return false; //error to copy the resource } $bdId = voiceemail_createResourceFromResource($resourceId, $resource->getRid(), $restore->course_id); $voiceemail->course = backup_todb($restore->course_id); $voiceemail->rid = backup_todb($bdId); $voiceemail->recipients_email = backup_todb(backup_todb($info['MOD']['#']['RECIPIENTS_EMAIL']['0']['#'])); $voiceemail->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $voiceemail->section = backup_todb($info['MOD']['#']['SECTION']['0']['#']); $voiceemail->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); $voiceemail->isfirst = 1; //The structure is equal to the db, so insert the voiceemail $newid = insert_record("voiceemail", $voiceemail); //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "voiceemail") . " \"" . format_string(stripslashes($voiceemail->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; }
/** * Fonction de sauvegarde de l'activité Podcast. */ function podcast_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; // Now, build the podcast record structure $podcast->course = $restore->course_id; $podcast->userid = backup_todb($info['MOD']['USERID']['0']['#']); $podcast->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $podcast->author = backup_todb($info['MOD']['#']['AUTHOR']['0']['#']); $podcast->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']); $podcast->owner = backup_todb($info['MOD']['#']['OWNER']['0']['#']); $podcast->owner_email = backup_todb($info['MOD']['#']['OWNER_EMAIL']['0']['#']); $podcast->copyright = backup_todb($info['MOD']['#']['COPYRIGHT']['0']['#']); $podcast->lang = backup_todb($info['MOD']['#']['LANG']['0']['#']); $podcast->pubdate = backup_todb($info['MOD']['#']['PUBDATE']['0']['#']); $podcast->image_url = backup_todb($info['MOD']['#']['IMAGE_URL']['0']['#']); $podcast->image_img = backup_todb($info['MOD']['#']['IMAGE_IMG']['0']['#']); $podcast->category = backup_todb($info['MOD']['#']['CATEGORY']['0']['#']); $podcast->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); //The structure is equal to the db, so insert the podcast $newid = insert_record("podcast", $podcast); //We have to recode the userid field $user = backup_getid($restore->backup_unique_code, "user", $item->userid); if ($user) { $podcast->userid = $user->new_id; } //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "podcast") . " \"" . format_string(stripslashes($podcast->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, 'podcast', $mod->id)) { //Restore podcast_items $status = podcast_items_restore_mods($mod->id, $newid, $info, $restore); } } else { $status = false; } } else { $status = 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_map($old_question_id, $new_question_id, $info, $restore) { $multianswers = $info['#']['MULTIANSWERS']['0']['#']['MULTIANSWER']; foreach ($multianswers as $multianswer) { $sequence = $multianswer['#']['SEQUENCE']['0']['#']; $child_question_ids = array_filter(explode(',', $sequence)); foreach ($child_question_ids as $child_question_id) { if (!record_exists('question', 'id', $child_question_id)) { throw new SharingCart_XmlException('cloze child question not found'); } backup_putid($restore->backup_unique_code, 'question', $child_question_id, $child_question_id); } } return backup_putid($restore->backup_unique_code, 'question', $old_question_id, $new_question_id); }
function chat_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 // if necessary, write to restorelog and adjust date/time fields if ($restore->course_startdateoffset) { restore_log_date_changes('Chat', $restore, $info['MOD']['#'], array('CHATTIME')); } //Now, build the CHAT record structure $chat->course = $restore->course_id; $chat->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $chat->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']); $chat->keepdays = backup_todb($info['MOD']['#']['KEEPDAYS']['0']['#']); $chat->studentlogs = backup_todb($info['MOD']['#']['STUDENTLOGS']['0']['#']); $chat->schedule = backup_todb($info['MOD']['#']['SCHEDULE']['0']['#']); $chat->chattime = backup_todb($info['MOD']['#']['CHATTIME']['0']['#']); $chat->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); //The structure is equal to the db, so insert the chat $newid = insert_record("chat", $chat); //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "chat") . " \"" . format_string(stripslashes($chat->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, 'chat', $mod->id)) { //Restore chat_messages $status = chat_messages_restore_mods($mod->id, $newid, $info, $restore); } } else { $status = false; } } else { $status = false; } return $status; }
/** * Restore everything from the given backup. */ function sloodle_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) { // Get the XML backup data as an array $info = $data->info; // Build our SLOODLE DB record $sloodle = new object(); $sloodle->course = $restore->course_id; $sloodle->type = backup_todb($info['MOD']['#']['SUBTYPE']['0']['#']); $sloodle->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $sloodle->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']); $sloodle->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']); $sloodle->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); $newid = insert_record("sloodle", $sloodle); // Inform the user what we are restoring if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "sloodle") . " \"" . format_string(stripslashes($sloodle->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); // Should we restore userdata? $includeuserdata = restore_userdata_selected($restore, 'sloodle', $mod->id); // Attempt to get a SloodleModule object for this module sub-type $dummysession = new SloodleSession(false); // We need to provide this to keep the module happy! $moduleobj = sloodle_load_module($sloodle->type, $dummysession); if ($moduleobj != false) { // Attempt to restore this module's secondary data if (!$moduleobj->restore($newid, $info['MOD']['#']['SECONDARYDATA']['0']['#'], $includeuserdata)) { $status = false; } } else { echo "<li>Failed to fully restore SLOODLE module type {$sloodle->type}. This type may not be available on your installation.</li>"; } } 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 openmeetings_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 // if necessary, write to restorelog and adjust date/time fields if ($restore->course_startdateoffset) { // restore_log_date_changes('openmeetings', $restore, $info['MOD']['#'], array('openmeetingsTIME')); } //Now, build the openmeetings record structure $openmeetings->course = $restore->course_id; $openmeetings->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $openmeetings->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']); $openmeetings->introformat = backup_todb($info['MOD']['#']['INTROFORMAT']['0']['#']); $openmeetings->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); $openmeetings->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']); $openmeetings->teacher = backup_todb($info['MOD']['#']['TEACHER']['0']['#']); $newid = openmeetings_add_instance($openmeetings); //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "openmeetings") . " \"" . format_string(stripslashes($openmeetings->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, 'openmeetings', $mod->id)) { //Restore nothing $status = false; } } else { $status = false; } } else { $status = false; } return $status; }
function slideshow_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 // if necessary, write to restorelog and adjust date/time fields //Now, build the SLIDESHOW record structure $slideshow->course = $restore->course_id; $slideshow->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $slideshow->location = backup_todb($info['MOD']['#']['LOCATION']['0']['#']); $slideshow->layout = backup_todb($info['MOD']['#']['LAYOUT']['0']['#']); $slideshow->filename = backup_todb($info['MOD']['#']['FILENAME']['0']['#']); $slideshow->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); //The structure is equal to the db, so insert the slideshow $newid = insert_record("slideshow", $slideshow); //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "slideshow") . " \"" . format_string(stripslashes($slideshow->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); // // need new instance id of slideshow for captions: $rec = backup_getid($restore->backup_unique_code, "course_modules", $info['MOD']['#']['CAPTIONS']['0']['#']['CAPTION']['3']['#']['SLIDESHOW']['0']['#']); //Restore slideshow_captions $status = slideshow_captions_restore_mods($mod->id, $rec->new_id, $info, $restore); // } else { $status = false; } } else { $status = false; } return $status; }
function jclic_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 JClic record structure $jclic->course = $restore->course_id; $jclic->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $jclic->description = backup_todb($info['MOD']['#']['DESCRIPTION']['0']['#']); $jclic->url = backup_todb($info['MOD']['#']['URL']['0']['#']); $jclic->skin = backup_todb($info['MOD']['#']['SKIN']['0']['#']); $jclic->maxattempts = backup_todb($info['MOD']['#']['MAXATTEMPTS']['0']['#']); $jclic->width = backup_todb($info['MOD']['#']['WIDTH']['0']['#']); $jclic->height = backup_todb($info['MOD']['#']['HEIGHT']['0']['#']); $jclic->avaluation = backup_todb($info['MOD']['#']['AVALUATION']['0']['#']); $jclic->maxgrade = backup_todb($info['MOD']['#']['MAXGRADE']['0']['#']); //The structure is equal to the db, so insert the jclic $newid = insert_record("jclic", $jclic); //Do some output echo "<li>" . get_string("modulename", "jclic") . " \"" . format_string(stripslashes($jclic->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->mods['jclic']->userinfo) { //Restore jclic_sessions $status = jclic_sessions_restore_mods($mod->id, $newid, $info, $restore); } } else { $status = false; } } 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; }
/** * eBook course format restore routine * * @param object $restore Restore object * @param array $data This is the xmlized information underneath FORMATDATA in the backup XML file. **/ function ebook_restore_format_data($restore, $data) { global $CFG; //require_once($CFG->dirroot.'/course/format/ebook/lib.php'); $status = true; // Get the backup data if (!empty($data['FORMATDATA']['#']['PAGES']['0']['#']['PAGE'])) { //$newpageids = array(); // Get all the pages and restore them. $pages = $data['FORMATDATA']['#']['PAGES']['0']['#']['PAGE']; for ($i = 0; $i < count($pages); $i++) { $pageinfo = $pages[$i]; $page = new stdClass(); $page->courseid = $restore->course_id; //$page->id = backup_todb($pageinfo['#']['ID']['0']['#']); //$page->courseid = backup_todb($pageinfo['#']['COURSEID']['0']['#']); $page->chapter = backup_todb($pageinfo['#']['CHAPTER']['0']['#']); $page->page = backup_todb($pageinfo['#']['PAGE']['0']['#']); $page->section = backup_todb($pageinfo['#']['SECTION']['0']['#']); $page->title = backup_todb($pageinfo['#']['TITLE']['0']['#']); $oldid = backup_todb($pageinfo['#']['ID']['0']['#']); if ($newid = insert_record('course_format_ebook', $page)) { //$newpageids[$oldid] = $newid; backup_putid($restore->backup_unique_code, 'course_format_ebook', $oldid, $newid); } else { $status = false; break; } } // Need to remap parentids // foreach($newpageids as $oldid => $newid) { // $parent = get_field('course_format_ebook', 'parent', 'id', $newid); // if (!empty($parent)) { // set_field('course_format_ebook', 'parent', $newpageids[$parent], 'id', $newid); // } // } // Need to fix sortorder for old courses - doesn't do much of anything if sortorder is already OK //$status = $status and page_fix_page_sortorder($restore->course_id); //$status = $status and page_fix_pageitem_sortorder($restore->course_id); // Helps to repair sortorder if an item fails } return $status; }
function attforblock_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; if (count_records('attforblock', 'course', $restore->course_id)) { return false; } //Now, build the attforblock record structure $attforblock->course = $restore->course_id; // $attforblock->teacher = backup_todb($info['MOD']['#']['TEACHER']['0']['#']); $attforblock->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); if (isset($info['MOD']['#']['GRADE'])) { $attforblock->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']); } else { $attforblock->grade = 100; } //The structure is equal to the db, so insert the attforblock $newid = insert_record('attforblock', $attforblock); if ($newid) { //We have the newid, update backup_ids backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid); attforblock_restore_attendance_statuses($mod->id, $newid, $info, $restore); attforblock_restore_attendance_sessions($mod->id, $newid, $info, $restore); //Now check if want to restore user data and do it. if (restore_userdata_selected($restore, 'attforblock', $mod->id)) { attforblock_restore_attendance_log($mod->id, $newid, $info, $restore); } } else { $status = false; } } else { $status = false; } return $status; }
function groupselect_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 $groupselect = new object(); $groupselect->course = $restore->course_id; $groupselect->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $groupselect->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']); $groupselect->password = backup_todb($info['MOD']['#']['PASSWORD']['0']['#']); $groupselect->timeavailable = backup_todb($info['MOD']['#']['TIMEAVAILABLE']['0']['#']); $groupselect->timedue = backup_todb($info['MOD']['#']['TIMEDUE']['0']['#']); $groupselect->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); //The structure is equal to the db, so insert the groupselect $newid = insert_record("groupselect", $groupselect); //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "groupselect") . " \"" . format_string(stripslashes($groupselect->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 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 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 data_content_restore_mods($old_record_id, $new_record_id, $old_data_id, $new_data_id, $recinfo, $restore) { global $CFG, $fieldids; $status = true; $contents = $recinfo['#']['CONTENTS']['0']['#']['CONTENT']; for ($i = 0; $i < sizeof($contents); $i++) { $con_info = $contents[$i]; $oldid = backup_todb($con_info['#']['ID']['0']['#']); $oldfieldid = backup_todb($con_info['#']['FIELDID']['0']['#']); $oldrecordid = backup_todb($con_info['#']['RECORDID']['0']['#']); $content->recordid = $new_record_id; $content->fieldid = $fieldids[$oldfieldid]; $content->content = backup_todb($con_info['#']['CONTENT']['0']['#']); $content->content1 = backup_todb($con_info['#']['CONTENT1']['0']['#']); $content->content2 = backup_todb($con_info['#']['CONTENT2']['0']['#']); $content->content3 = backup_todb($con_info['#']['CONTENT3']['0']['#']); $content->content4 = backup_todb($con_info['#']['CONTENT4']['0']['#']); $newid = insert_record("data_content", $content); //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 $status = $status and data_restore_files($old_data_id, $new_data_id, $oldfieldid, $content->fieldid, $oldrecordid, $content->recordid, $recinfo, $restore); $status = $status and backup_putid($restore->backup_unique_code, "data_content", $oldid, $newid); } else { $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 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 mail_groups_restore_mods($mailid, $info, $restore) { global $CFG; $status = true; //Get the mail_elements array $groups = $info['MOD']['#']['GROUPS']['0']['#']['GROUP']; //Iterate over mail groups (they are held in their logical order) for ($i = 0; $i < sizeof($groups); $i++) { $group_info = $groups[$i]; //We'll need this later!! $oldid = backup_todb($group_info['#']['ID']['0']['#']); //Now, build the mail_group record structure $group->mailid = $mailid; $group->name = backup_todb($group_info['#']['NAME']['0']['#']); $group->timemodified = backup_todb($group_info['#']['TIMEMODIFIED']['0']['#']); //The structure is equal to the db, so insert the mail_group $newid = insert_record("mail_groups", $group); //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, "mail_groups", $oldid, $newid); // backup branch table info for branch tables. if ($status) { if (!mail_members_groups_restore_mods($newid, $group_info, $restore)) { return false; } } } else { $status = false; } } return $status; }
function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys, $more_restore, $secondary_key) { // general purpose function to restore a single record // $restore : (see "hotpot_restore_mods" above) // $status : current status of backup (true or false) // $xml : XML tree of current record // $table : name of Moodle database table to restore to // $foreign_keys : array of foreign keys, if any, specifed as $key=>$value // $key : the name of a field in the current $record // $value : if $value is numeric, then $record->$key is set to $value. // Otherwise $value is assumed to be a table name and $record->$key // is treated as a comma separated list of ids in that table // $more_restore : optional PHP code to be eval(uated) for each record // $secondary_key : // the name of the secondary key field, if any, in the current $record. // If this field is specified, then the current record will only be added // if the $record->$secondarykey value does not already exist in $table // maintain a cache of info on table columns static $table_columns = array(); if (empty($table_columns[$table])) { global $CFG, $db; $table_columns[$table] = $db->MetaColumns("{$CFG->prefix}{$table}"); } // get values for fields in this record $record = new stdClass(); $TAGS = array_keys($xml); foreach ($TAGS as $TAG) { $value = $xml[$TAG][0]['#']; if (is_string($value)) { $tag = strtolower($TAG); $record->{$tag} = backup_todb($value); } } // update foreign keys, if any $ok = true; foreach ($foreign_keys as $key => $value) { if (is_numeric($value)) { $record->{$key} = $value; } else { $key_table = $value; $new_ids = array(); if (isset($record->{$key})) { $old_ids = explode(',', $record->{$key}); foreach ($old_ids as $old_id) { if (empty($old_id)) { // do nothing } else { $key_record = backup_getid($restore->backup_unique_code, $key_table, $old_id); if ($key_record) { $new_ids[] = $key_record->new_id; } else { // foreign key could not be updated if (!defined('RESTORE_SILENTLY')) { print "<ul><li><b>Warning:</b><br/>Foreign key could not be updated:<br/>"; print "'{$key_table}' record (old id={$old_id}) is missing from backup data<br/>"; print "'{$table}' record "; if (isset($record->id)) { print "(old id={$record->id}) "; } print "was not restored</li></ul>"; } $ok = false; } } } } $record->{$key} = implode(',', $new_ids); } } // set md5 keys if necessary (restoring from Moodle<1.6) if ($table == 'hotpot_questions' && empty($record->md5key)) { $record->md5key = md5($record->name); } if ($table == 'hotpot_strings' && empty($record->md5key)) { $record->md5key = md5($record->string); } // check all "not null" fields have been set foreach ($table_columns[$table] as $column) { if ($column->not_null) { $name = $column->name; if ($name != 'id' && empty($record->{$name})) { if (isset($column->default_value)) { $default = $column->default_value; } else { if (preg_match('/int|decimal|double|float|time|year/i', $column->type)) { $default = 0; } else { $default = ''; } } $record->{$name} = $default; } } } // check everything is OK so far if ($ok) { // store old record id, if necessary if (isset($record->id)) { $record->old_id = $record->id; unset($record->id); } // if there is a secondary key field ... if ($secondary_key) { // check to see if a record with the same value already exists $key_records = get_records($table, $secondary_key, $record->{$secondary_key}); if ($key_records) { // set new record id from already existing record $key_record = reset($key_records); $record->id = $key_record->id; } } if (empty($record->id)) { // add the $record (and get new id) $record->id = insert_record($table, $record); } // check $record was added (or found) if (is_numeric($record->id)) { // if there was an old id, save a mapping to the new id if (isset($record->old_id)) { backup_putid($restore->backup_unique_code, $table, $record->old_id, $record->id); } } else { // failed to add (or find) $record if (!defined('RESTORE_SILENTLY')) { print "<ul><li>Record could not be added: table={$table}</li></ul>"; } $status = false; } // restore related records, if required if ($more_restore) { eval($more_restore); } } return $status; }
/** * Page formats restore routine * * @param object $restore Restore object * @param array $data This is the xmlized information underneath FORMATDATA in the backup XML file. **/ function learning_restore_format_data($restore, $data) { global $CFG; require_once $CFG->dirroot . '/course/format/page/lib.php'; $status = true; if (isset($restore->preferences['nopages'])) { // request not to proceed with course format restore return $status; } // Get the backup data if (!empty($data['FORMATDATA']['#']['PAGES']['0']['#']['PAGE'])) { $newpageids = array(); // Get all the pages and restore them, restoring page items along the way. $pages = $data['FORMATDATA']['#']['PAGES']['0']['#']['PAGE']; for ($i = 0; $i < count($pages); $i++) { $pageinfo = $pages[$i]; $page = new stdClass(); $page->courseid = $restore->course_id; $page->nameone = backup_todb($pageinfo['#']['NAMEONE']['0']['#']); $page->nametwo = backup_todb($pageinfo['#']['NAMETWO']['0']['#']); $page->display = backup_todb($pageinfo['#']['DISPLAY']['0']['#']); $page->prefleftwidth = backup_todb($pageinfo['#']['PREFLEFTWIDTH']['0']['#']); $page->prefcenterwidth = backup_todb($pageinfo['#']['PREFCENTERWIDTH']['0']['#']); $page->prefrightwidth = backup_todb($pageinfo['#']['PREFRIGHTWIDTH']['0']['#']); $page->parent = backup_todb($pageinfo['#']['PARENT']['0']['#']); // will remap later when we know all ids are present $page->sortorder = backup_todb($pageinfo['#']['SORTORDER']['0']['#']); $page->template = backup_todb($pageinfo['#']['TEMPLATE']['0']['#']); $page->showbuttons = backup_todb($pageinfo['#']['SHOWBUTTONS']['0']['#']); $oldid = backup_todb($pageinfo['#']['ID']['0']['#']); if ($newid = insert_record('format_page', $page)) { $newpageids[$oldid] = $newid; backup_putid($restore->backup_unique_code, 'format_page', $oldid, $newid); // Now restore the page_items if (isset($pageinfo['#']['ITEMS'])) { $items = $pageinfo['#']['ITEMS']['0']['#']['ITEM']; for ($j = 0; $j < count($items); $j++) { $iteminfo = $items[$j]; $item = new stdClass(); $item->pageid = $newid; $item->cmid = backup_todb($iteminfo['#']['CMID']['0']['#']); if (!empty($item->cmid)) { // Try to remap the cm ID $cmid = backup_getid($restore->backup_unique_code, 'course_modules', $item->cmid); if ($cmid) { $item->cmid = $cmid->new_id; } else { // Failed to remap - could be for various valid reasons - skip this item continue; } } $item->blockinstance = $iteminfo['#']['BLOCKINSTANCE']['0']['#']; // we'll remap blockids when we decode contentlinks $item->position = backup_todb($iteminfo['#']['POSITION']['0']['#']); $item->sortorder = backup_todb($iteminfo['#']['SORTORDER']['0']['#']); $item->visible = backup_todb($iteminfo['#']['VISIBLE']['0']['#']); $itemoldid = backup_todb($pageinfo['#']['ID']['0']['#']); if ($itemnewid = insert_record('format_page_items', $item)) { backup_putid($restore->backup_unique_code, 'format_page_items', $itemoldid, $itemnewid); } else { $status = false; break; } } } } else { $status = false; break; } } // Need to remap parentids foreach ($newpageids as $oldid => $newid) { $parent = get_field('format_page', 'parent', 'id', $newid); if (!empty($parent)) { set_field('format_page', 'parent', $newpageids[$parent], 'id', $newid); } } // Need to fix sortorder for old courses - doesn't do much of anything if sortorder is already OK $status = $status and page_fix_page_sortorder($restore->course_id); $status = $status and page_fix_pageitem_sortorder($restore->course_id); // Helps to repair sortorder if an item fails } return $status; }
function restore_map($old_question_id, $new_question_id, $info, $restore) { $matchs = $info['#']['MATCHS']['0']['#']['MATCH']; foreach ($matchs as $match) { $match_sub_id = backup_todb($match['#']['ID']['0']['#']); if (!record_exists('question_match_sub', 'id', $match_sub_id)) { throw new SharingCart_XmlException('match sub question not found'); } backup_putid($restore->backup_unique_code, 'question_match_sub', $match_sub_id, $match_sub_id); } return backup_putid($restore->backup_unique_code, 'question', $old_question_id, $new_question_id); }