From 0f66acede00ed04826ae43a36b877251ea17a486 Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Thu, 11 Nov 2010 19:46:04 +0000 Subject: [PATCH] MDL-22135 - logs restore, course and activities + cleanup --- backup/backup.class.php | 4 +- backup/backuplib.php | 68 --- backup/moodle2/backup_course_task.class.php | 2 +- backup/moodle2/backup_stepslib.php | 38 +- .../moodle2/restore_activity_task.class.php | 14 +- backup/moodle2/restore_course_task.class.php | 5 - backup/moodle2/restore_final_task.class.php | 55 +++ backup/moodle2/restore_stepslib.php | 118 +++++ backup/restorelib.php | 406 +----------------- .../dbops/backup_controller_dbops.class.php | 2 + .../helper/restore_decode_processor.class.php | 2 +- backup/util/helper/restore_log_rule.class.php | 246 +++++++++++ .../helper/restore_logs_processor.class.php | 143 ++++++ backup/util/includes/restore_includes.php | 2 + ...restore_assignment_activity_task.class.php | 37 ++ mod/assignment/lib.php | 4 +- mod/assignment/restorelib.php | 116 ----- .../restore_chat_activity_task.class.php | 36 ++ mod/chat/restorelib.php | 102 ----- .../restore_choice_activity_task.class.php | 40 ++ mod/choice/index.php | 2 +- mod/choice/restorelib.php | 119 ----- .../restore_data_activity_task.class.php | 38 ++ mod/data/restorelib.php | 35 -- .../restore_feedback_activity_task.class.php | 36 ++ mod/feedback/restorelib.php | 127 ------ .../restore_folder_activity_task.class.php | 34 ++ .../restore_forum_activity_task.class.php | 57 +++ mod/forum/restorelib.php | 305 ------------- .../restore_glossary_activity_task.class.php | 42 ++ mod/glossary/restorelib.php | 221 ---------- .../restore_imscp_activity_task.class.php | 34 ++ .../restore_label_activity_task.class.php | 34 ++ mod/label/restorelib.php | 88 ---- .../restore_lesson_activity_task.class.php | 41 ++ mod/lesson/restorelib.php | 140 ------ .../restore_page_activity_task.class.php | 34 ++ mod/quiz/attempt.php | 3 +- .../restore_quiz_activity_task.class.php | 76 ++++ .../backup/moodle2/restore_quiz_stepslib.php | 10 +- mod/quiz/restorelib.php | 212 --------- .../restore_resource_activity_task.class.php | 34 ++ .../restore_scorm_activity_task.class.php | 38 ++ mod/scorm/restorelib.php | 38 -- .../restore_survey_activity_task.class.php | 39 ++ mod/survey/restorelib.php | 129 ------ .../restore_url_activity_task.class.php | 34 ++ .../restore_wiki_activity_task.class.php | 43 ++ .../restore_workshop_activity_task.class.php | 34 ++ 49 files changed, 1392 insertions(+), 2125 deletions(-) create mode 100644 backup/util/helper/restore_log_rule.class.php create mode 100644 backup/util/helper/restore_logs_processor.class.php delete mode 100644 mod/assignment/restorelib.php delete mode 100644 mod/chat/restorelib.php delete mode 100644 mod/choice/restorelib.php delete mode 100644 mod/data/restorelib.php delete mode 100644 mod/feedback/restorelib.php delete mode 100644 mod/forum/restorelib.php delete mode 100644 mod/glossary/restorelib.php delete mode 100644 mod/label/restorelib.php delete mode 100644 mod/lesson/restorelib.php delete mode 100644 mod/quiz/restorelib.php delete mode 100755 mod/scorm/restorelib.php delete mode 100644 mod/survey/restorelib.php diff --git a/backup/backup.class.php b/backup/backup.class.php index b09d8e44aaa..d1d364aed6f 100644 --- a/backup/backup.class.php +++ b/backup/backup.class.php @@ -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'; } /* diff --git a/backup/backuplib.php b/backup/backuplib.php index 3eaea31879c..b79646fa8e3 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -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 "
"; - } - 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; diff --git a/backup/moodle2/backup_course_task.class.php b/backup/moodle2/backup_course_task.class.php index 1076dfeed8b..2492925a5d3 100644 --- a/backup/moodle2/backup_course_task.class.php +++ b/backup/moodle2/backup_course_task.class.php @@ -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) diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index 7db2d98eab5..269ad4bc251 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -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) diff --git a/backup/moodle2/restore_activity_task.class.php b/backup/moodle2/restore_activity_task.class.php index bdddd2e0761..51962c2d7e1 100644 --- a/backup/moodle2/restore_activity_task.class.php +++ b/backup/moodle2/restore_activity_task.class.php @@ -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 /** diff --git a/backup/moodle2/restore_course_task.class.php b/backup/moodle2/restore_course_task.class.php index 7591efb3bdd..0e6896a28b0 100644 --- a/backup/moodle2/restore_course_task.class.php +++ b/backup/moodle2/restore_course_task.class.php @@ -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; } diff --git a/backup/moodle2/restore_final_task.class.php b/backup/moodle2/restore_final_task.class.php index 95132ff42c0..cebf2ea9e11 100644 --- a/backup/moodle2/restore_final_task.class.php +++ b/backup/moodle2/restore_final_task.class.php @@ -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 /** diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index f0e06ba2e29..1664f2a0186 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -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 diff --git a/backup/restorelib.php b/backup/restorelib.php index e770dcd1c74..d9ad84b3c97 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -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."
"; //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."
"; //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 "
"; - } - } - 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 "
Before transformations
"; //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
"; //Debug - break; - } - - //echo "After transformations
"; //Debug - //print_object($log); //Debug - - //Now if $toinsert is set, insert the record - if ($toinsert) { - //echo "Inserting record
"; //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 "
Before transformations
"; //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
"; //Debug - break; - } - - //echo "After transformations
"; //Debug - //print_object($log); //Debug - - //Now if $toinsert is set, insert the record - if ($toinsert) { - //echo "Inserting record
"; //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 "
Before transformations
"; //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
"; //Debug - //print_object($log); //Debug - - //Now if $toinsert is set, insert the record - if ($toinsert) { - //echo "Inserting record
"; //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 "
  • ".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 '
  • '; - } - } - //Now, if all is OK, adjust activity events if ($status) { if (!defined('RESTORE_SILENTLY')) { @@ -1013,4 +609,4 @@ echo ''; } } - } \ No newline at end of file + } diff --git a/backup/util/dbops/backup_controller_dbops.class.php b/backup/util/dbops/backup_controller_dbops.class.php index cc7c6311563..6c59c568946 100644 --- a/backup/util/dbops/backup_controller_dbops.class.php +++ b/backup/util/dbops/backup_controller_dbops.class.php @@ -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'; diff --git a/backup/util/helper/restore_decode_processor.class.php b/backup/util/helper/restore_decode_processor.class.php index 1fdddb3e2a3..8716029881f 100644 --- a/backup/util/helper/restore_decode_processor.class.php +++ b/backup/util/helper/restore_decode_processor.class.php @@ -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; diff --git a/backup/util/helper/restore_log_rule.class.php b/backup/util/helper/restore_log_rule.class.php new file mode 100644 index 00000000000..bb7d4e3faa4 --- /dev/null +++ b/backup/util/helper/restore_log_rule.class.php @@ -0,0 +1,246 @@ +. + +/** + * @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 . '~'; + } +} diff --git a/backup/util/helper/restore_logs_processor.class.php b/backup/util/helper/restore_logs_processor.class.php new file mode 100644 index 00000000000..e4c8176eae8 --- /dev/null +++ b/backup/util/helper/restore_logs_processor.class.php @@ -0,0 +1,143 @@ +. + +/** + * @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); + } +} diff --git a/backup/util/includes/restore_includes.php b/backup/util/includes/restore_includes.php index 4973e7597e6..8cbe6817e98 100644 --- a/backup/util/includes/restore_includes.php +++ b/backup/util/includes/restore_includes.php @@ -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'); diff --git a/mod/assignment/backup/moodle2/restore_assignment_activity_task.class.php b/mod/assignment/backup/moodle2/restore_assignment_activity_task.class.php index c693b586199..e5d8a7f37d5 100644 --- a/mod/assignment/backup/moodle2/restore_assignment_activity_task.class.php +++ b/mod/assignment/backup/moodle2/restore_assignment_activity_task.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; + } } diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 032734811fa..634f663134e 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -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(); diff --git a/mod/assignment/restorelib.php b/mod/assignment/restorelib.php deleted file mode 100644 index 81354ae5ab0..00000000000 --- a/mod/assignment/restorelib.php +++ /dev/null @@ -1,116 +0,0 @@ -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
    "; //Debug - } - break; - } - - if ($status) { - $status = $log; - } - return $status; - } - diff --git a/mod/chat/backup/moodle2/restore_chat_activity_task.class.php b/mod/chat/backup/moodle2/restore_chat_activity_task.class.php index 3c0c5e25770..80920f75908 100644 --- a/mod/chat/backup/moodle2/restore_chat_activity_task.class.php +++ b/mod/chat/backup/moodle2/restore_chat_activity_task.class.php @@ -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; + } } diff --git a/mod/chat/restorelib.php b/mod/chat/restorelib.php deleted file mode 100644 index 84eb13ceb8b..00000000000 --- a/mod/chat/restorelib.php +++ /dev/null @@ -1,102 +0,0 @@ -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
    "; //Debug - } - break; - } - - if ($status) { - $status = $log; - } - return $status; - } - diff --git a/mod/choice/backup/moodle2/restore_choice_activity_task.class.php b/mod/choice/backup/moodle2/restore_choice_activity_task.class.php index 5fb078c3683..95a35c49790 100644 --- a/mod/choice/backup/moodle2/restore_choice_activity_task.class.php +++ b/mod/choice/backup/moodle2/restore_choice_activity_task.class.php @@ -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; + } } diff --git a/mod/choice/index.php b/mod/choice/index.php index 0ae6484271d..e63b8763593 100644 --- a/mod/choice/index.php +++ b/mod/choice/index.php @@ -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"); diff --git a/mod/choice/restorelib.php b/mod/choice/restorelib.php deleted file mode 100644 index 07c62c5667c..00000000000 --- a/mod/choice/restorelib.php +++ /dev/null @@ -1,119 +0,0 @@ -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
    "; //Debug - } - break; - } - - if ($status) { - $status = $log; - } - return $status; - } - diff --git a/mod/data/backup/moodle2/restore_data_activity_task.class.php b/mod/data/backup/moodle2/restore_data_activity_task.class.php index a97c26b0c95..3896158189b 100644 --- a/mod/data/backup/moodle2/restore_data_activity_task.class.php +++ b/mod/data/backup/moodle2/restore_data_activity_task.class.php @@ -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; + } } diff --git a/mod/data/restorelib.php b/mod/data/restorelib.php deleted file mode 100644 index 4ba5aeebb10..00000000000 --- a/mod/data/restorelib.php +++ /dev/null @@ -1,35 +0,0 @@ -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 -} diff --git a/mod/feedback/backup/moodle2/restore_feedback_activity_task.class.php b/mod/feedback/backup/moodle2/restore_feedback_activity_task.class.php index fe085a69975..1a288e58f05 100644 --- a/mod/feedback/backup/moodle2/restore_feedback_activity_task.class.php +++ b/mod/feedback/backup/moodle2/restore_feedback_activity_task.class.php @@ -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; + } } diff --git a/mod/feedback/restorelib.php b/mod/feedback/restorelib.php deleted file mode 100644 index 370686fde9e..00000000000 --- a/mod/feedback/restorelib.php +++ /dev/null @@ -1,127 +0,0 @@ -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
    "; //Debug - } - break; - } - - if ($status) { - $status = $log; - } - return $status; - } - - diff --git a/mod/folder/backup/moodle2/restore_folder_activity_task.class.php b/mod/folder/backup/moodle2/restore_folder_activity_task.class.php index dec8b721d09..3367948474e 100644 --- a/mod/folder/backup/moodle2/restore_folder_activity_task.class.php +++ b/mod/folder/backup/moodle2/restore_folder_activity_task.class.php @@ -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; + } } diff --git a/mod/forum/backup/moodle2/restore_forum_activity_task.class.php b/mod/forum/backup/moodle2/restore_forum_activity_task.class.php index 0ae70ca81f5..bb5bfb6e654 100644 --- a/mod/forum/backup/moodle2/restore_forum_activity_task.class.php +++ b/mod/forum/backup/moodle2/restore_forum_activity_task.class.php @@ -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; + } } diff --git a/mod/forum/restorelib.php b/mod/forum/restorelib.php deleted file mode 100644 index 6709f2283cb..00000000000 --- a/mod/forum/restorelib.php +++ /dev/null @@ -1,305 +0,0 @@ -. - -/** - * 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
    "; //Debug - } - break; - } - - if ($status) { - $status = $log; - } - return $status; - } - diff --git a/mod/glossary/backup/moodle2/restore_glossary_activity_task.class.php b/mod/glossary/backup/moodle2/restore_glossary_activity_task.class.php index 36675bb47d0..f542436f18d 100644 --- a/mod/glossary/backup/moodle2/restore_glossary_activity_task.class.php +++ b/mod/glossary/backup/moodle2/restore_glossary_activity_task.class.php @@ -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; + } } diff --git a/mod/glossary/restorelib.php b/mod/glossary/restorelib.php deleted file mode 100644 index 0cb5a75a5b2..00000000000 --- a/mod/glossary/restorelib.php +++ /dev/null @@ -1,221 +0,0 @@ -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
    "; //Debug - } - break; - } - - if ($status) { - $status = $log; - } - return $status; - } - diff --git a/mod/imscp/backup/moodle2/restore_imscp_activity_task.class.php b/mod/imscp/backup/moodle2/restore_imscp_activity_task.class.php index c8bb4567acc..16f861d4798 100644 --- a/mod/imscp/backup/moodle2/restore_imscp_activity_task.class.php +++ b/mod/imscp/backup/moodle2/restore_imscp_activity_task.class.php @@ -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; + } } diff --git a/mod/label/backup/moodle2/restore_label_activity_task.class.php b/mod/label/backup/moodle2/restore_label_activity_task.class.php index b7270ffa0d8..6bfad238bf5 100644 --- a/mod/label/backup/moodle2/restore_label_activity_task.class.php +++ b/mod/label/backup/moodle2/restore_label_activity_task.class.php @@ -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; + } } diff --git a/mod/label/restorelib.php b/mod/label/restorelib.php deleted file mode 100644 index 38ad8b5064a..00000000000 --- a/mod/label/restorelib.php +++ /dev/null @@ -1,88 +0,0 @@ -. - -/** - * 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
    "; //Debug - } - break; - } - - if ($status) { - $status = $log; - } - return $status; - } - diff --git a/mod/lesson/backup/moodle2/restore_lesson_activity_task.class.php b/mod/lesson/backup/moodle2/restore_lesson_activity_task.class.php index 6836db7562c..3f44d84b8b2 100644 --- a/mod/lesson/backup/moodle2/restore_lesson_activity_task.class.php +++ b/mod/lesson/backup/moodle2/restore_lesson_activity_task.class.php @@ -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; + } } diff --git a/mod/lesson/restorelib.php b/mod/lesson/restorelib.php deleted file mode 100644 index 47ea38106be..00000000000 --- a/mod/lesson/restorelib.php +++ /dev/null @@ -1,140 +0,0 @@ -. - -/** - * 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
    "; //Debug - } - break; - } - - if ($status) { - $status = $log; - } - return $status; - } - diff --git a/mod/page/backup/moodle2/restore_page_activity_task.class.php b/mod/page/backup/moodle2/restore_page_activity_task.class.php index 9b34c66e15a..2951bb557c3 100644 --- a/mod/page/backup/moodle2/restore_page_activity_task.class.php +++ b/mod/page/backup/moodle2/restore_page_activity_task.class.php @@ -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; + } } diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index 0ff3d6017b0..a8c95959277 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -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()); diff --git a/mod/quiz/backup/moodle2/restore_quiz_activity_task.class.php b/mod/quiz/backup/moodle2/restore_quiz_activity_task.class.php index bf79c7fae18..baedede8d64 100644 --- a/mod/quiz/backup/moodle2/restore_quiz_activity_task.class.php +++ b/mod/quiz/backup/moodle2/restore_quiz_activity_task.class.php @@ -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; + } } diff --git a/mod/quiz/backup/moodle2/restore_quiz_stepslib.php b/mod/quiz/backup/moodle2/restore_quiz_stepslib.php index 41e535d7757..30f8baa0ae2 100644 --- a/mod/quiz/backup/moodle2/restore_quiz_stepslib.php +++ b/mod/quiz/backup/moodle2/restore_quiz_stepslib.php @@ -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() { diff --git a/mod/quiz/restorelib.php b/mod/quiz/restorelib.php deleted file mode 100644 index ad24dc052be..00000000000 --- a/mod/quiz/restorelib.php +++ /dev/null @@ -1,212 +0,0 @@ -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
    "; //Debug - } - break; - } - - if ($status) { - $status = $log; - } - return $status; - } diff --git a/mod/resource/backup/moodle2/restore_resource_activity_task.class.php b/mod/resource/backup/moodle2/restore_resource_activity_task.class.php index caefda1c997..1a1b6300431 100644 --- a/mod/resource/backup/moodle2/restore_resource_activity_task.class.php +++ b/mod/resource/backup/moodle2/restore_resource_activity_task.class.php @@ -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; + } } diff --git a/mod/scorm/backup/moodle2/restore_scorm_activity_task.class.php b/mod/scorm/backup/moodle2/restore_scorm_activity_task.class.php index 0606849e98c..77081d07d6b 100644 --- a/mod/scorm/backup/moodle2/restore_scorm_activity_task.class.php +++ b/mod/scorm/backup/moodle2/restore_scorm_activity_task.class.php @@ -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; + } } diff --git a/mod/scorm/restorelib.php b/mod/scorm/restorelib.php deleted file mode 100755 index 87fa11de56c..00000000000 --- a/mod/scorm/restorelib.php +++ /dev/null @@ -1,38 +0,0 @@ -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; - } - diff --git a/mod/survey/backup/moodle2/restore_survey_activity_task.class.php b/mod/survey/backup/moodle2/restore_survey_activity_task.class.php index 6fcf18f85ee..de499617add 100644 --- a/mod/survey/backup/moodle2/restore_survey_activity_task.class.php +++ b/mod/survey/backup/moodle2/restore_survey_activity_task.class.php @@ -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; + } } diff --git a/mod/survey/restorelib.php b/mod/survey/restorelib.php deleted file mode 100644 index dd6fb346cad..00000000000 --- a/mod/survey/restorelib.php +++ /dev/null @@ -1,129 +0,0 @@ -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
    "; //Debug - } - break; - } - - if ($status) { - $status = $log; - } - return $status; - } - diff --git a/mod/url/backup/moodle2/restore_url_activity_task.class.php b/mod/url/backup/moodle2/restore_url_activity_task.class.php index d6e21f8fae6..d33e14e1210 100644 --- a/mod/url/backup/moodle2/restore_url_activity_task.class.php +++ b/mod/url/backup/moodle2/restore_url_activity_task.class.php @@ -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; + } } diff --git a/mod/wiki/backup/moodle2/restore_wiki_activity_task.class.php b/mod/wiki/backup/moodle2/restore_wiki_activity_task.class.php index 0e81e5f3fd9..10e52e1e9a3 100644 --- a/mod/wiki/backup/moodle2/restore_wiki_activity_task.class.php +++ b/mod/wiki/backup/moodle2/restore_wiki_activity_task.class.php @@ -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; + } } diff --git a/mod/workshop/backup/moodle2/restore_workshop_activity_task.class.php b/mod/workshop/backup/moodle2/restore_workshop_activity_task.class.php index d88beb3db78..d55b01a9a52 100644 --- a/mod/workshop/backup/moodle2/restore_workshop_activity_task.class.php +++ b/mod/workshop/backup/moodle2/restore_workshop_activity_task.class.php @@ -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; + } }