MDL-22135 - logs restore, course and activities + cleanup
This commit is contained in:
@@ -107,8 +107,8 @@ abstract class backup implements checksumable {
|
||||
const OPERATION_RESTORE ='restore';// We are performing one restore
|
||||
|
||||
// Version (to keep CFG->backup_version (and release) updated automatically)
|
||||
const VERSION = 2010092100;
|
||||
const RELEASE = '2.0 RC1';
|
||||
const VERSION = 2010101000;
|
||||
const RELEASE = '2.0 RC2';
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -229,74 +229,6 @@
|
||||
return fwrite ($bf,end_tag("FORMATDATA",2,true));
|
||||
}
|
||||
|
||||
//Backup log info (time ordered)
|
||||
function backup_log_info($bf,$preferences) {
|
||||
global $CFG, $DB;
|
||||
|
||||
//Number of records to get in every chunk
|
||||
$recordset_size = 1000;
|
||||
|
||||
$status = true;
|
||||
|
||||
//Counter, points to current record
|
||||
$counter = 0;
|
||||
|
||||
//Count records
|
||||
$count_logs = $DB->count_records("log", array("course"=>$preferences->backup_course));
|
||||
|
||||
//Pring logs header
|
||||
if ($count_logs > 0 ) {
|
||||
fwrite ($bf,start_tag("LOGS",2,true));
|
||||
}
|
||||
while ($counter < $count_logs) {
|
||||
//Get a chunk of records
|
||||
$logs = $DB->get_records ("log", array("course"=>$preferences->backup_course),"time","*",$counter,$recordset_size);
|
||||
|
||||
//We have logs
|
||||
if ($logs) {
|
||||
//Iterate
|
||||
foreach ($logs as $log) {
|
||||
//See if it is a valid module to backup
|
||||
if ($log->module == "course" or
|
||||
$log->module == "user" or
|
||||
(array_key_exists($log->module, $preferences->mods) and $preferences->mods[$log->module]->backup == 1)) {
|
||||
// logs with 'upload' in module field are ignored, there is no restore code anyway
|
||||
//Begin log tag
|
||||
fwrite ($bf,start_tag("LOG",3,true));
|
||||
|
||||
//Output log tag
|
||||
fwrite ($bf,full_tag("ID",4,false,$log->id));
|
||||
fwrite ($bf,full_tag("TIME",4,false,$log->time));
|
||||
fwrite ($bf,full_tag("USERID",4,false,$log->userid));
|
||||
fwrite ($bf,full_tag("IP",4,false,$log->ip));
|
||||
fwrite ($bf,full_tag("MODULE",4,false,$log->module));
|
||||
fwrite ($bf,full_tag("CMID",4,false,$log->cmid));
|
||||
fwrite ($bf,full_tag("ACTION",4,false,$log->action));
|
||||
fwrite ($bf,full_tag("URL",4,false,$log->url));
|
||||
fwrite ($bf,full_tag("INFO",4,false,$log->info));
|
||||
|
||||
//End log tag
|
||||
fwrite ($bf,end_tag("LOG",3,true));
|
||||
}
|
||||
//Do some output
|
||||
$counter++;
|
||||
if ($counter % 20 == 0) {
|
||||
echo ".";
|
||||
if ($counter % 400 == 0) {
|
||||
echo "<br />";
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//End logs tag
|
||||
if ($count_logs > 0 ) {
|
||||
$status = fwrite ($bf,end_tag("LOGS",2,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
function backup_gradebook_categories_history_info($bf, $preferences) {
|
||||
global $CFG, $DB;
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ class backup_course_task extends backup_task {
|
||||
|
||||
// Generate the logs file (conditionally)
|
||||
if ($this->get_setting_value('logs')) {
|
||||
//$this->add_step(new backup_course_logs_structure_step('course_logs', 'logs.xml'));
|
||||
$this->add_step(new backup_course_logs_structure_step('course_logs', 'logs.xml'));
|
||||
}
|
||||
|
||||
// Generate the inforef file (must be after ALL steps gathering annotations of ANY type)
|
||||
|
||||
@@ -1184,6 +1184,42 @@ class backup_block_instance_structure_step extends backup_structure_step {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* structure step in charge of constructing the logs.xml file for all the log records found
|
||||
* in course. Note that we are sending to backup ALL the log records having cmid = 0. That
|
||||
* includes some records that won't be restoreable (like 'upload', 'calendar'...) but we do
|
||||
* that just in case they become restored some day in the future
|
||||
*/
|
||||
class backup_course_logs_structure_step extends backup_structure_step {
|
||||
|
||||
protected function define_structure() {
|
||||
|
||||
// Define each element separated
|
||||
|
||||
$logs = new backup_nested_element('logs');
|
||||
|
||||
$log = new backup_nested_element('log', array('id'), array(
|
||||
'time', 'userid', 'ip', 'module',
|
||||
'action', 'url', 'info'));
|
||||
|
||||
// Build the tree
|
||||
|
||||
$logs->add_child($log);
|
||||
|
||||
// Define sources (all the records belonging to the course, having cmid = 0)
|
||||
|
||||
$log->set_source_table('log', array('course' => backup::VAR_COURSEID, 'cmid' => backup_helper::is_sqlparam(0)));
|
||||
|
||||
// Annotations
|
||||
// NOTE: We don't annotate users from logs as far as they MUST be
|
||||
// always annotated by the course (enrol, ras... whatever)
|
||||
|
||||
// Return the root element (logs)
|
||||
|
||||
return $logs;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* structure step in charge of constructing the logs.xml file for all the log records found
|
||||
* in activity
|
||||
@@ -1210,7 +1246,7 @@ class backup_activity_logs_structure_step extends backup_structure_step {
|
||||
|
||||
// Annotations
|
||||
// NOTE: We don't annotate users from logs as far as they MUST be
|
||||
// always annotated by the activity.
|
||||
// always annotated by the activity (true participants).
|
||||
|
||||
// Return the root element (logs)
|
||||
|
||||
|
||||
@@ -146,9 +146,9 @@ abstract class restore_activity_task extends restore_task {
|
||||
$this->add_step(new restore_userscompletion_structure_step('activity_userscompletion', 'completion.xml'));
|
||||
}
|
||||
|
||||
// TODO: Logs (conditionally)
|
||||
// Logs (conditionally)
|
||||
if ($this->get_setting_value('logs')) {
|
||||
//$this->add_step(new restore_activity_logs_structure_step('activity_logs', 'logs.xml'));
|
||||
$this->add_step(new restore_activity_logs_structure_step('activity_logs', 'logs.xml'));
|
||||
}
|
||||
|
||||
// At the end, mark it as built
|
||||
@@ -228,6 +228,16 @@ abstract class restore_activity_task extends restore_task {
|
||||
throw new coding_exception('define_decode_rules() method needs to be overridden in each subclass of restore_activity_task');
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* activity logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
throw new coding_exception('define_restore_log_rules() method needs to be overridden in each subclass of restore_activity_task');
|
||||
}
|
||||
|
||||
// Protected API starts here
|
||||
|
||||
/**
|
||||
|
||||
@@ -82,11 +82,6 @@ class restore_course_task extends restore_task {
|
||||
$this->add_step(new restore_comments_structure_step('course_comments', 'comments.xml'));
|
||||
}
|
||||
|
||||
// Restore course logs (conditionally)
|
||||
if ($this->get_setting_value('logs')) {
|
||||
//$this->add_step(new restore_course_logs_structure_step('course_logs', 'logs.xml'));
|
||||
}
|
||||
|
||||
// At the end, mark it as built
|
||||
$this->built = true;
|
||||
}
|
||||
|
||||
@@ -65,6 +65,12 @@ class restore_final_task extends restore_task {
|
||||
// Decode all the interlinks
|
||||
$this->add_step(new restore_decode_interlinks('decode_interlinks'));
|
||||
|
||||
// Restore course logs (conditionally). They are restored here because we need all
|
||||
// the activities to be already restored
|
||||
if ($this->get_setting_value('logs')) {
|
||||
$this->add_step(new restore_course_logs_structure_step('course_logs', 'course/logs.xml'));
|
||||
}
|
||||
|
||||
// Rebuild course cache to see results, whoah!
|
||||
$this->add_step(new restore_rebuild_course_cache('rebuild_course_cache'));
|
||||
|
||||
@@ -89,6 +95,55 @@ class restore_final_task extends restore_task {
|
||||
$this->plan->execute_after_restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note these are course logs, but are defined and restored
|
||||
* in final task because we need all the activities to be
|
||||
* restored in order to handle some log records properly
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
// module 'course' rules
|
||||
$rules[] = new restore_log_rule('course', 'view', 'view.php?id={course}', '{course}');
|
||||
$rules[] = new restore_log_rule('course', 'guest', 'view.php?id={course}', null);
|
||||
$rules[] = new restore_log_rule('course', 'user report', 'user.php?id={course}&user={user}&mode=[mode]', null);
|
||||
$rules[] = new restore_log_rule('course', 'add mod', '../mod/[modname]/view.php?id={course_module}', '[modname] {[modname]}');
|
||||
$rules[] = new restore_log_rule('course', 'update mod', '../mod/[modname]/view.php?id={course_module}', '[modname] {[modname]}');
|
||||
$rules[] = new restore_log_rule('course', 'delete mod', 'view.php?id={course}', null);
|
||||
$rules[] = new restore_log_rule('course', 'update', 'view.php?id={course}', '');
|
||||
$rules[] = new restore_log_rule('course', 'enrol', 'view.php?id={course}', '{user}');
|
||||
$rules[] = new restore_log_rule('course', 'unenrol', 'view.php?id={course}', '{user}');
|
||||
$rules[] = new restore_log_rule('course', 'editsection', 'editsection.php?id={course_section}', null);
|
||||
$rules[] = new restore_log_rule('course', 'new', 'view.php?id={course}', '');
|
||||
$rules[] = new restore_log_rule('course', 'recent', 'recent.php?id={course}', '');
|
||||
$rules[] = new restore_log_rule('course', 'report log', 'report/log/index.php?id={course}', '{course}');
|
||||
$rules[] = new restore_log_rule('course', 'report live', 'report/live/index.php?id={course}', '{course}');
|
||||
$rules[] = new restore_log_rule('course', 'report outline', 'report/outline/index.php?id={course}', '{course}');
|
||||
$rules[] = new restore_log_rule('course', 'report participation', 'report/participation/index.php?id={course}', '{course}');
|
||||
$rules[] = new restore_log_rule('course', 'report stats', 'report/stats/index.php?id={course}', '{course}');
|
||||
|
||||
// module 'user' rules
|
||||
$rules[] = new restore_log_rule('user', 'view', 'view.php?id={user}&course={course}', '{user}');
|
||||
$rules[] = new restore_log_rule('user', 'change password', 'view.php?id={user}&course={course}', '{user}');
|
||||
$rules[] = new restore_log_rule('user', 'login', 'view.php?id={user}&course={course}', '{user}');
|
||||
$rules[] = new restore_log_rule('user', 'logout', 'view.php?id={user}&course={course}', '{user}');
|
||||
$rules[] = new restore_log_rule('user', 'view all', 'index.php?id={course}', '');
|
||||
$rules[] = new restore_log_rule('user', 'update', 'view.php?id={user}&course={course}', '');
|
||||
|
||||
// rules from other tasks (activities) not belonging to one module instance (cmid = 0), so are restored here
|
||||
$rules = array_merge($rules, restore_logs_processor::register_log_rules_for_course());
|
||||
|
||||
// TODO: Other logs like 'calendar', 'upload'... will go here
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
|
||||
// Protected API starts here
|
||||
|
||||
/**
|
||||
|
||||
@@ -1613,6 +1613,124 @@ class restore_course_completion_structure_step extends restore_structure_step {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This structure step restores course logs (cmid = 0), delegating
|
||||
* the hard work to the corresponding {@link restore_logs_processor} passing the
|
||||
* collection of {@link restore_log_rule} rules to be observed as they are defined
|
||||
* by the task. Note this is only executed based in the 'logs' setting.
|
||||
*
|
||||
* NOTE: This is executed by final task, to have all the activities already restored
|
||||
*
|
||||
* NOTE: Not all course logs are being restored. For now only 'course' and 'user'
|
||||
* records are. There are others like 'calendar' and 'upload' that will be handled
|
||||
* later.
|
||||
*
|
||||
* NOTE: All the missing actions (not able to be restored) are sent to logs for
|
||||
* debugging purposes
|
||||
*/
|
||||
class restore_course_logs_structure_step extends restore_structure_step {
|
||||
|
||||
/**
|
||||
* Conditionally decide if this step should be executed.
|
||||
*
|
||||
* This function checks the following four parameters:
|
||||
*
|
||||
* 1. the course/logs.xml file exists
|
||||
*
|
||||
* @return bool true is safe to execute, false otherwise
|
||||
*/
|
||||
protected function execute_condition() {
|
||||
|
||||
// Check it is included in the backup
|
||||
$fullpath = $this->task->get_taskbasepath();
|
||||
$fullpath = rtrim($fullpath, '/') . '/' . $this->filename;
|
||||
if (!file_exists($fullpath)) {
|
||||
// Not found, can't restore course logs
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function define_structure() {
|
||||
|
||||
$paths = array();
|
||||
|
||||
// Simple, one plain level of information contains them
|
||||
$paths[] = new restore_path_element('log', '/logs/log');
|
||||
|
||||
return $paths;
|
||||
}
|
||||
|
||||
protected function process_log($data) {
|
||||
global $DB;
|
||||
|
||||
$data = (object)($data);
|
||||
|
||||
$data->time = $this->apply_date_offset($data->time);
|
||||
$data->userid = $this->get_mappingid('user', $data->userid);
|
||||
$data->course = $this->get_courseid();
|
||||
$data->cmid = 0;
|
||||
|
||||
// For any reason user wasn't remapped ok, stop processing this
|
||||
if (empty($data->userid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Everything ready, let's delegate to the restore_logs_processor
|
||||
|
||||
// Set some fixed values that will save tons of DB requests
|
||||
$values = array(
|
||||
'course' => $this->get_courseid());
|
||||
// Get instance and process log record
|
||||
$data = restore_logs_processor::get_instance($this->task, $values)->process_log_record($data);
|
||||
|
||||
// If we have data, insert it, else something went wrong in the restore_logs_processor
|
||||
if ($data) {
|
||||
$DB->insert_record('log', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This structure step restores activity logs, extending {@link restore_course_logs_structure_step}
|
||||
* sharing its same structure but modifying the way records are handled
|
||||
*/
|
||||
class restore_activity_logs_structure_step extends restore_course_logs_structure_step {
|
||||
|
||||
protected function process_log($data) {
|
||||
global $DB;
|
||||
|
||||
$data = (object)($data);
|
||||
|
||||
$data->time = $this->apply_date_offset($data->time);
|
||||
$data->userid = $this->get_mappingid('user', $data->userid);
|
||||
$data->course = $this->get_courseid();
|
||||
$data->cmid = $this->task->get_moduleid();
|
||||
|
||||
// For any reason user wasn't remapped ok, stop processing this
|
||||
if (empty($data->userid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Everything ready, let's delegate to the restore_logs_processor
|
||||
|
||||
// Set some fixed values that will save tons of DB requests
|
||||
$values = array(
|
||||
'course' => $this->get_courseid(),
|
||||
'course_module' => $this->task->get_moduleid(),
|
||||
$this->task->get_modulename() => $this->task->get_activityid());
|
||||
// Get instance and process log record
|
||||
$data = restore_logs_processor::get_instance($this->task, $values)->process_log_record($data);
|
||||
|
||||
// If we have data, insert it, else something went wrong in the restore_logs_processor
|
||||
if ($data) {
|
||||
$DB->insert_record('log', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This structure step restores the grade items associated with one activity
|
||||
* All the grade items are made child of the "course" grade item but the original
|
||||
|
||||
+1
-405
@@ -546,392 +546,6 @@
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function creates all the structures for every log in backup file
|
||||
//Depending what has been selected.
|
||||
function restore_create_logs($restore,$xml_file) {
|
||||
global $CFG, $DB;
|
||||
|
||||
//Number of records to get in every chunk
|
||||
$recordset_size = 4;
|
||||
//Counter, points to current record
|
||||
$counter = 0;
|
||||
//To count all the recods to restore
|
||||
$count_logs = 0;
|
||||
|
||||
$status = true;
|
||||
//Check it exists
|
||||
if (!file_exists($xml_file)) {
|
||||
$status = false;
|
||||
}
|
||||
//Get info from xml
|
||||
if ($status) {
|
||||
//count_logs will contain the number of logs entries to process
|
||||
//in backup_ids->info will be the real info (serialized)
|
||||
$count_logs = restore_read_xml_logs($restore,$xml_file);
|
||||
}
|
||||
|
||||
//Now, if we have records in count_logs, we have to restore that logs
|
||||
//from backup_ids. This piece of code makes calls to:
|
||||
// - restore_log_course() if it's a course log
|
||||
// - restore_log_user() if it's a user log
|
||||
// - restore_log_module() if it's a module log.
|
||||
//And all is segmented in chunks to allow large recordsets to be restored !!
|
||||
if ($count_logs > 0) {
|
||||
while ($counter < $count_logs) {
|
||||
//Get a chunk of records
|
||||
//Take old_id twice to avoid adodb limitation
|
||||
$logs = $DB->get_records("backup_ids", array("table_name"=>'log', 'backup_code'=>$restore->backup_unique_code),"old_id","old_id",$counter,$recordset_size);
|
||||
//We have logs
|
||||
if ($logs) {
|
||||
//Iterate
|
||||
foreach ($logs as $log) {
|
||||
//Get the full record from backup_ids
|
||||
$data = backup_getid($restore->backup_unique_code,"log",$log->old_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 LOG record structure
|
||||
$dblog = new stdClass();
|
||||
$dblog->time = backup_todb($info['LOG']['#']['TIME']['0']['#']);
|
||||
$dblog->userid = backup_todb($info['LOG']['#']['USERID']['0']['#']);
|
||||
$dblog->ip = backup_todb($info['LOG']['#']['IP']['0']['#']);
|
||||
$dblog->course = $restore->course_id;
|
||||
$dblog->module = backup_todb($info['LOG']['#']['MODULE']['0']['#']);
|
||||
$dblog->cmid = backup_todb($info['LOG']['#']['CMID']['0']['#']);
|
||||
$dblog->action = backup_todb($info['LOG']['#']['ACTION']['0']['#']);
|
||||
$dblog->url = backup_todb($info['LOG']['#']['URL']['0']['#']);
|
||||
$dblog->info = backup_todb($info['LOG']['#']['INFO']['0']['#']);
|
||||
//We have to recode the userid field
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$dblog->userid);
|
||||
if ($user) {
|
||||
//echo "User ".$dblog->userid." to user ".$user->new_id."<br />"; //Debug
|
||||
$dblog->userid = $user->new_id;
|
||||
}
|
||||
//We have to recode the cmid field (if module isn't "course" or "user")
|
||||
if ($dblog->module != "course" and $dblog->module != "user") {
|
||||
$cm = backup_getid($restore->backup_unique_code,"course_modules",$dblog->cmid);
|
||||
if ($cm) {
|
||||
//echo "Module ".$dblog->cmid." to module ".$cm->new_id."<br />"; //Debug
|
||||
$dblog->cmid = $cm->new_id;
|
||||
} else {
|
||||
$dblog->cmid = 0;
|
||||
}
|
||||
}
|
||||
//print_object ($dblog); //Debug
|
||||
//Now, we redirect to the needed function to make all the work
|
||||
if ($dblog->module == "course") {
|
||||
//It's a course log,
|
||||
$stat = restore_log_course($restore,$dblog);
|
||||
} elseif ($dblog->module == "user") {
|
||||
//It's a user log,
|
||||
$stat = restore_log_user($restore,$dblog);
|
||||
} else {
|
||||
//It's a module log,
|
||||
$stat = restore_log_module($restore,$dblog);
|
||||
}
|
||||
}
|
||||
|
||||
//Do some output
|
||||
$counter++;
|
||||
if ($counter % 10 == 0) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo ".";
|
||||
if ($counter % 200 == 0) {
|
||||
echo "<br />";
|
||||
}
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//We never should arrive here
|
||||
$counter = $count_logs;
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function inserts a course log record, calculating the URL field as necessary
|
||||
function restore_log_course($restore,$log) {
|
||||
global $DB;
|
||||
|
||||
$status = true;
|
||||
$toinsert = false;
|
||||
|
||||
//echo "<hr />Before transformations<br />"; //Debug
|
||||
//print_object($log); //Debug
|
||||
//Depending of the action, we recode different things
|
||||
switch ($log->action) {
|
||||
case "view":
|
||||
$log->url = "view.php?id=".$log->course;
|
||||
$log->info = $log->course;
|
||||
$toinsert = true;
|
||||
break;
|
||||
case "guest":
|
||||
$log->url = "view.php?id=".$log->course;
|
||||
$toinsert = true;
|
||||
break;
|
||||
case "user report":
|
||||
//recode the info field (it's the user id)
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$log->info);
|
||||
if ($user) {
|
||||
$log->info = $user->new_id;
|
||||
//Now, extract the mode from the url field
|
||||
$mode = substr(strrchr($log->url,"="),1);
|
||||
$log->url = "user.php?id=".$log->course."&user=".$log->info."&mode=".$mode;
|
||||
$toinsert = true;
|
||||
}
|
||||
break;
|
||||
case "add mod":
|
||||
//Extract the course_module from the url field
|
||||
$cmid = substr(strrchr($log->url,"="),1);
|
||||
//recode the course_module to see it it has been restored
|
||||
$cm = backup_getid($restore->backup_unique_code,"course_modules",$cmid);
|
||||
if ($cm) {
|
||||
$cmid = $cm->new_id;
|
||||
//Extract the module name and the module id from the info field
|
||||
$modname = strtok($log->info," ");
|
||||
$modid = strtok(" ");
|
||||
//recode the module id to see if it has been restored
|
||||
$mod = backup_getid($restore->backup_unique_code,$modname,$modid);
|
||||
if ($mod) {
|
||||
$modid = $mod->new_id;
|
||||
//Now I have everything so reconstruct url and info
|
||||
$log->info = $modname." ".$modid;
|
||||
$log->url = "../mod/".$modname."/view.php?id=".$cmid;
|
||||
$toinsert = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "update mod":
|
||||
//Extract the course_module from the url field
|
||||
$cmid = substr(strrchr($log->url,"="),1);
|
||||
//recode the course_module to see it it has been restored
|
||||
$cm = backup_getid($restore->backup_unique_code,"course_modules",$cmid);
|
||||
if ($cm) {
|
||||
$cmid = $cm->new_id;
|
||||
//Extract the module name and the module id from the info field
|
||||
$modname = strtok($log->info," ");
|
||||
$modid = strtok(" ");
|
||||
//recode the module id to see if it has been restored
|
||||
$mod = backup_getid($restore->backup_unique_code,$modname,$modid);
|
||||
if ($mod) {
|
||||
$modid = $mod->new_id;
|
||||
//Now I have everything so reconstruct url and info
|
||||
$log->info = $modname." ".$modid;
|
||||
$log->url = "../mod/".$modname."/view.php?id=".$cmid;
|
||||
$toinsert = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "delete mod":
|
||||
$log->url = "view.php?id=".$log->course;
|
||||
$toinsert = true;
|
||||
break;
|
||||
case "update":
|
||||
$log->url = "edit.php?id=".$log->course;
|
||||
$log->info = "";
|
||||
$toinsert = true;
|
||||
break;
|
||||
case "unenrol":
|
||||
//recode the info field (it's the user id)
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$log->info);
|
||||
if ($user) {
|
||||
$log->info = $user->new_id;
|
||||
$log->url = "view.php?id=".$log->course;
|
||||
$toinsert = true;
|
||||
}
|
||||
break;
|
||||
case "enrol":
|
||||
//recode the info field (it's the user id)
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$log->info);
|
||||
if ($user) {
|
||||
$log->info = $user->new_id;
|
||||
$log->url = "view.php?id=".$log->course;
|
||||
$toinsert = true;
|
||||
}
|
||||
break;
|
||||
case "editsection":
|
||||
//Extract the course_section from the url field
|
||||
$secid = substr(strrchr($log->url,"="),1);
|
||||
//recode the course_section to see if it has been restored
|
||||
$sec = backup_getid($restore->backup_unique_code,"course_sections",$secid);
|
||||
if ($sec) {
|
||||
$secid = $sec->new_id;
|
||||
//Now I have everything so reconstruct url and info
|
||||
$log->url = "editsection.php?id=".$secid;
|
||||
$toinsert = true;
|
||||
}
|
||||
break;
|
||||
case "new":
|
||||
$log->url = "view.php?id=".$log->course;
|
||||
$log->info = "";
|
||||
$toinsert = true;
|
||||
break;
|
||||
case "recent":
|
||||
$log->url = "recent.php?id=".$log->course;
|
||||
$log->info = "";
|
||||
$toinsert = true;
|
||||
break;
|
||||
case "report log":
|
||||
$log->url = "report/log/index.php?id=".$log->course;
|
||||
$log->info = $log->course;
|
||||
$toinsert = true;
|
||||
break;
|
||||
case "report live":
|
||||
$log->url = "report/log/live.php?id=".$log->course;
|
||||
$log->info = $log->course;
|
||||
$toinsert = true;
|
||||
break;
|
||||
case "report outline":
|
||||
$log->url = "report/outline/index.php?id=".$log->course;
|
||||
$log->info = $log->course;
|
||||
$toinsert = true;
|
||||
break;
|
||||
case "report participation":
|
||||
$log->url = "report/participation/index.php?id=".$log->course;
|
||||
$log->info = $log->course;
|
||||
$toinsert = true;
|
||||
break;
|
||||
case "report stats":
|
||||
$log->url = "report/stats/index.php?id=".$log->course;
|
||||
$log->info = $log->course;
|
||||
$toinsert = true;
|
||||
break;
|
||||
default:
|
||||
echo "action (".$log->module."-".$log->action.") unknown. Not restored<br />"; //Debug
|
||||
break;
|
||||
}
|
||||
|
||||
//echo "After transformations<br />"; //Debug
|
||||
//print_object($log); //Debug
|
||||
|
||||
//Now if $toinsert is set, insert the record
|
||||
if ($toinsert) {
|
||||
//echo "Inserting record<br />"; //Debug
|
||||
$status = $DB->insert_record("log",$log);
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function inserts a user log record, calculating the URL field as necessary
|
||||
function restore_log_user($restore,$log) {
|
||||
global $DB;
|
||||
|
||||
$status = true;
|
||||
$toinsert = false;
|
||||
|
||||
//echo "<hr />Before transformations<br />"; //Debug
|
||||
//print_object($log); //Debug
|
||||
//Depending of the action, we recode different things
|
||||
switch ($log->action) {
|
||||
case "view":
|
||||
//recode the info field (it's the user id)
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$log->info);
|
||||
if ($user) {
|
||||
$log->info = $user->new_id;
|
||||
$log->url = "view.php?id=".$log->info."&course=".$log->course;
|
||||
$toinsert = true;
|
||||
}
|
||||
break;
|
||||
case "change password":
|
||||
//recode the info field (it's the user id)
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$log->info);
|
||||
if ($user) {
|
||||
$log->info = $user->new_id;
|
||||
$log->url = "view.php?id=".$log->info."&course=".$log->course;
|
||||
$toinsert = true;
|
||||
}
|
||||
break;
|
||||
case "login":
|
||||
//recode the info field (it's the user id)
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$log->info);
|
||||
if ($user) {
|
||||
$log->info = $user->new_id;
|
||||
$log->url = "view.php?id=".$log->info."&course=".$log->course;
|
||||
$toinsert = true;
|
||||
}
|
||||
break;
|
||||
case "logout":
|
||||
//recode the info field (it's the user id)
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$log->info);
|
||||
if ($user) {
|
||||
$log->info = $user->new_id;
|
||||
$log->url = "view.php?id=".$log->info."&course=".$log->course;
|
||||
$toinsert = true;
|
||||
}
|
||||
break;
|
||||
case "view all":
|
||||
$log->url = "view.php?id=".$log->course;
|
||||
$log->info = "";
|
||||
$toinsert = true;
|
||||
case "update":
|
||||
//We split the url by ampersand char
|
||||
$first_part = strtok($log->url,"&");
|
||||
//Get data after the = char. It's the user being updated
|
||||
$userid = substr(strrchr($first_part,"="),1);
|
||||
//Recode the user
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$userid);
|
||||
if ($user) {
|
||||
$log->info = "";
|
||||
$log->url = "view.php?id=".$user->new_id."&course=".$log->course;
|
||||
$toinsert = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
echo "action (".$log->module."-".$log->action.") unknown. Not restored<br />"; //Debug
|
||||
break;
|
||||
}
|
||||
|
||||
//echo "After transformations<br />"; //Debug
|
||||
//print_object($log); //Debug
|
||||
|
||||
//Now if $toinsert is set, insert the record
|
||||
if ($toinsert) {
|
||||
//echo "Inserting record<br />"; //Debug
|
||||
$status = $DB->insert_record("log",$log);
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function inserts a module log record, calculating the URL field as necessary
|
||||
function restore_log_module($restore,$log) {
|
||||
global $DB;
|
||||
|
||||
$status = true;
|
||||
$toinsert = false;
|
||||
|
||||
//echo "<hr />Before transformations<br />"; //Debug
|
||||
//print_object($log); //Debug
|
||||
|
||||
//Now we see if the required function in the module exists
|
||||
$function = $log->module."_restore_logs";
|
||||
if (function_exists($function)) {
|
||||
//Call the function
|
||||
$log = $function($restore,$log);
|
||||
//If everything is ok, mark the insert flag
|
||||
if ($log) {
|
||||
$toinsert = true;
|
||||
}
|
||||
}
|
||||
|
||||
//echo "After transformations<br />"; //Debug
|
||||
//print_object($log); //Debug
|
||||
|
||||
//Now if $toinsert is set, insert the record
|
||||
if ($toinsert) {
|
||||
//echo "Inserting record<br />"; //Debug
|
||||
$status = $DB->insert_record("log",$log);
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
function restore_execute(&$restore,$info,$course_header,&$errorstr) {
|
||||
global $CFG, $USER, $DB, $OUTPUT;
|
||||
|
||||
@@ -978,24 +592,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
//Now create log entries as needed
|
||||
if ($status and ($info->backup_logs == 'true' && $restore->logs)) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo "<li>".get_string("creatinglogentries");
|
||||
}
|
||||
if (!$status = restore_create_logs($restore,$xml_file)) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo $OUTPUT->notification("Could not restore logs!");
|
||||
} else {
|
||||
$errorstr = "Could not restore logs!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo '</li>';
|
||||
}
|
||||
}
|
||||
|
||||
//Now, if all is OK, adjust activity events
|
||||
if ($status) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
@@ -1013,4 +609,4 @@
|
||||
echo '</li>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,8 @@ abstract class backup_controller_dbops extends backup_dbops {
|
||||
// that way, any change in the "template" will be applied here automatically. If this causes
|
||||
// too much slow, we can always forget about the template and keep maintained the xmldb_table
|
||||
// structure inline - manually - here.
|
||||
// TODO: Right now, loading the whole lib/db/install.xml is "eating" 10M, we should
|
||||
// change our way here in order to decrease that memory usage
|
||||
$templatetablename = $realtablename;
|
||||
$targettablename = $temptablename;
|
||||
$xmlfile = $CFG->dirroot . '/lib/db/install.xml';
|
||||
|
||||
@@ -42,7 +42,7 @@ class restore_decode_processor {
|
||||
protected $rules; // Array of restore_decode_rule workers
|
||||
protected $restoreid; // The unique restoreid we are executing
|
||||
protected $sourcewwwroot; // The original wwwroot of the backup file
|
||||
protected $targetwwwroot; // The targer wwwroot of the restore operation
|
||||
protected $targetwwwroot; // The target wwwroot of the restore operation
|
||||
|
||||
public function __construct($restoreid, $sourcewwwroot, $targetwwwroot) {
|
||||
$this->restoreid = $restoreid;
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* @package moodlecore
|
||||
* @subpackage backup-helper
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Helper class used to restore logs, converting all the information as needed
|
||||
*
|
||||
* This class allows each restore task to specify which logs (by action) will
|
||||
* be handled on restore and which transformations will be performed in order
|
||||
* to accomodate them into their new destination
|
||||
*
|
||||
* TODO: Complete phpdocs
|
||||
*/
|
||||
class restore_log_rule implements processable {
|
||||
|
||||
protected $module; // module of the log record
|
||||
protected $action; // action of the log record
|
||||
|
||||
protected $urlread; // url format of the log record in backup file
|
||||
protected $inforead; // info format of the log record in backup file
|
||||
|
||||
protected $modulewrite;// module of the log record to be written (defaults to $module if not specified)
|
||||
protected $actionwrite;// action of the log record to be written (defaults to $action if not specified)
|
||||
|
||||
protected $urlwrite; // url format of the log record to be written (defaults to $urlread if not specified)
|
||||
protected $infowrite;// info format of the log record to be written (defaults to $inforead if not specified)
|
||||
|
||||
protected $urlreadregexp; // Regexps for extracting information from url and info
|
||||
protected $inforeadregexp;
|
||||
|
||||
protected $allpairs; // to acummulate all tokens and values pairs on each log record restored
|
||||
|
||||
protected $urltokens; // tokens present int the $urlread attribute
|
||||
protected $infotokens;// tokens present in the $inforead attribute
|
||||
|
||||
protected $fixedvalues; // Some values that will have precedence over mappings to save tons of DB mappings
|
||||
|
||||
protected $restoreid;
|
||||
|
||||
public function __construct($module, $action, $urlread, $inforead,
|
||||
$modulewrite = null, $actionwrite = null, $urlwrite = null, $infowrite = null) {
|
||||
$this->module = $module;
|
||||
$this->action = $action;
|
||||
$this->urlread = $urlread;
|
||||
$this->inforead = $inforead;
|
||||
$this->modulewrite = is_null($modulewrite) ? $module : $modulewrite;
|
||||
$this->actionwrite= is_null($actionwrite) ? $action : $actionwrite;
|
||||
$this->urlwrite = is_null($urlwrite) ? $urlread : $urlwrite;
|
||||
$this->infowrite= is_null($infowrite) ? $inforead : $infowrite;
|
||||
$this->allpairs = array();
|
||||
$this->urltokens = array();
|
||||
$this->infotokens= array();
|
||||
$this->urlreadregexp = null;
|
||||
$this->inforeadregexp = null;
|
||||
$this->fixedvalues = array();
|
||||
$this->restoreid = null;
|
||||
|
||||
// TODO: validate module, action are valid => exception
|
||||
|
||||
// Calculate regexps and tokens, both for urlread and inforead
|
||||
$this->calculate_url_regexp($this->urlread);
|
||||
$this->calculate_info_regexp($this->inforead);
|
||||
}
|
||||
|
||||
public function set_restoreid($restoreid) {
|
||||
$this->restoreid = $restoreid;
|
||||
}
|
||||
|
||||
public function set_fixed_values($values) {
|
||||
//TODO: check $values is array => exception
|
||||
$this->fixedvalues = $values;
|
||||
}
|
||||
|
||||
public function get_key_name() {
|
||||
return $this->module . '-' . $this->action;
|
||||
}
|
||||
|
||||
public function process($log) {
|
||||
|
||||
// Reset the allpairs array
|
||||
$this->allpairs = array();
|
||||
|
||||
$urlmatches = array();
|
||||
$infomatches = array();
|
||||
// Apply urlreadregexp to the $log->url if necessary
|
||||
if ($this->urlreadregexp) {
|
||||
preg_match($this->urlreadregexp, $log->url, $urlmatches);
|
||||
if (empty($urlmatches)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!is_null($this->urlread)) { // If not null, use it (null means unmodified)
|
||||
$log->url = $this->urlread;
|
||||
}
|
||||
}
|
||||
// Apply inforeadregexp to the $log->info if necessary
|
||||
if ($this->inforeadregexp) {
|
||||
preg_match($this->inforeadregexp, $log->info, $infomatches);
|
||||
if (empty($infomatches)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!is_null($this->inforead)) { // If not null, use it (null means unmodified)
|
||||
$log->info = $this->inforead;
|
||||
}
|
||||
}
|
||||
|
||||
// If there are $urlmatches, let's process them
|
||||
if (!empty($urlmatches)) {
|
||||
array_shift($urlmatches); // Take out first element
|
||||
if (count($urlmatches) !== count($this->urltokens)) { // Number of matches must be number of tokens
|
||||
return false;
|
||||
}
|
||||
// Let's process all the tokens and matches, using them to parse the urlwrite
|
||||
$log->url = $this->parse_tokens_and_matches($this->urltokens, $urlmatches, $this->urlwrite);
|
||||
}
|
||||
|
||||
// If there are $infomatches, let's process them
|
||||
if (!empty($infomatches)) {
|
||||
array_shift($infomatches); // Take out first element
|
||||
if (count($infomatches) !== count($this->infotokens)) { // Number of matches must be number of tokens
|
||||
return false;
|
||||
}
|
||||
// Let's process all the tokens and matches, using them to parse the infowrite
|
||||
$log->info = $this->parse_tokens_and_matches($this->infotokens, $infomatches, $this->infowrite);
|
||||
}
|
||||
|
||||
// Arrived here, if there is any pending token in $log->url or $log->info, stop
|
||||
if ($this->extract_tokens($log->url) || $this->extract_tokens($log->info)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Finally, set module and action
|
||||
$log->module = $this->modulewrite;
|
||||
$log->action = $this->actionwrite;
|
||||
|
||||
return $log;
|
||||
}
|
||||
|
||||
// Protected API starts here
|
||||
|
||||
protected function parse_tokens_and_matches($tokens, $values, $content) {
|
||||
|
||||
$pairs = array_combine($tokens, $values);
|
||||
ksort($pairs); // First literals, then mappings
|
||||
foreach ($pairs as $token => $value) {
|
||||
// If one token has already been processed, continue
|
||||
if (array_key_exists($token, $this->allpairs)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the pair is one literal token, just keep it unmodified
|
||||
if (substr($token, 0, 1) == '[') {
|
||||
$this->allpairs[$token] = $value;
|
||||
|
||||
// If the pair is one mapping token, let's process it
|
||||
} else if (substr($token, 0, 1) == '{') {
|
||||
$ctoken = $token;
|
||||
|
||||
// First, resolve mappings to literals if necessary
|
||||
if (substr($token, 1, 1) == '[') {
|
||||
$literaltoken = trim($token, '{}');
|
||||
if (array_key_exists($literaltoken, $this->allpairs)) {
|
||||
$ctoken = '{' . $this->allpairs[$literaltoken] . '}';
|
||||
}
|
||||
}
|
||||
|
||||
// Look for mapping in fixedvalues before going to DB
|
||||
$plaintoken = trim($ctoken, '{}');
|
||||
if (array_key_exists($plaintoken, $this->fixedvalues)) {
|
||||
$this->allpairs[$token] = $this->fixedvalues[$plaintoken];
|
||||
|
||||
// Last chance, fetch value from backup_ids_temp, via mapping
|
||||
} else {
|
||||
if ($mapping = restore_dbops::get_backup_ids_record($this->restoreid, $plaintoken, $value)) {
|
||||
$this->allpairs[$token] = $mapping->newitemid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply all the conversions array (allpairs) to content
|
||||
krsort($this->allpairs); // First mappings, then literals
|
||||
$content = str_replace(array_keys($this->allpairs), $this->allpairs, $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function calculate_url_regexp($urlexpression) {
|
||||
// Detect all the tokens in the expression
|
||||
if ($tokens = $this->extract_tokens($urlexpression)) {
|
||||
$this->urltokens = $tokens;
|
||||
// Now, build the regexp
|
||||
$this->urlreadregexp = $this->build_regexp($urlexpression, $this->urltokens);
|
||||
}
|
||||
}
|
||||
|
||||
protected function calculate_info_regexp($infoexpression) {
|
||||
// Detect all the tokens in the expression
|
||||
if ($tokens = $this->extract_tokens($infoexpression)) {
|
||||
$this->infotokens = $tokens;
|
||||
// Now, build the regexp
|
||||
$this->inforeadregexp = $this->build_regexp($infoexpression, $this->infotokens);
|
||||
}
|
||||
}
|
||||
|
||||
protected function extract_tokens($expression) {
|
||||
// Extract all the tokens enclosed in square and curly brackets
|
||||
preg_match_all('~\[[^\]]+\]|\{[^\}]+\}~', $expression, $matches);
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
protected function build_regexp($expression, $tokens) {
|
||||
// Replace to temp (and preg_quote() safe) placeholders
|
||||
foreach ($tokens as $token) {
|
||||
$expression = preg_replace('~' . preg_quote($token, '~') . '~', '#@@#@@#', $expression, 1);
|
||||
}
|
||||
// quote the expression
|
||||
$expression = preg_quote($expression, '~');
|
||||
// Replace all the placeholders
|
||||
$expression = preg_replace('~#@@#@@#~', '(.*)', $expression);
|
||||
return '~' . $expression . '~';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* @package moodlecore
|
||||
* @subpackage backup-helper
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
* TODO: Finish phpdocs
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is one varying singleton that, for all the logs corresponding to
|
||||
* one task, is in charge of storing all its {@link restore_log_rule} rules,
|
||||
* dispatching to the correct one and insert/log the resulting information.
|
||||
*
|
||||
* Each time the task getting the instance changes, the rules are completely
|
||||
* reloaded with the ones in the new task. And all rules are informed with
|
||||
* new fixed values if explicity set.
|
||||
*
|
||||
* This class adopts the singleton pattern to be able to provide some persistency
|
||||
* of rules along the restore of all the logs corresponding to one restore_task
|
||||
*/
|
||||
class restore_logs_processor {
|
||||
|
||||
private static $instance; // The current instance of restore_logs_processor
|
||||
private static $task; // The current restore_task instance this processor belongs to
|
||||
private $rules; // Array of restore_log_rule rules (module-action being keys), supports multiple per key
|
||||
|
||||
private function __construct($values) { // Private constructor
|
||||
|
||||
// Constructor has been called, so we need to reload everything
|
||||
// Process rules
|
||||
$this->rules = array();
|
||||
$rules = call_user_func(array(self::$task, 'define_restore_log_rules'));
|
||||
foreach ($rules as $rule) {
|
||||
// TODO: Check it is one restore_log_rule
|
||||
|
||||
// Set rule restoreid
|
||||
$rule->set_restoreid(self::$task->get_restoreid());
|
||||
// Set rule fixed values if needed
|
||||
if (is_array($values) and !empty($values)) {
|
||||
$rule->set_fixed_values($values);
|
||||
}
|
||||
// Add the rule to the associative array
|
||||
if (array_key_exists($rule->get_key_name(), $this->rules)) {
|
||||
$this->rules[$rule->get_key_name()][] = $rule;
|
||||
} else {
|
||||
$this->rules[$rule->get_key_name()] = array($rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_instance($task, $values) {
|
||||
// If the singleton isn't set or if the task is another one, create new instance
|
||||
if (!isset(self::$instance) || self::$task !== $task) {
|
||||
self::$task = $task;
|
||||
self::$instance = new restore_logs_processor($values);
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function process_log_record($log) {
|
||||
// Check we have one restore_log_rule for this log record
|
||||
$keyname = $log->module . '-' . $log->action;
|
||||
if (array_key_exists($keyname, $this->rules)) {
|
||||
// Try it for each rule available
|
||||
foreach ($this->rules[$keyname] as $rule) {
|
||||
$newlog = $rule->process($log);
|
||||
// Some rule has been able to perform the conversion, exit from loop
|
||||
if (!empty($newlog)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Arrived here log is empty, no rule was able to perform the conversion, log the problem
|
||||
if (empty($newlog)) {
|
||||
self::$task->log('Log module-action "' . $keyname . ' process problem. Not restored', backup::LOG_DEBUG);
|
||||
}
|
||||
|
||||
} else { // Action not found log the problem
|
||||
self::$task->log('Log module-action "' . $keyname . ' unknown. Not restored', backup::LOG_DEBUG);
|
||||
$newlog = false;
|
||||
|
||||
}
|
||||
return $newlog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all the activity {@link restore_log_rule} rules
|
||||
* defined in activity task but corresponding to log
|
||||
* records at course level (cmid = 0).
|
||||
*/
|
||||
public static function register_log_rules_for_course() {
|
||||
$tasks = array(); // To get the list of tasks having log rules for course
|
||||
$rules = array(); // To accumulate rules for course
|
||||
|
||||
// Add the module tasks
|
||||
$mods = get_plugin_list('mod');
|
||||
foreach ($mods as $mod => $moddir) {
|
||||
if (class_exists('restore_' . $mod . '_activity_task')) {
|
||||
$tasks[$mod] = 'restore_' . $mod . '_activity_task';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($tasks as $mod => $classname) {
|
||||
if (!method_exists($classname, 'define_restore_log_rules_for_course')) {
|
||||
continue; // This method is optional
|
||||
}
|
||||
// Get restore_log_rule array and accumulate
|
||||
$taskrules = call_user_func(array($classname, 'define_restore_log_rules_for_course'));
|
||||
if (!is_array($taskrules)) {
|
||||
throw new restore_logs_processor_exception('define_restore_log_rules_for_course_not_array', $classname);
|
||||
}
|
||||
$rules = array_merge($rules, $taskrules);
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Exception class used by all the @restore_logs_processor stuff
|
||||
*/
|
||||
class restore_logs_processor_exception extends backup_exception {
|
||||
|
||||
public function __construct($errorcode, $a=NULL, $debuginfo=null) {
|
||||
return parent::__construct($errorcode, $a, $debuginfo);
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,8 @@ require_once($CFG->dirroot . '/backup/util/helper/restore_structure_parser_proce
|
||||
require_once($CFG->dirroot . '/backup/util/helper/restore_decode_rule.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/helper/restore_decode_content.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/helper/restore_decode_processor.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/helper/restore_logs_processor.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/helper/restore_log_rule.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/xml/parser/progressive_parser.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/output/output_controller.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/dbops/backup_dbops.class.php');
|
||||
|
||||
@@ -72,4 +72,41 @@ class restore_assignment_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* assignment logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('assignment', 'add', 'view.php?id={course_module}', '{assignment}');
|
||||
$rules[] = new restore_log_rule('assignment', 'update', 'view.php?id={course_module}', '{assignment}');
|
||||
$rules[] = new restore_log_rule('assignment', 'view', 'view.php?id={course_module}', '{assignment}');
|
||||
$rules[] = new restore_log_rule('assignment', 'upload', 'view.php?a={assignment}', '{assignment}');
|
||||
$rules[] = new restore_log_rule('assignment', 'view submission', 'submissions.php.php?id={course_module}', '{assignment}');
|
||||
$rules[] = new restore_log_rule('assignment', 'update grades', 'submissions.php.php?id={course_module}&user={user}', '{user}');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('assignment', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -722,7 +722,7 @@ class assignment_base {
|
||||
|
||||
//add to log only if updating
|
||||
add_to_log($this->course->id, 'assignment', 'update grades',
|
||||
'submissions.php?id='.$this->assignment->id.'&user='.$submission->userid,
|
||||
'submissions.php?id='.$this->cm->id.'&user='.$submission->userid,
|
||||
$submission->userid, $this->cm->id);
|
||||
}
|
||||
|
||||
@@ -1573,7 +1573,7 @@ class assignment_base {
|
||||
$this->update_grade($submission);
|
||||
|
||||
add_to_log($this->course->id, 'assignment', 'update grades',
|
||||
'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
|
||||
'submissions.php?id='.$this->cm->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
|
||||
if (!is_null($formdata)) {
|
||||
if ($this->type == 'upload' || $this->type == 'uploadsingle') {
|
||||
$mformdata = $formdata->mform->get_data();
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
<?php
|
||||
//This php script contains all the stuff to backup/restore
|
||||
//assignment mods
|
||||
|
||||
//This is the "graphical" structure of the assignment mod:
|
||||
//
|
||||
// assignment
|
||||
// (CL,pk->id)
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// assignment_submisions
|
||||
// (UL,pk->id, fk->assignment,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 returns a log record with all the necessary transformations
|
||||
//done. It's used by restore_log_module() to restore modules log.
|
||||
function assignment_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;
|
||||
case "upload":
|
||||
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?a=".$mod->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "view submission":
|
||||
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 = "submissions.php?id=".$mod->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "update grades":
|
||||
if ($log->cmid) {
|
||||
//Extract the assignment id from the url field
|
||||
$assid = substr(strrchr($log->url,"="),1);
|
||||
//Get the new_id of the module (to recode the info field)
|
||||
$mod = backup_getid($restore->backup_unique_code,$log->module,$assid);
|
||||
if ($mod) {
|
||||
$log->url = "submissions.php?id=".$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;
|
||||
}
|
||||
|
||||
@@ -73,4 +73,40 @@ class restore_chat_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* chat logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('chat', 'add', 'view.php?id={course_module}', '{chat}');
|
||||
$rules[] = new restore_log_rule('chat', 'update', 'view.php?id={course_module}', '{chat}');
|
||||
$rules[] = new restore_log_rule('chat', 'view', 'view.php?id={course_module}', '{chat}');
|
||||
$rules[] = new restore_log_rule('chat', 'talk', 'view.php?id={course_module}', '{chat}');
|
||||
$rules[] = new restore_log_rule('chat', 'report', 'report.php?id={course_module}', '{chat}');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('chat', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
<?php
|
||||
//This php script contains all the stuff to backup/restore
|
||||
//chat mods
|
||||
|
||||
//This is the "graphical" structure of the chat mod:
|
||||
//
|
||||
// chat
|
||||
// (CL,pk->id)
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// chat_messages
|
||||
// (UL,pk->id, fk->chatid)
|
||||
//
|
||||
// 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 returns a log record with all the necessary transformations
|
||||
//done. It's used by restore_log_module() to restore modules log.
|
||||
function chat_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 "talk":
|
||||
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;
|
||||
case "report":
|
||||
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 = "report.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;
|
||||
}
|
||||
|
||||
@@ -72,4 +72,44 @@ class restore_choice_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* choice logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('choice', 'add', 'view.php?id={course_module}', '{choice}');
|
||||
$rules[] = new restore_log_rule('choice', 'update', 'view.php?id={course_module}', '{choice}');
|
||||
$rules[] = new restore_log_rule('choice', 'view', 'view.php?id={course_module}', '{choice}');
|
||||
$rules[] = new restore_log_rule('choice', 'choose', 'view.php?id={course_module}', '{choice}');
|
||||
$rules[] = new restore_log_rule('choice', 'choose again', 'view.php?id={course_module}', '{choice}');
|
||||
$rules[] = new restore_log_rule('choice', 'report', 'report.php?id={course_module}', '{choice}');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
// Fix old wrong uses (missing extension)
|
||||
$rules[] = new restore_log_rule('choice', 'view all', 'index?id={course}', null,
|
||||
null, null, 'index.php?id={course}');
|
||||
$rules[] = new restore_log_rule('choice', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
require_course_login($course);
|
||||
$PAGE->set_pagelayout('incourse');
|
||||
|
||||
add_to_log($course->id, "choice", "view all", "index?id=$course->id", "");
|
||||
add_to_log($course->id, "choice", "view all", "index.php?id=$course->id", "");
|
||||
|
||||
$strchoice = get_string("modulename", "choice");
|
||||
$strchoices = get_string("modulenameplural", "choice");
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
<?php
|
||||
//This php script contains all the stuff to backup/restore
|
||||
//choice mods
|
||||
|
||||
//This is the "graphical" structure of the choice mod:
|
||||
//
|
||||
// choice
|
||||
// (CL,pk->id)----------|
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// choice_options |
|
||||
// (UL,pk->id, fk->choiceid) |
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// choice_answers |
|
||||
// (UL,pk->id, fk->choiceid, fk->optionid)
|
||||
//
|
||||
// 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 returns a log record with all the necessary transformations
|
||||
//done. It's used by restore_log_module() to restore modules log.
|
||||
function choice_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 "choose":
|
||||
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 "choose again":
|
||||
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;
|
||||
case "report":
|
||||
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 = "report.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;
|
||||
}
|
||||
|
||||
@@ -82,4 +82,42 @@ class restore_data_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* data logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('data', 'add', 'view.php?d={data}&rid={data_record}', '{data}');
|
||||
$rules[] = new restore_log_rule('data', 'update', 'view.php?d={data}&rid={data_record}', '{data}');
|
||||
$rules[] = new restore_log_rule('data', 'view', 'view.php?id={course_module}', '{data}');
|
||||
$rules[] = new restore_log_rule('data', 'record delete', 'view.php?id={course_module}', '{data}');
|
||||
$rules[] = new restore_log_rule('data', 'fields add', 'field.php?d={data}&mode=display&fid={data_field}', '{data_field}');
|
||||
$rules[] = new restore_log_rule('data', 'fields update', 'field.php?d={data}&mode=display&fid={data_field}', '{data_field}');
|
||||
$rules[] = new restore_log_rule('data', 'fields delete', 'field.php?d={data}', '[name]');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('data', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
//This php script contains all the stuff to backup/restore data mod
|
||||
|
||||
//This is the "graphical" structure of the data mod:
|
||||
//
|
||||
// data
|
||||
// (CL,pk->id)
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// ---------------------------------------------------------------------------------
|
||||
// | |
|
||||
//data_records (UL,pk->id, fk->data) data_fields (pk->id, fk->data)
|
||||
// | |
|
||||
// | |
|
||||
// ----------------------------------------------------------------------------- |
|
||||
// | | | |
|
||||
//data_ratings(fk->recordid, pk->id) data_comments (fk->recordid, pk->id) | |
|
||||
// data_content(pk->id, fk->recordid, fk->fieldid)
|
||||
//
|
||||
//
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
|
||||
// !! data module never has had this in previous versions of restore. Amazing!
|
||||
function data_restore_logs($restore,$log) {
|
||||
// nothing here, just a reminder for work todo in 2.0
|
||||
}
|
||||
@@ -76,4 +76,40 @@ class restore_feedback_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* feedback logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('feedback', 'add', 'view.php?id={course_module}', '{feedback}');
|
||||
$rules[] = new restore_log_rule('feedback', 'update', 'view.php?id={course_module}', '{feedback}');
|
||||
$rules[] = new restore_log_rule('feedback', 'view', 'view.php?id={course_module}', '{feedback}');
|
||||
$rules[] = new restore_log_rule('feedback', 'submit', 'view.php?id={course_module}', '{feedback}');
|
||||
$rules[] = new restore_log_rule('feedback', 'startcomplete', 'view.php?id={course_module}', '{feedback}');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('feedback', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
<?php
|
||||
//This php script contains all the stuff to backup/restore
|
||||
//feedback mods
|
||||
|
||||
//This is the "graphical" structure of the feedback mod:
|
||||
//
|
||||
// feedback---------------------------------feedback_tracking
|
||||
// (CL,pk->id) (UL, pk->id, fk->feedback,completed)
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// feedback_template feedback_completed
|
||||
// (CL,pk->id) (UL, pk->id, fk->feedback)
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// feedback_item---------------------------------feedback_value
|
||||
// (ML,pk->id, fk->feedback, fk->template) (UL, pk->id, fk->item, fk->completed)
|
||||
//
|
||||
// Meaning: pk->primary key field of the table
|
||||
// fk->foreign key to link with parent
|
||||
// CL->course level info
|
||||
// ML->modul level info
|
||||
// UL->userid level info
|
||||
// message->text of each feedback_posting
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
|
||||
|
||||
//This function returns a log record with all the necessary transformations
|
||||
//done. It's used by restore_log_module() to restore modules log.
|
||||
function feedback_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 "add entry":
|
||||
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 entry":
|
||||
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 responses":
|
||||
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 = "report.php?id=".$log->cmid;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "update feedback":
|
||||
if ($log->cmid) {
|
||||
$log->url = "report.php?id=".$log->cmid;
|
||||
$status = true;
|
||||
}
|
||||
break;
|
||||
case "view all":
|
||||
$log->url = "index.php?id=".$log->course;
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,4 +72,38 @@ class restore_folder_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* folder logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('folder', 'add', 'view.php?id={course_module}', '{folder}');
|
||||
$rules[] = new restore_log_rule('folder', 'edit', 'edit.php?id={course_module}', '{folder}');
|
||||
$rules[] = new restore_log_rule('folder', 'view', 'view.php?id={course_module}', '{folder}');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('folder', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,4 +82,61 @@ class restore_forum_activity_task extends restore_activity_task {
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* forum logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('forum', 'add', 'view.php?id={course_module}', '{forum}');
|
||||
$rules[] = new restore_log_rule('forum', 'update', 'view.php?id={course_module}', '{forum}');
|
||||
$rules[] = new restore_log_rule('forum', 'view', 'view.php?id={course_module}', '{forum}');
|
||||
$rules[] = new restore_log_rule('forum', 'view forum', 'view.php?id={course_module}', '{forum}');
|
||||
$rules[] = new restore_log_rule('forum', 'mark read', 'view.php?f={forum}', '{forum}');
|
||||
$rules[] = new restore_log_rule('forum', 'start tracking', 'view.php?f={forum}', '{forum}');
|
||||
$rules[] = new restore_log_rule('forum', 'stop tracking', 'view.php?f={forum}', '{forum}');
|
||||
$rules[] = new restore_log_rule('forum', 'subscribe', 'view.php?f={forum}', '{forum}');
|
||||
$rules[] = new restore_log_rule('forum', 'unsubscribe', 'view.php?f={forum}', '{forum}');
|
||||
$rules[] = new restore_log_rule('forum', 'subscriber', 'subscribers.php?id={forum}', '{forum}');
|
||||
$rules[] = new restore_log_rule('forum', 'subscribers', 'subscribers.php?id={forum}', '{forum}');
|
||||
$rules[] = new restore_log_rule('forum', 'view subscribers', 'subscribers.php?id={forum}', '{forum}');
|
||||
$rules[] = new restore_log_rule('forum', 'add discussion', 'discuss.php?d={forum_discussion}', '{forum_discussion}');
|
||||
$rules[] = new restore_log_rule('forum', 'view discussion', 'discuss.php?d={forum_discussion}', '{forum_discussion}');
|
||||
$rules[] = new restore_log_rule('forum', 'move discussion', 'discuss.php?d={forum_discussion}', '{forum_discussion}');
|
||||
$rules[] = new restore_log_rule('forum', 'delete discussi', 'view.php?id={course_module}', '{forum}',
|
||||
null, 'delete discussion');
|
||||
$rules[] = new restore_log_rule('forum', 'delete discussion', 'view.php?id={course_module}', '{forum}');
|
||||
$rules[] = new restore_log_rule('forum', 'add post', 'discuss.php?d={forum_discussion}&parent={forum_post}', '{forum_post}');
|
||||
$rules[] = new restore_log_rule('forum', 'update post', 'discuss.php?d={forum_discussion}&parent={forum_post}', '{forum_post}');
|
||||
$rules[] = new restore_log_rule('forum', 'prune post', 'discuss.php?d={forum_discussion}', '{forum_post}');
|
||||
$rules[] = new restore_log_rule('forum', 'delete post', 'discuss.php?d={forum_discussion}', '[post]');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('forum', 'view forums', 'index.php?id={course}', null);
|
||||
$rules[] = new restore_log_rule('forum', 'subscribeall', 'index.php?id={course}', '{course}');
|
||||
$rules[] = new restore_log_rule('forum', 'unsubscribeall', 'index.php?id={course}', '{course}');
|
||||
$rules[] = new restore_log_rule('forum', 'user report', 'user.php?course={course}&id={user}&mode=[mode]', '{user}');
|
||||
$rules[] = new restore_log_rule('forum', 'search', 'search.php?id={course}&search=[searchenc]', '[search]');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,305 +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/>.
|
||||
|
||||
/**
|
||||
* This php script contains all the stuff to backup/restore forum mods
|
||||
*
|
||||
* @package mod-forum
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
//This is the "graphical" structure of the forum mod:
|
||||
//
|
||||
// forum
|
||||
// (CL,pk->id)
|
||||
// |
|
||||
// ---------------------------------------------------
|
||||
// | |
|
||||
// subscriptions forum_discussions
|
||||
//(UL,pk->id, fk->forum) ---------------(UL,pk->id, fk->forum)
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// | forum_posts
|
||||
// |-------------(UL,pk->id,fk->discussion,
|
||||
// | nt->parent,files)
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// forum_read
|
||||
// (UL,pk->id,fk->post
|
||||
//
|
||||
// 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 returns a log record with all the necessary transformations
|
||||
//done. It's used by restore_log_module() to restore modules log.
|
||||
function forum_restore_logs($restore,$log) {
|
||||
global $DB;
|
||||
|
||||
$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 "mark read":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the module (to recode the url and info fields)
|
||||
$mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
|
||||
if ($mod) {
|
||||
$log->url = "view.php?f=".$mod->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "start tracking":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the module (to recode the url and info fields)
|
||||
$mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
|
||||
if ($mod) {
|
||||
$log->url = "view.php?f=".$mod->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "stop tracking":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the module (to recode the url and info fields)
|
||||
$mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
|
||||
if ($mod) {
|
||||
$log->url = "view.php?f=".$mod->new_id;
|
||||
$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 forum":
|
||||
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 forums":
|
||||
$log->url = "index.php?id=".$log->course;
|
||||
$status = true;
|
||||
break;
|
||||
case "subscribeall":
|
||||
$log->url = "index.php?id=".$log->course;
|
||||
$status = true;
|
||||
break;
|
||||
case "unsubscribeall":
|
||||
$log->url = "index.php?id=".$log->course;
|
||||
$status = true;
|
||||
break;
|
||||
case "subscribe":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the module (to recode the info and url field)
|
||||
$mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
|
||||
if ($mod) {
|
||||
$log->url = "view.php?f=".$mod->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "view subscriber":
|
||||
case "view subscribers":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the module (to recode the info and field)
|
||||
$mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
|
||||
if ($mod) {
|
||||
$log->url = "subscribers.php?id=".$mod->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "unsubscribe":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the module (to recode the info and url field)
|
||||
$mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
|
||||
if ($mod) {
|
||||
$log->url = "view.php?f=".$mod->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "add discussion":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the discussion (to recode the info and url field)
|
||||
$dis = backup_getid($restore->backup_unique_code,"forum_discussions",$log->info);
|
||||
if ($dis) {
|
||||
$log->url = "discuss.php?d=".$dis->new_id;
|
||||
$log->info = $dis->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "view discussion":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the discussion (to recode the info and url field)
|
||||
$dis = backup_getid($restore->backup_unique_code,"forum_discussions",$log->info);
|
||||
if ($dis) {
|
||||
$log->url = "discuss.php?d=".$dis->new_id;
|
||||
$log->info = $dis->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "move discussion":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the discussion (to recode the info and url field)
|
||||
$dis = backup_getid($restore->backup_unique_code,"forum_discussions",$log->info);
|
||||
if ($dis) {
|
||||
$log->url = "discuss.php?d=".$dis->new_id;
|
||||
$log->info = $dis->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "delete discussi":
|
||||
case "delete discussion":
|
||||
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 "add post":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the post (to recode the url and info field)
|
||||
$pos = backup_getid($restore->backup_unique_code,"forum_posts",$log->info);
|
||||
if ($pos) {
|
||||
//Get the post record from database
|
||||
$dbpos = $DB->get_record("forum_posts", array("id"=>$pos->new_id));
|
||||
if ($dbpos) {
|
||||
$log->url = "discuss.php?d=".$dbpos->discussion."&parent=".$pos->new_id;
|
||||
$log->info = $pos->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "prune post":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the post (to recode the url and info field)
|
||||
$pos = backup_getid($restore->backup_unique_code,"forum_posts",$log->info);
|
||||
if ($pos) {
|
||||
//Get the post record from database
|
||||
$dbpos = $DB->get_record("forum_posts", array("id"=>$pos->new_id));
|
||||
if ($dbpos) {
|
||||
$log->url = "discuss.php?d=".$dbpos->discussion;
|
||||
$log->info = $pos->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "update post":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the post (to recode the url and info field)
|
||||
$pos = backup_getid($restore->backup_unique_code,"forum_posts",$log->info);
|
||||
if ($pos) {
|
||||
//Get the post record from database
|
||||
$dbpos = $DB->get_record("forum_posts", array("id"=>$pos->new_id));
|
||||
if ($dbpos) {
|
||||
$log->url = "discuss.php?d=".$dbpos->discussion."&parent=".$pos->new_id;
|
||||
$log->info = $pos->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "delete post":
|
||||
if ($log->cmid) {
|
||||
//Extract the discussion id from the url field
|
||||
$disid = substr(strrchr($log->url,"="),1);
|
||||
//Get the new_id of the discussion (to recode the url field)
|
||||
$dis = backup_getid($restore->backup_unique_code,"quiz_discussions",$disid);
|
||||
if ($dis) {
|
||||
$log->url = "discuss.php?d=".$dis->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "user report":
|
||||
//Extract mode from url
|
||||
$mode = substr(strrchr($log->url,"="),1);
|
||||
//Get new user id
|
||||
if ($use = backup_getid($restore->backup_unique_code, 'user', $log->info)) {
|
||||
$log->url = 'user.php?course=' . $log->course . '&id=' . $use->new_id . '&mode=' . $mode;
|
||||
$log->info = $use->new_id;
|
||||
$status = true;
|
||||
}
|
||||
break;
|
||||
case "search":
|
||||
$log->url = "search.php?id=".$log->course."&search=".urlencode($log->info);
|
||||
$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;
|
||||
}
|
||||
|
||||
@@ -73,4 +73,46 @@ class restore_glossary_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* glossary logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('glossary', 'add', 'view.php?id={course_module}', '{glossary}');
|
||||
$rules[] = new restore_log_rule('glossary', 'update', 'view.php?id={course_module}', '{glossary}');
|
||||
$rules[] = new restore_log_rule('glossary', 'view', 'view.php?id={course_module}', '{glossary}');
|
||||
$rules[] = new restore_log_rule('glossary', 'add category', 'editcategories.php?id={course_module}', '{glossary_category}');
|
||||
$rules[] = new restore_log_rule('glossary', 'edit category', 'editcategories.php?id={course_module}', '{glossary_category}');
|
||||
$rules[] = new restore_log_rule('glossary', 'delete category', 'editcategories.php?id={course_module}', '{glossary_category}');
|
||||
$rules[] = new restore_log_rule('glossary', 'add entry', 'view.php?id={course_module}&mode=entry&hook={glossary_entry}', '{glossary_entry}');
|
||||
$rules[] = new restore_log_rule('glossary', 'update entry', 'view.php?id={course_module}&mode=entry&hook={glossary_entry}', '{glossary_entry}');
|
||||
$rules[] = new restore_log_rule('glossary', 'delete entry', 'view.php?id={course_module}&mode=entry&hook={glossary_entry}', '{glossary_entry}');
|
||||
$rules[] = new restore_log_rule('glossary', 'approve entry', 'showentry.php?id={course_module}&eid={glossary_entry}', '{glossary_entry}');
|
||||
$rules[] = new restore_log_rule('glossary', 'view entry', 'showentry.php?eid={glossary_entry}', '{glossary_entry}');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('glossary', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,221 +0,0 @@
|
||||
<?php
|
||||
//This php script contains all the stuff to backup/restore
|
||||
//glossary mods
|
||||
|
||||
//This is the "graphical" structure of the glossary mod:
|
||||
//
|
||||
// glossary ----------------------------------------- glossary_categories
|
||||
// (CL,pk->id) (CL,pk->id,fk->glossaryid)
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// glossary_entries --------------------------------glossary_entries_categories
|
||||
// (UL,pk->id, fk->glossaryid, files) | (UL, pk->categoryid,entryid)
|
||||
// | |
|
||||
// | |--------------------glossary_ratings
|
||||
// | | (UL, pk->id, pk->entryid)
|
||||
// glossary_comments |
|
||||
// (UL,pk->id, fk->entryid) |---------------------glossary_alias
|
||||
// (UL, pk->id, pk->entryid)
|
||||
//
|
||||
//
|
||||
// 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 returns a log record with all the necessary transformations
|
||||
//done. It's used by restore_log_module() to restore modules log.
|
||||
function glossary_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;
|
||||
case "add category":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the glossary_category (to recode the info field)
|
||||
$cat = backup_getid($restore->backup_unique_code,"glossary_categories",$log->info);
|
||||
if ($cat) {
|
||||
$log->url = "editcategories.php?id=".$log->cmid;
|
||||
$log->info = $cat->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "edit category":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the glossary_category (to recode the info field)
|
||||
$cat = backup_getid($restore->backup_unique_code,"glossary_categories",$log->info);
|
||||
if ($cat) {
|
||||
$log->url = "editcategories.php?id=".$log->cmid;
|
||||
$log->info = $cat->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "delete category":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the glossary_category (to recode the info field)
|
||||
$cat = backup_getid($restore->backup_unique_code,"glossary_categories",$log->info);
|
||||
if ($cat) {
|
||||
$log->url = "editcategories.php?id=".$log->cmid;
|
||||
$log->info = $cat->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "add entry":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the glossary_entry (to recode the info and url field)
|
||||
$ent = backup_getid($restore->backup_unique_code,"glossary_entries",$log->info);
|
||||
if ($ent) {
|
||||
$log->url = "view.php?id=".$log->cmid."&mode=entry&hook=".$ent->new_id;
|
||||
$log->info = $ent->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "update entry":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the glossary_entry (to recode the info and url field)
|
||||
$ent = backup_getid($restore->backup_unique_code,"glossary_entries",$log->info);
|
||||
if ($ent) {
|
||||
$log->url = "view.php?id=".$log->cmid."&mode=entry&hook=".$ent->new_id;
|
||||
$log->info = $ent->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "delete entry":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the glossary_entry (to recode the info and url field)
|
||||
$ent = backup_getid($restore->backup_unique_code,"glossary_entries",$log->info);
|
||||
if ($ent) {
|
||||
$log->url = "view.php?id=".$log->cmid."&mode=entry&hook=".$ent->new_id;
|
||||
$log->info = $ent->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "approve entry":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the glossary_entry (to recode the info and url field)
|
||||
$ent = backup_getid($restore->backup_unique_code,"glossary_entries",$log->info);
|
||||
if ($ent) {
|
||||
$log->url = "showentry.php?id=".$log->cmid."&eid=".$ent->new_id;
|
||||
$log->info = $ent->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "view entry":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the glossary_entry (to recode the info and url field)
|
||||
$ent = backup_getid($restore->backup_unique_code,"glossary_entries",$log->info);
|
||||
if ($ent) {
|
||||
$log->url = "showentry.php?&eid=".$ent->new_id;
|
||||
$log->info = $ent->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "add comment":
|
||||
if ($log->cmid) {
|
||||
//Extract the entryid from the url field
|
||||
$entid = substr(strrchr($log->url,"="),1);
|
||||
//Get the new_id of the glossary_entry (to recode the url field)
|
||||
$ent = backup_getid($restore->backup_unique_code,"glossary_entries",$entid);
|
||||
//Get the new_id of the glossary_comment (to recode the info field)
|
||||
$com = backup_getid($restore->backup_unique_code,"glossary_comments",$log->info);
|
||||
if ($ent and $com) {
|
||||
$log->url = "comments.php?id=".$log->cmid."&eid=".$ent->new_id;
|
||||
$log->info = $com->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "update comment":
|
||||
if ($log->cmid) {
|
||||
//Extract the entryid from the url field
|
||||
$entid = substr(strrchr($log->url,"="),1);
|
||||
//Get the new_id of the glossary_entry (to recode the url field)
|
||||
$ent = backup_getid($restore->backup_unique_code,"glossary_entries",$entid);
|
||||
//Get the new_id of the glossary_comment (to recode the info field)
|
||||
$com = backup_getid($restore->backup_unique_code,"glossary_comments",$log->info);
|
||||
if ($ent and $com) {
|
||||
$log->url = "comments.php?id=".$log->cmid."&eid=".$ent->new_id;
|
||||
$log->info = $com->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "delete comment":
|
||||
if ($log->cmid) {
|
||||
//Extract the entryid from the url field
|
||||
$entid = substr(strrchr($log->url,"="),1);
|
||||
//Get the new_id of the glossary_entry (to recode the url field)
|
||||
$ent = backup_getid($restore->backup_unique_code,"glossary_entries",$entid);
|
||||
//Get the new_id of the glossary_comment (to recode the info field)
|
||||
$com = backup_getid($restore->backup_unique_code,"glossary_comments",$log->info);
|
||||
if ($ent and $com) {
|
||||
$log->url = "comments.php?id=".$log->cmid."&eid=".$ent->new_id;
|
||||
$log->info = $com->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;
|
||||
}
|
||||
|
||||
@@ -72,4 +72,38 @@ class restore_imscp_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* imscp logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('imscp', 'add', 'view.php?id={course_module}', '{imscp}');
|
||||
$rules[] = new restore_log_rule('imscp', 'update', 'view.php?id={course_module}', '{imscp}');
|
||||
$rules[] = new restore_log_rule('imscp', 'view', 'view.php?id={course_module}', '{imscp}');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('imscp', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,4 +66,38 @@ class restore_label_activity_task extends restore_activity_task {
|
||||
static public function define_decode_rules() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* label logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('label', 'add', 'view.php?id={course_module}', '{label}');
|
||||
$rules[] = new restore_log_rule('label', 'update', 'view.php?id={course_module}', '{label}');
|
||||
$rules[] = new restore_log_rule('label', 'view', 'view.php?id={course_module}', '{label}');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('label', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,88 +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/>.
|
||||
|
||||
/**
|
||||
* 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 returns a log record with all the necessary 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;
|
||||
}
|
||||
|
||||
@@ -79,4 +79,45 @@ class restore_lesson_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* lesson logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('lesson', 'add', 'view.php?id={course_module}', '{lesson}');
|
||||
$rules[] = new restore_log_rule('lesson', 'update', 'view.php?id={course_module}', '{lesson}');
|
||||
$rules[] = new restore_log_rule('lesson', 'view', 'view.php?id={course_module}', '{lesson}');
|
||||
$rules[] = new restore_log_rule('lesson', 'start', 'view.php?id={course_module}', '{lesson}');
|
||||
$rules[] = new restore_log_rule('lesson', 'end', 'view.php?id={course_module}', '{lesson}');
|
||||
$rules[] = new restore_log_rule('lesson', 'view grade', 'essay.php?id={course_module}', '[name]');
|
||||
$rules[] = new restore_log_rule('lesson', 'update grade', 'essay.php?id={course_module}', '[name]');
|
||||
$rules[] = new restore_log_rule('lesson', 'update email essay grade', 'essay.php?id={course_module}', '[name]');
|
||||
$rules[] = new restore_log_rule('lesson', 'update highscores', 'highscores.php?id={course_module}', '[name]');
|
||||
$rules[] = new restore_log_rule('lesson', 'view highscores', 'highscores.php?id={course_module}', '[name]');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('lesson', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,140 +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/>.
|
||||
|
||||
/**
|
||||
* This php script contains all the stuff to restore lesson mods
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage lesson
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
|
||||
**/
|
||||
|
||||
//This is the "graphical" structure of the lesson mod:
|
||||
//
|
||||
// lesson ----------------------------|--------------------------|--------------------------|
|
||||
// (CL,pk->id) | | |
|
||||
// | | | |
|
||||
// | lesson_grades lesson_high_scores lesson_timer
|
||||
// | (UL, pk->id,fk->lessonid) (UL, pk->id,fk->lessonid) (UL, pk->id,fk->lessonid)
|
||||
// |
|
||||
// |
|
||||
// lesson_pages---------------------------|
|
||||
// (CL,pk->id,fk->lessonid) |
|
||||
// | |
|
||||
// | lesson_branch
|
||||
// | (UL, pk->id,fk->pageid)
|
||||
// lesson_answers
|
||||
// (CL,pk->id,fk->pageid)
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// lesson_attempts
|
||||
// (UL,pk->id,fk->answerid)
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
//This function returns a log record with all the necessary transformations
|
||||
//done. It's used by restore_log_module() to restore modules log.
|
||||
function lesson_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 all":
|
||||
$log->url = "index.php?id=".$log->course;
|
||||
$status = true;
|
||||
break;
|
||||
case "start":
|
||||
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 "end":
|
||||
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 page (to recode the url field)
|
||||
$pag = backup_getid($restore->backup_unique_code,"lesson_pages",$log->info);
|
||||
if ($pag) {
|
||||
$log->url = "view.php?id=".$log->cmid."&action=navigation&pageid=".$pag->new_id;
|
||||
$log->info = $pag->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;
|
||||
}
|
||||
|
||||
@@ -72,4 +72,38 @@ class restore_page_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* page logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('page', 'add', 'view.php?id={course_module}', '{page}');
|
||||
$rules[] = new restore_log_rule('page', 'update', 'view.php?id={course_module}', '{page}');
|
||||
$rules[] = new restore_log_rule('page', 'view', 'view.php?id={course_module}', '{page}');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('page', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,8 +72,7 @@
|
||||
}
|
||||
$accessmanager->do_password_check($attemptobj->is_preview_user());
|
||||
|
||||
/// This action used to be 'continue attempt' but the database field has only 15 characters.
|
||||
add_to_log($attemptobj->get_courseid(), 'quiz', 'continue attemp',
|
||||
add_to_log($attemptobj->get_courseid(), 'quiz', 'continue attempt',
|
||||
'review.php?attempt=' . $attemptobj->get_attemptid(),
|
||||
$attemptobj->get_quizid(), $attemptobj->get_cmid());
|
||||
|
||||
|
||||
@@ -74,4 +74,80 @@ class restore_quiz_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* quiz logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('quiz', 'add', 'view.php?id={course_module}', '{quiz}');
|
||||
$rules[] = new restore_log_rule('quiz', 'update', 'view.php?id={course_module}', '{quiz}');
|
||||
$rules[] = new restore_log_rule('quiz', 'view', 'view.php?id={course_module}', '{quiz}');
|
||||
$rules[] = new restore_log_rule('quiz', 'preview', 'view.php?id={course_module}', '{quiz}');
|
||||
$rules[] = new restore_log_rule('quiz', 'report', 'report.php?id={course_module}', '{quiz}');
|
||||
$rules[] = new restore_log_rule('quiz', 'editquestions', 'view.php?id={course_module}', '{quiz}');
|
||||
$rules[] = new restore_log_rule('quiz', 'delete attempt', 'report.php?id={course_module}', '[oldattempt]');
|
||||
$rules[] = new restore_log_rule('quiz', 'edit override', 'overrideedit.php?id={quiz_override}', '{quiz}');
|
||||
$rules[] = new restore_log_rule('quiz', 'delete override', 'overrides.php.php?cmid={course_module}', '{quiz}');
|
||||
$rules[] = new restore_log_rule('quiz', 'addcategory', 'view.php?id={course_module}', '{question_category}');
|
||||
$rules[] = new restore_log_rule('quiz', 'view summary', 'summary.php?attempt={quiz_attempt_id}', '{quiz}');
|
||||
$rules[] = new restore_log_rule('quiz', 'manualgrade', 'comment.php?attempt={quiz_attempt_id}&question={question}', '{quiz}');
|
||||
$rules[] = new restore_log_rule('quiz', 'manualgrading', 'report.php?mode=grading&q={quiz}', '{quiz}');
|
||||
// All the ones calling to review.php have two rules to handle both old and new urls
|
||||
// in any case they are always converted to new urls on restore
|
||||
// TODO: In Moodle 2.x (x >= 5) kill the old rules
|
||||
// Note we are using the 'quiz_attempt_id' mapping becuase that is the one containing the quiz_attempt->ids
|
||||
// old an new for quiz-attempt
|
||||
$rules[] = new restore_log_rule('quiz', 'attempt', 'review.php?id={course_module}&attempt={quiz_attempt}', '{quiz}',
|
||||
null, null, 'review.php?attempt={quiz_attempt}');
|
||||
// old an new for quiz-submit
|
||||
$rules[] = new restore_log_rule('quiz', 'submit', 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}',
|
||||
null, null, 'review.php?attempt={quiz_attempt_id}');
|
||||
$rules[] = new restore_log_rule('quiz', 'submit', 'review.php?attempt={quiz_attempt_id}', '{quiz}');
|
||||
// old an new for quiz-review
|
||||
$rules[] = new restore_log_rule('quiz', 'review', 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}',
|
||||
null, null, 'review.php?attempt={quiz_attempt_id}');
|
||||
$rules[] = new restore_log_rule('quiz', 'review', 'review.php?attempt={quiz_attempt_id}', '{quiz}');
|
||||
// old an new for quiz-start attemp
|
||||
$rules[] = new restore_log_rule('quiz', 'start attempt', 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}',
|
||||
null, null, 'review.php?attempt={quiz_attempt_id}');
|
||||
$rules[] = new restore_log_rule('quiz', 'start attempt', 'review.php?attempt={quiz_attempt_id}', '{quiz}');
|
||||
// old an new for quiz-close attemp
|
||||
$rules[] = new restore_log_rule('quiz', 'close attempt', 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}',
|
||||
null, null, 'review.php?attempt={quiz_attempt_id}');
|
||||
$rules[] = new restore_log_rule('quiz', 'close attempt', 'review.php?attempt={quiz_attempt_id}', '{quiz}');
|
||||
// old an new for quiz-continue attempt
|
||||
$rules[] = new restore_log_rule('quiz', 'continue attempt', 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}',
|
||||
null, null, 'review.php?attempt={quiz_attempt_id}');
|
||||
$rules[] = new restore_log_rule('quiz', 'continue attempt', 'review.php?attempt={quiz_attempt_id}', '{quiz}');
|
||||
// old an new for quiz-continue attemp
|
||||
$rules[] = new restore_log_rule('quiz', 'continue attemp', 'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}',
|
||||
null, 'continue attempt', 'review.php?attempt={quiz_attempt_id}');
|
||||
$rules[] = new restore_log_rule('quiz', 'continue attemp', 'review.php?attempt={quiz_attempt_id}', '{quiz}',
|
||||
null, 'continue attempt');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('quiz', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,10 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
|
||||
$data->timeopen = $this->apply_date_offset($data->timeopen);
|
||||
$data->timeclose = $this->apply_date_offset($data->timeclose);
|
||||
|
||||
$DB->insert_record('quiz_overrides', $data);
|
||||
$newitemid = $DB->insert_record('quiz_overrides', $data);
|
||||
|
||||
// Add mapping, restore of logs needs it
|
||||
$this->set_mapping('quiz_override', $oldid, $newitemid);
|
||||
}
|
||||
|
||||
protected function process_quiz_grade($data) {
|
||||
@@ -162,9 +165,10 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
|
||||
$newitemid = $DB->insert_record('quiz_attempts', $data);
|
||||
|
||||
// Save quiz_attempt->uniqueid as quiz_attempt mapping, both question_states and
|
||||
// question_sessions have Fk to it and not to quiz_attempts->id at all. In fact
|
||||
// quiz_attempt->id isn't use by anybody
|
||||
// question_sessions have Fk to it and not to quiz_attempts->id at all.
|
||||
$this->set_mapping('quiz_attempt', $olduniqueid, $data->uniqueid, false);
|
||||
// Also save quiz_attempt->id mapping, because logs use it
|
||||
$this->set_mapping('quiz_attempt_id', $oldid, $newitemid, false);
|
||||
}
|
||||
|
||||
protected function after_execute() {
|
||||
|
||||
@@ -1,212 +0,0 @@
|
||||
<?php
|
||||
|
||||
//This function returns a log record with all the necessary transformations
|
||||
//done. It's used by restore_log_module() to restore modules log.
|
||||
function quiz_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;
|
||||
case "report":
|
||||
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 = "report.php?id=".$log->cmid;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "attempt":
|
||||
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) {
|
||||
//Extract the attempt id from the url field
|
||||
$attid = substr(strrchr($log->url,"="),1);
|
||||
//Get the new_id of the attempt (to recode the url field)
|
||||
$att = backup_getid($restore->backup_unique_code,"quiz_attempts",$attid);
|
||||
if ($att) {
|
||||
$log->url = "review.php?id=".$log->cmid."&attempt=".$att->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "submit":
|
||||
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) {
|
||||
//Extract the attempt id from the url field
|
||||
$attid = substr(strrchr($log->url,"="),1);
|
||||
//Get the new_id of the attempt (to recode the url field)
|
||||
$att = backup_getid($restore->backup_unique_code,"quiz_attempts",$attid);
|
||||
if ($att) {
|
||||
$log->url = "review.php?id=".$log->cmid."&attempt=".$att->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "review":
|
||||
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) {
|
||||
//Extract the attempt id from the url field
|
||||
$attid = substr(strrchr($log->url,"="),1);
|
||||
//Get the new_id of the attempt (to recode the url field)
|
||||
$att = backup_getid($restore->backup_unique_code,"quiz_attempts",$attid);
|
||||
if ($att) {
|
||||
$log->url = "review.php?id=".$log->cmid."&attempt=".$att->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "editquestions":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the module (to recode the url 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 "preview":
|
||||
if ($log->cmid) {
|
||||
//Get the new_id of the module (to recode the url field)
|
||||
$mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
|
||||
if ($mod) {
|
||||
$log->url = "attempt.php?id=".$log->cmid;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "start attempt":
|
||||
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) {
|
||||
//Extract the attempt id from the url field
|
||||
$attid = substr(strrchr($log->url,"="),1);
|
||||
//Get the new_id of the attempt (to recode the url field)
|
||||
$att = backup_getid($restore->backup_unique_code,"quiz_attempts",$attid);
|
||||
if ($att) {
|
||||
$log->url = "review.php?id=".$log->cmid."&attempt=".$att->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "close attempt":
|
||||
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) {
|
||||
//Extract the attempt id from the url field
|
||||
$attid = substr(strrchr($log->url,"="),1);
|
||||
//Get the new_id of the attempt (to recode the url field)
|
||||
$att = backup_getid($restore->backup_unique_code,"quiz_attempts",$attid);
|
||||
if ($att) {
|
||||
$log->url = "review.php?id=".$log->cmid."&attempt=".$att->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "continue attempt":
|
||||
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) {
|
||||
//Extract the attempt id from the url field
|
||||
$attid = substr(strrchr($log->url,"="),1);
|
||||
//Get the new_id of the attempt (to recode the url field)
|
||||
$att = backup_getid($restore->backup_unique_code,"quiz_attempts",$attid);
|
||||
if ($att) {
|
||||
$log->url = "review.php?id=".$log->cmid."&attempt=".$att->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "continue attemp":
|
||||
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) {
|
||||
//Extract the attempt id from the url field
|
||||
$attid = substr(strrchr($log->url,"="),1);
|
||||
//Get the new_id of the attempt (to recode the url field)
|
||||
$att = backup_getid($restore->backup_unique_code,"quiz_attempts",$attid);
|
||||
if ($att) {
|
||||
$log->url = "review.php?id=".$log->cmid."&attempt=".$att->new_id;
|
||||
$log->info = $mod->new_id;
|
||||
$log->action = "continue attempt"; //To recover some bad actions
|
||||
$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;
|
||||
}
|
||||
@@ -72,4 +72,38 @@ class restore_resource_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* resource logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('resource', 'add', 'view.php?id={course_module}', '{resource}');
|
||||
$rules[] = new restore_log_rule('resource', 'update', 'view.php?id={course_module}', '{resource}');
|
||||
$rules[] = new restore_log_rule('resource', 'view', 'view.php?id={course_module}', '{resource}');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('resource', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,4 +72,42 @@ class restore_scorm_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* scorm logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('scorm', 'add', 'view.php?id={course_module}', '{scorm}');
|
||||
$rules[] = new restore_log_rule('scorm', 'update', 'view.php?id={course_module}', '{scorm}');
|
||||
$rules[] = new restore_log_rule('scorm', 'view', 'player.php?cm={course_module}&scoid={scorm_sco}', '{scorm}');
|
||||
$rules[] = new restore_log_rule('scorm', 'pre-view', 'view.php?id={course_module}', '{scorm}');
|
||||
$rules[] = new restore_log_rule('scorm', 'report', 'report.php?id={course_module}', '{scorm}');
|
||||
$rules[] = new restore_log_rule('scorm', 'launch', 'view.php?id={course_module}', '[result]');
|
||||
$rules[] = new restore_log_rule('scorm', 'delete attempts', 'report.php?id={course_module}', '[oldattempts]');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('scorm', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
//This php script contains all the stuff to backup/restore
|
||||
//reservation mods
|
||||
|
||||
//This is the "graphical" structure of the scorm mod:
|
||||
//
|
||||
// scorm
|
||||
// (CL,pk->id)---------------------
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// scorm_scoes |
|
||||
// (UL,pk->id, fk->scorm) |
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// scorm_scoes_track |
|
||||
// (UL,pk->id, fk->scormid, fk->scoid, fk->userid)--
|
||||
//
|
||||
// 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 returns a log record with all the necessary transformations
|
||||
//done. It's used by restore_log_module() to restore modules log.
|
||||
function scorm_restore_logs($restore,$log) {
|
||||
|
||||
$status = true;
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
@@ -72,4 +72,43 @@ class restore_survey_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* survey logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('survey', 'add', 'view.php?id={course_module}', '{survey}');
|
||||
$rules[] = new restore_log_rule('survey', 'update', 'view.php?id={course_module}', '{survey}');
|
||||
$rules[] = new restore_log_rule('survey', 'view', 'view.php?id={course_module}', '{survey}');
|
||||
$rules[] = new restore_log_rule('survey', 'download', 'download.php?id={course_module}&type=[type]&group=[group]', '{survey}');
|
||||
$rules[] = new restore_log_rule('survey', 'view report', 'report.php?id={course_module}', '{survey}');
|
||||
$rules[] = new restore_log_rule('survey', 'submit', 'view.php?id={course_module}', '{survey}');
|
||||
$rules[] = new restore_log_rule('survey', 'view graph', 'view.php?id={course_module}', '{survey}');
|
||||
$rules[] = new restore_log_rule('survey', 'view form', 'view.php?id={course_module}', '{survey}');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('survey', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
<?php
|
||||
//This php script contains all the stuff to backup/restore
|
||||
//survey mods
|
||||
|
||||
//This is the "graphical" structure of the survey mod:
|
||||
// --------------------
|
||||
// survey | survey_questions |
|
||||
// (CL,pk->id) |(CL,pk->id,?????) |
|
||||
// | --------------------
|
||||
// |
|
||||
// -----------------------------------
|
||||
// | |
|
||||
// survey_analysis survey_answers
|
||||
// (UL,pk->id, fk->survey) (UL,pk->id, fk->survey)
|
||||
//
|
||||
// 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 returns a log record with all the necessary transformations
|
||||
//done. It's used by restore_log_module() to restore modules log.
|
||||
function survey_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 "submit":
|
||||
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 form":
|
||||
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 graph":
|
||||
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 report":
|
||||
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 = "report.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;
|
||||
case "download":
|
||||
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) {
|
||||
//Rebuild the url, extracting the type (txt, xls)
|
||||
$filetype = substr($log->url,-3);
|
||||
$log->url = "download.php?id=".$log->cmid."&type=".$filetype;
|
||||
$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;
|
||||
}
|
||||
|
||||
@@ -73,4 +73,38 @@ class restore_url_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* url logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('url', 'add', 'view.php?id={course_module}', '{url}');
|
||||
$rules[] = new restore_log_rule('url', 'update', 'view.php?id={course_module}', '{url}');
|
||||
$rules[] = new restore_log_rule('url', 'view', 'view.php?id={course_module}', '{url}');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('url', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,4 +74,47 @@ class restore_wiki_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* wiki logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('wiki', 'add', 'view.php?id={course_module}', '{wiki}');
|
||||
$rules[] = new restore_log_rule('wiki', 'update', 'view.php?id={course_module}', '{wiki}');
|
||||
$rules[] = new restore_log_rule('wiki', 'view', 'view.php?id={course_module}', '{wiki}');
|
||||
$rules[] = new restore_log_rule('wiki', 'comments', 'comments.php?id={course_module}', '{wiki}');
|
||||
$rules[] = new restore_log_rule('wiki', 'diff', 'diff.php?id={course_module}', '{wiki}');
|
||||
$rules[] = new restore_log_rule('wiki', 'edit', 'edit.php?id={course_module}', '{wiki}');
|
||||
$rules[] = new restore_log_rule('wiki', 'history', 'history.php?id={course_module}', '{wiki}');
|
||||
$rules[] = new restore_log_rule('wiki', 'map', 'map.php?id={course_module}', '{wiki}');
|
||||
$rules[] = new restore_log_rule('wiki', 'overridelocks', 'overridelocks.php?id={course_module}', '{wiki}');
|
||||
/// TODO: Examine these 2 rules, because module is not "wiki", and it shouldn't happen
|
||||
$rules[] = new restore_log_rule('restore', 'restore', 'view.php?id={course_module}', '{wiki}');
|
||||
$rules[] = new restore_log_rule('createpage', 'createpage', 'view.php?id={course_module}', '{wiki}');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('wiki', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,4 +77,38 @@ class restore_workshop_activity_task extends restore_activity_task {
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* workshop logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*/
|
||||
static public function define_restore_log_rules() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('workshop', 'add', 'view.php?id={course_module}', '{workshop}');
|
||||
$rules[] = new restore_log_rule('workshop', 'update', 'view.php?id={course_module}', '{workshop}');
|
||||
$rules[] = new restore_log_rule('workshop', 'view', 'view.php?id={course_module}', '[name]');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the restore log rules that will be applied
|
||||
* by the {@link restore_logs_processor} when restoring
|
||||
* course logs. It must return one array
|
||||
* of {@link restore_log_rule} objects
|
||||
*
|
||||
* Note this rules are applied when restoring course logs
|
||||
* by the restore final task, but are defined here at
|
||||
* activity level. All them are rules not linked to any module instance (cmid = 0)
|
||||
*/
|
||||
static public function define_restore_log_rules_for_course() {
|
||||
$rules = array();
|
||||
|
||||
$rules[] = new restore_log_rule('workshop', 'view all', 'index.php?id={course}', null);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user