Merge branch 'MDL-63168_35' of git://github.com/markn86/moodle into MOODLE_35_STABLE

This commit is contained in:
Sara Arjona 2019-01-29 13:01:10 +01:00
commit 64a588ccca
2 changed files with 32 additions and 1 deletions

View file

@ -229,7 +229,7 @@ class migrate_message_data extends \core\task\adhoc_task {
}
// Check if we need to mark this message as deleted for the user to.
if ($message->timeusertodeleted) {
if ($message->timeusertodeleted and ($message->useridfrom != $message->useridto)) {
$mua = new \stdClass();
$mua->userid = $message->useridto;
$mua->messageid = $messageid;

View file

@ -324,6 +324,37 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase
$this->assertEquals(FORMAT_MOODLE, $notification->fullmessageformat);
}
/**
* Test migrating a legacy message that a user sent to themselves then deleted.
*/
public function test_migrating_message_deleted_message_sent_to_self() {
global $DB;
// Create user to test with.
$user1 = $this->getDataGenerator()->create_user();
$m1 = $this->create_legacy_message_or_notification($user1->id, $user1->id, null, false, null, null);
// Let's delete the message for the 'user to' and 'user from' which in this case is the same user.
$messageupdate = new stdClass();
$messageupdate->id = $m1;
$messageupdate->timeuserfromdeleted = time();
$messageupdate->timeusertodeleted = time();
$DB->update_record('message', $messageupdate);
// Now, let's execute the task for the user.
$task = new \core_message\task\migrate_message_data();
$task->set_custom_data(
[
'userid' => $user1->id
]
);
$task->execute();
$this->assertEquals(0, $DB->count_records('message'));
$this->assertEquals(1, $DB->count_records('message_user_actions'));
}
/**
* Creates a legacy message or notification to be used for testing.
*