Skip to content

Commit

Permalink
MDL-39846 prevent use of snapshots in restored events
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jul 19, 2013
1 parent 300dbc6 commit 4ad6d5c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/classes/event/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,16 @@ public function add_record_snapshot($tablename, $record) {
* @param string $tablename
* @param int $id
* @return \stdClass
*
* @throws \coding_exception if used after ::restore()
*/
public function get_record_snapshot($tablename, $id) {
global $DB;

if ($this->restored) {
throw new \coding_exception('It is not possible to get snapshots from restored events');
}

if (isset($this->recordsnapshots[$tablename][$id])) {
return $this->recordsnapshots[$tablename][$id];
}
Expand Down
8 changes: 8 additions & 0 deletions lib/tests/event_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,14 @@ public function test_record_snapshots() {
} catch (\moodle_exception $e) {
$this->assertInstanceOf('\coding_exception', $e);
}

$event2 = \core_tests\event\unittest_executed::restore($event->get_data(), array());
try {
$event2->get_record_snapshot('course', 1, $course1);
$this->fail('Reading of snapshots from restored events is not ok');;
} catch (\moodle_exception $e) {
$this->assertInstanceOf('\coding_exception', $e);
}
}

public function test_iteration() {
Expand Down

0 comments on commit 4ad6d5c

Please sign in to comment.