diff --git a/lib/classes/event/base.php b/lib/classes/event/base.php index 6a73c1637bd00..d523309795d94 100644 --- a/lib/classes/event/base.php +++ b/lib/classes/event/base.php @@ -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]; } diff --git a/lib/tests/event_test.php b/lib/tests/event_test.php index 3c69163161efe..9f7a94f1cee9d 100644 --- a/lib/tests/event_test.php +++ b/lib/tests/event_test.php @@ -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() {