MDL-39846 prevent adding of snapshots after event trigger
This commit is contained in:
@@ -508,10 +508,16 @@ abstract class base implements \IteratorAggregate {
|
||||
*
|
||||
* @param string $tablename
|
||||
* @param \stdClass $record
|
||||
*
|
||||
* @throws \coding_exception if used after ::trigger()
|
||||
*/
|
||||
public function add_record_snapshot($tablename, $record) {
|
||||
global $DB;
|
||||
|
||||
if ($this->triggered) {
|
||||
throw new \coding_exception('It is not possible to add snapshots after triggering of events');
|
||||
}
|
||||
|
||||
// NOTE: this might use some kind of MUC cache,
|
||||
// hopefully we will not run out of memory here...
|
||||
if (debugging('', DEBUG_DEVELOPER)) { // This should be replaced by new $CFG->slowdebug flag if introduced.
|
||||
|
||||
@@ -639,6 +639,15 @@ class core_event_testcase extends advanced_testcase {
|
||||
$user = $event->get_record_snapshot('user', 1);
|
||||
$this->assertEquals(1, $user->id);
|
||||
$this->assertSame('guest', $user->username);
|
||||
|
||||
$event->add_record_snapshot('course', $course1);
|
||||
$event->trigger();
|
||||
try {
|
||||
$event->add_record_snapshot('course', $course1);
|
||||
$this->fail('Updating of snapshots after trigger is not ok');;
|
||||
} catch (\moodle_exception $e) {
|
||||
$this->assertInstanceOf('\coding_exception', $e);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_iteration() {
|
||||
|
||||
Reference in New Issue
Block a user