Skip to content

Commit

Permalink
Merge branch 'MDL-56090-master-fix' of github.com:andrewnicols/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Oct 26, 2016
2 parents 01435b4 + ebc746d commit c642302
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
7 changes: 5 additions & 2 deletions message/classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@ public static function get_messages($userid, $otheruserid, $timedeleted = 0, $li
$sort = 'timecreated ASC') {
global $DB;

$sql = "SELECT id, useridfrom, useridto, subject, fullmessage, fullmessagehtml, fullmessageformat,
$messageid = $DB->sql_concat("'message_'", 'id');
$messagereadid = $DB->sql_concat("'messageread_'", 'id');

$sql = "SELECT {$messageid} AS fakeid, id, useridfrom, useridto, subject, fullmessage, fullmessagehtml, fullmessageformat,
smallmessage, notification, timecreated, 0 as timeread
FROM {message} m
WHERE ((useridto = ? AND useridfrom = ? AND timeusertodeleted = ?)
OR (useridto = ? AND useridfrom = ? AND timeuserfromdeleted = ?))
AND notification = 0
UNION ALL
SELECT id, useridfrom, useridto, subject, fullmessage, fullmessagehtml, fullmessageformat,
SELECT {$messagereadid} AS fakeid, id, useridfrom, useridto, subject, fullmessage, fullmessagehtml, fullmessageformat,
smallmessage, notification, timecreated, timeread
FROM {message_read} mr
WHERE ((useridto = ? AND useridfrom = ? AND timeusertodeleted = ?)
Expand Down
24 changes: 12 additions & 12 deletions message/tests/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,33 +321,34 @@ public function test_message_deleted_whole_conversation() {
$message->timeusertodeleted = 0;
$message->timecreated = 1;

$messages = [];
// Send this a few times.
$messageid1 = $DB->insert_record('message', $message);
$messages[] = $DB->insert_record('message', $message);

$message->timecreated++;
$messageid2 = $DB->insert_record('message', $message);
$messages[] = $DB->insert_record('message', $message);

$message->timecreated++;
$messageid3 = $DB->insert_record('message', $message);
$messages[] = $DB->insert_record('message', $message);

$message->timecreated++;
$messageid4 = $DB->insert_record('message', $message);
$messages[] = $DB->insert_record('message', $message);

// Create a read message.
$message->timeread = time();

// Send this a few times.
$message->timecreated++;
$messageid5 = $DB->insert_record('message_read', $message);
$messages[] = $DB->insert_record('message_read', $message);

$message->timecreated++;
$messageid6 = $DB->insert_record('message_read', $message);
$messages[] = $DB->insert_record('message_read', $message);

$message->timecreated++;
$messageid7 = $DB->insert_record('message_read', $message);
$messages[] = $DB->insert_record('message_read', $message);

$message->timecreated++;
$messageid8 = $DB->insert_record('message_read', $message);
$messages[] = $DB->insert_record('message_read', $message);

// Trigger and capture the event.
$sink = $this->redirectEvents();
Expand All @@ -358,16 +359,15 @@ public function test_message_deleted_whole_conversation() {
$this->assertEquals(8, count($events));

// Check that the event data is valid.
$i = 1;
$i = 0;
foreach ($events as $event) {
$table = ($i > 4) ? 'message_read' : 'message';
$messageid = 'messageid' . $i;
$table = ($i > 3) ? 'message_read' : 'message';

$this->assertInstanceOf('\core\event\message_deleted', $event);
$this->assertEquals($message->useridfrom, $event->userid);
$this->assertEquals($message->useridto, $event->relateduserid);
$this->assertEquals($table, $event->other['messagetable']);
$this->assertEquals($$messageid, $event->other['messageid']);
$this->assertEquals($messages[$i], $event->other['messageid']);
$this->assertEquals($message->useridfrom, $event->other['useridfrom']);
$this->assertEquals($message->useridto, $event->other['useridto']);

Expand Down

0 comments on commit c642302

Please sign in to comment.