Skip to content

Commit

Permalink
MDL-48644 backup: Preserve log IP and time during restore
Browse files Browse the repository at this point in the history
  • Loading branch information
polothy committed Dec 18, 2014
1 parent 981f06f commit 362bc07
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 4 additions & 2 deletions admin/tool/log/classes/log/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
8 changes: 5 additions & 3 deletions admin/tool/log/store/legacy/classes/log/store.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 362bc07

Please sign in to comment.