diff --git a/lib/classes/event/base.php b/lib/classes/event/base.php index 38a999e53ea..8082ab96946 100644 --- a/lib/classes/event/base.php +++ b/lib/classes/event/base.php @@ -573,6 +573,13 @@ abstract class base implements \IteratorAggregate { if ($CFG->debugdeveloper) { if (!$DB->get_manager()->table_exists($tablename)) { debugging("Invalid table name '$tablename' specified, database table does not exist.", DEBUG_DEVELOPER); + } else { + $columns = $DB->get_columns($tablename); + $missingfields = array_diff(array_keys($columns), array_keys((array)$record)); + if (!empty($missingfields)) { + debugging("Fields list in snapshot record does not match fields list in '$tablename'. Record is missing fields: ". + join(', ', $missingfields), DEBUG_DEVELOPER); + } } } $this->recordsnapshots[$tablename][$record->id] = $record; @@ -595,7 +602,7 @@ abstract class base implements \IteratorAggregate { } if (isset($this->recordsnapshots[$tablename][$id])) { - return $this->recordsnapshots[$tablename][$id]; + return clone($this->recordsnapshots[$tablename][$id]); } $record = $DB->get_record($tablename, array('id'=>$id)); diff --git a/lib/tests/event_test.php b/lib/tests/event_test.php index 713fc14b649..0c3458e32fa 100644 --- a/lib/tests/event_test.php +++ b/lib/tests/event_test.php @@ -709,8 +709,9 @@ class core_event_testcase extends advanced_testcase { $event->add_record_snapshot('course', $course1); - $result = $event->get_record_snapshot('course', 1, $course1); - $this->assertSame($course1, $result); + $result = $event->get_record_snapshot('course', 1); + // Convert to arrays because record snapshot returns a clone of the object. + $this->assertSame((array)$course1, (array)$result); $user = $event->get_record_snapshot('user', 1); $this->assertEquals(1, $user->id);