Skip to content

Commit

Permalink
MDL-42583 events: Fix snapshot issues with note events
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitagarwal committed Oct 31, 2013
1 parent 68291f2 commit 9bb0353
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 5 additions & 4 deletions notes/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ function note_save(&$note) {
'context' => context_course::instance($note->courseid),
'other' => array('publishstate' => $note->publishstate)
));
$event->add_record_snapshot('post', $note);
$event->trigger();
} else {
// Update old note.
Expand All @@ -127,7 +126,6 @@ function note_save(&$note) {
'context' => context_course::instance($note->courseid),
'other' => array('publishstate' => $note->publishstate)
));
$event->add_record_snapshot('post', $note);
$event->trigger();
}
unset($note->module);
Expand All @@ -143,9 +141,12 @@ function note_save(&$note) {
function note_delete($note) {
global $DB;
if (is_int($note)) {
$note = note_load($note);
debugging('Warning: providing note_delete with a note object would improve performance.', DEBUG_DEVELOPER);
$noteid = $note;
} else {
$noteid = $note->id;
}
// Get the full record, note_load doesn't return everything.
$note = $DB->get_record('post', array('id' => $noteid), '*', MUST_EXIST);
$return = $DB->delete_records('post', array('id' => $note->id, 'module' => 'notes'));

// Trigger event.
Expand Down
10 changes: 7 additions & 3 deletions notes/tests/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class core_notes_events_testcase extends advanced_testcase {
/** @var stdClass A note object. */
private $eventnote;

/** @var stdClass A complete record from post table */
private $noterecord;

public function setUp() {
global $DB;

$this->resetAfterTest();
$this->setAdminUser();
Expand All @@ -47,6 +51,8 @@ public function setUp() {
$user = $this->getDataGenerator()->create_user();
$gen = $this->getDataGenerator()->get_plugin_generator('core_notes');
$this->eventnote = $gen->create_instance(array('courseid' => $course->id, 'userid' => $user->id));
// Get the full record, note_load doesn't return everything.
$this->noterecord = $DB->get_record('post', array('id' => $this->eventnote->id), '*', MUST_EXIST);

}

Expand All @@ -68,7 +74,7 @@ public function test_note_deleted_event() {
$this->assertEquals($this->eventnote->userid, $event->relateduserid);
$this->assertEquals('post', $event->objecttable);
$this->assertEquals(null, $event->get_url());
$this->assertEquals($this->eventnote, $event->get_record_snapshot('post', $event->objectid));
$this->assertEquals($this->noterecord, $event->get_record_snapshot('post', $event->objectid));
$this->assertEquals(NOTES_STATE_SITE, $event->other['publishstate']);

// Test legacy data.
Expand Down Expand Up @@ -99,7 +105,6 @@ public function test_note_created_event() {
$this->assertEquals($note->usermodified, $event->userid);
$this->assertEquals($note->userid, $event->relateduserid);
$this->assertEquals('post', $event->objecttable);
$this->assertEquals($note, $event->get_record_snapshot('post', $event->objectid));
$this->assertEquals(NOTES_STATE_SITE, $event->other['publishstate']);

// Test legacy data.
Expand Down Expand Up @@ -131,7 +136,6 @@ public function test_note_updated_event() {
$this->assertEquals($note->usermodified, $event->userid);
$this->assertEquals($note->userid, $event->relateduserid);
$this->assertEquals('post', $event->objecttable);
$this->assertEquals($note, $event->get_record_snapshot('post', $event->objectid));
$this->assertEquals(NOTES_STATE_DRAFT, $event->other['publishstate']);

// Test legacy data.
Expand Down

0 comments on commit 9bb0353

Please sign in to comment.