MDL-23479 backup - label revised & old code deleted (but restore logs)

This commit is contained in:
Eloy Lafuente
2010-07-30 23:01:20 +00:00
parent 35716b8682
commit c61b92fd49
3 changed files with 2 additions and 207 deletions
@@ -52,11 +52,7 @@ class restore_label_activity_task extends restore_activity_task {
* processed by the link decoder
*/
static public function define_decode_contents() {
$contents = array();
$contents[] = new restore_decode_content('label', array('intro'), 'label');
return $contents;
return array();
}
/**
@@ -64,12 +60,6 @@ class restore_label_activity_task extends restore_activity_task {
* to the activity to be executed by the link decoder
*/
static public function define_decode_rules() {
$rules = array();
$rules[] = new restore_decode_rule('LABELVIEWBYID', '/mod/label/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('LABELINDEX', '/mod/label/index.php?id=$1', 'course');
return $rules;
return array();
}
}
-112
View File
@@ -1,112 +0,0 @@
<?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/>.
/**
* Backup supportfor 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 backup procedure about this mod
function label_backup_mods($bf,$preferences) {
global $CFG, $DB;
$status = true;
////Iterate over label table
if ($labels = $DB->get_records ("label","course", array($preferences->backup_course=>"id"))) {
foreach ($labels as $label) {
if (backup_mod_selected($preferences,'label',$label->id)) {
$status = label_backup_one_mod($bf,$preferences,$label);
}
}
}
return $status;
}
function label_backup_one_mod($bf,$preferences,$label) {
global $CFG, $DB;
if (is_numeric($label)) {
$label = $DB->get_record('label', array('id'=>$label));
}
$status = true;
//Start mod
fwrite ($bf,start_tag("MOD",3,true));
//Print assignment data
fwrite ($bf,full_tag("ID",4,false,$label->id));
fwrite ($bf,full_tag("MODTYPE",4,false,"label"));
fwrite ($bf,full_tag("NAME",4,false,$label->name));
fwrite ($bf,full_tag("CONTENT",4,false,$label->intro));
fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$label->timemodified));
//End mod
$status = fwrite ($bf,end_tag("MOD",3,true));
return $status;
}
////Return an array of info (name,value)
function label_check_backup_mods($course,$user_data=false,$backup_unique_code,$instances=null) {
global $DB;
if (!empty($instances) && is_array($instances) && count($instances)) {
$info = array();
foreach ($instances as $id => $instance) {
$info += label_check_backup_mods_instances($instance,$backup_unique_code);
}
return $info;
}
//First the course data
$info[0][0] = get_string("modulenameplural","label");
$info[0][1] = $DB->count_records("label", array("course"=>$course));
return $info;
}
////Return an array of info (name,value)
function label_check_backup_mods_instances($instance,$backup_unique_code) {
//First the course data
$info[$instance->id.'0'][0] = '<b>'.$instance->name.'</b>';
$info[$instance->id.'0'][1] = '';
return $info;
}
-83
View File
@@ -43,89 +43,6 @@ defined('MOODLE_INTERNAL') || die;
//
//-----------------------------------------------------------
//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) {