mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
171 lines
6.1 KiB
PHP
171 lines
6.1 KiB
PHP
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
//
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
/**
|
|
* Resto support for label module
|
|
*
|
|
* @package mod
|
|
* @subpackage label
|
|
* @copyright 2003 onwards Martin Dougiamas {@link http://moodle.com}
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
|
|
defined('MOODLE_INTERNAL') || die;
|
|
|
|
//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, $DB;
|
|
|
|
$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->intro = backup_todb($info['MOD']['#']['CONTENT']['0']['#']);
|
|
$label->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#'];
|
|
|
|
//The structure is equal to the db, so insert the label
|
|
$newid = $DB->insert_record ("label",$label);
|
|
|
|
//Do some output
|
|
if (!defined('RESTORE_SILENTLY')) {
|
|
echo "<li>".get_string("modulename","label")." \"".format_string($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 label_decode_content_links_caller($restore) {
|
|
global $CFG, $DB;
|
|
$status = true;
|
|
|
|
if ($labels = $DB->get_records('label', array('course'=>$restore->course_id), '', "id,content")) {
|
|
$i = 0; //Counter to send some output to the browser to avoid timeouts
|
|
foreach ($labels as $label) {
|
|
//Increment counter
|
|
$i++;
|
|
$content = $label->intro;
|
|
$result = restore_decode_content_links_worker($content,$restore);
|
|
|
|
if ($result != $content) {
|
|
//Update record
|
|
$label->intro = $result;
|
|
$status = $DB->update_record("label", $label);
|
|
if (debugging()) {
|
|
if (!defined('RESTORE_SILENTLY')) {
|
|
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
|
|
}
|
|
}
|
|
}
|
|
//Do some output
|
|
if (($i+1) % 5 == 0) {
|
|
if (!defined('RESTORE_SILENTLY')) {
|
|
echo ".";
|
|
if (($i+1) % 100 == 0) {
|
|
echo "<br />";
|
|
}
|
|
}
|
|
backup_flush(300);
|
|
}
|
|
}
|
|
}
|
|
return $status;
|
|
}
|
|
|
|
//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:
|
|
if (!defined('RESTORE_SILENTLY')) {
|
|
echo "action (".$log->module."-".$log->action.") unknown. Not restored<br />"; //Debug
|
|
}
|
|
break;
|
|
}
|
|
|
|
if ($status) {
|
|
$status = $log;
|
|
}
|
|
return $status;
|
|
}
|
|
|