MDL-39846 prevent adding of snapshots after event trigger

This commit is contained in:
Petr Škoda
2013-07-19 08:43:30 +02:00
parent 9cd7c32524
commit 300dbc66f2
2 changed files with 15 additions and 0 deletions
+6
View File
@@ -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.
+9
View File
@@ -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() {