commit 5b4615c8bd48abbe893eb54fd2b415a7cbb6cf48 Author: Mark Nielsen Date: Wed Dec 17 10:13:51 2014 -0800 MDL-48644 backup: Preserve log IP and time during restore diff --git a/admin/tool/log/classes/log/manager.php b/admin/tool/log/classes/log/manager.php index 129389f..8bc3c4c 100644 --- a/admin/tool/log/classes/log/manager.php +++ b/admin/tool/log/classes/log/manager.php @@ -213,11 +213,13 @@ class manager implements \core\log\manager { * @param string $info Additional description information * @param int $cm The course_module->id if there is one * @param int|\stdClass $user If log regards $user other than $USER + * @param string $ip Override the IP, should only be used for restore. + * @param int $time Override the log time, should only be used for restore. */ - public function legacy_add_to_log($courseid, $module, $action, $url = '', $info = '', $cm = 0, $user = 0) { + public function legacy_add_to_log($courseid, $module, $action, $url = '', $info = '', $cm = 0, $user = 0, $ip = null, $time = null) { $this->init(); if (isset($this->stores['logstore_legacy'])) { - $this->stores['logstore_legacy']->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user); + $this->stores['logstore_legacy']->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user, $ip, $time); } } } diff --git a/admin/tool/log/store/legacy/classes/log/store.php b/admin/tool/log/store/legacy/classes/log/store.php index 48d561e..cdeb75c 100644 --- a/admin/tool/log/store/legacy/classes/log/store.php +++ b/admin/tool/log/store/legacy/classes/log/store.php @@ -143,8 +143,10 @@ class store implements \tool_log\log\store, \core\log\sql_select_reader { * @param string $info Additional description information * @param int $cm The course_module->id if there is one * @param int|\stdClass $user If log regards $user other than $USER + * @param string $ip Override the IP, should only be used for restore. + * @param int $time Override the log time, should only be used for restore. */ - public function legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user) { + public function legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user, $ip = null, $time = null) { // Note that this function intentionally does not follow the normal Moodle DB access idioms. // This is for a good reason: it is the most frequently used DB update function, // so it has been optimised for speed. @@ -172,9 +174,9 @@ class store implements \tool_log\log\store, \core\log\sql_select_reader { } } - $remoteaddr = getremoteaddr(); + $remoteaddr = (is_null($ip)) ? getremoteaddr() : $ip; - $timenow = time(); + $timenow = (is_null($time)) ? time() : $time; if (!empty($url)) { // Could break doing html_entity_decode on an empty var. $url = html_entity_decode($url, ENT_QUOTES, 'UTF-8'); } else { diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 45630ff..2d79023 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -2764,7 +2764,7 @@ class restore_course_logs_structure_step extends restore_structure_step { $manager = get_log_manager(); if (method_exists($manager, 'legacy_add_to_log')) { $manager->legacy_add_to_log($data->course, $data->module, $data->action, $data->url, - $data->info, $data->cmid, $data->userid); + $data->info, $data->cmid, $data->userid, $data->ip, $data->time); } } } @@ -2813,7 +2813,7 @@ class restore_activity_logs_structure_step extends restore_course_logs_structure $manager = get_log_manager(); if (method_exists($manager, 'legacy_add_to_log')) { $manager->legacy_add_to_log($data->course, $data->module, $data->action, $data->url, - $data->info, $data->cmid, $data->userid); + $data->info, $data->cmid, $data->userid, $data->ip, $data->time); } } }