mirror of
https://github.com/moodle/moodle.git
synced 2025-01-20 15:08:32 +01:00
4130af7552
are restored properly (I think) :-)
109 lines
3.8 KiB
PHP
109 lines
3.8 KiB
PHP
<?PHP //$Id$
|
|
//This php script contains all the stuff to backup/restore
|
|
//label mods
|
|
|
|
//This is the "graphical" structure of the label mod:
|
|
//
|
|
// label
|
|
// (CL,pk->id)
|
|
//
|
|
// 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 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
|
|
echo "<ul><li>".get_string("modulename","label")." \"".$label->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);
|
|
|
|
} else {
|
|
$status = false;
|
|
}
|
|
|
|
//Finalize ul
|
|
echo "</ul>";
|
|
|
|
} else {
|
|
$status = false;
|
|
}
|
|
|
|
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 label_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;
|
|
default:
|
|
echo "action (".$log->module."-".$log->action.") unknow. Not restored<br>"; //Debug
|
|
break;
|
|
}
|
|
|
|
if ($status) {
|
|
$status = $log;
|
|
}
|
|
return $status;
|
|
}
|
|
?>
|