From 362bc070638e2f8d84fd1fb1fe535a468872af03 Mon Sep 17 00:00:00 2001 From: Mark Nielsen Date: Thu, 18 Dec 2014 11:30:28 -0800 Subject: [PATCH] MDL-48644 backup: Preserve log IP and time during restore --- admin/tool/log/classes/log/manager.php | 6 ++++-- admin/tool/log/store/legacy/classes/log/store.php | 8 +++++--- backup/moodle2/restore_stepslib.php | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/admin/tool/log/classes/log/manager.php b/admin/tool/log/classes/log/manager.php index 129389f2e1cf3..8bc3c4c054089 100644 --- a/admin/tool/log/classes/log/manager.php +++ b/admin/tool/log/classes/log/manager.php @@ -213,11 +213,13 @@ public function dispose() { * @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 faabf716b9837..f17a308b2b833 100644 --- a/admin/tool/log/store/legacy/classes/log/store.php +++ b/admin/tool/log/store/legacy/classes/log/store.php @@ -145,8 +145,10 @@ public function dispose() { * @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. @@ -174,9 +176,9 @@ public function legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, } } - $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 1380f204e0a41..2a6f1434fdf60 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -2762,7 +2762,7 @@ protected function process_log($data) { $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); } } } @@ -2811,7 +2811,7 @@ protected function process_log($data) { $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); } } }