id,files) // // Meaning: pk->primary key field of the table // fk->foreign key to link with parent // nt->nested field (recursive data) // CL->course level info // UL->user level info // files->table may have files) // //----------------------------------------------------------- //This function executes all the restore procedure about this mod function resource_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 RESOURCE record structure $resource->course = $restore->course_id; $resource->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $resource->type = $info['MOD']['#']['TYPE']['0']['#']; $resource->reference = backup_todb($info['MOD']['#']['REFERENCE']['0']['#']); $resource->summary = backup_todb($info['MOD']['#']['SUMMARY']['0']['#']); $resource->alltext = backup_todb($info['MOD']['#']['ALLTEXT']['0']['#']); $resource->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#']; //The structure is equal to the db, so insert the resource $newid = insert_record ("resource",$resource); //Do some output echo ""; } else { $status = false; } return $status; } //Return a content decoded to support interactivities linking. Every module //should have its own. They are called automatically from //resource_decode_content_links_caller() function in each module //in the restore process function resource_decode_content_links ($content,$restore) { global $CFG; $result = $content; //Link to the list of resources $searchstring='/\$@(RESOURCEINDEX)\*([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='/\$@(RESOURCEINDEX)\*('.$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/resource/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/resource/index.php?id='.$old_id,$result); } } } //Link to resource view by moduleid $searchstring='/\$@(RESOURCEVIEWBYID)\*([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='/\$@(RESOURCEVIEWBYID)\*('.$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/resource/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/resource/view.php?id='.$old_id,$result); } } } return $result; } //This function makes all the necessary calls to xxxx_decode_content_links() //function in each module, passing them the desired contents to be decoded //from backup format to destination site/course in order to mantain inter-activities //working in the backup/restore process. It's called from restore_decode_content_links() //function in restore process function resource_decode_content_links_caller($restore) { global $CFG; $status = true; echo ""; return $status; } //This function returns a log record with all the necessay transformations //done. It's used by restore_log_module() to restore modules log. function resource_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; default: echo "action (".$log->module."-".$log->action.") unknow. Not restored
"; //Debug break; } if ($status) { $status = $log; } return $status; } ?>