mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-64931 core_message: fixed PHP error when users are deleted from DB
This commit is contained in:
parent
07203d34f1
commit
89bab5e8f0
@ -713,6 +713,13 @@ class api {
|
||||
$members[$convid][$key]->canmessage = null;
|
||||
$members[$convid][$key]->contactrequests = [];
|
||||
}
|
||||
} else { // Remove all members and individual conversations where we could not get the member's information.
|
||||
unset($members[$convid][$key]);
|
||||
|
||||
// If the conversation is an individual conversation, then we should remove it from the list.
|
||||
if ($conversations[$convid]->conversationtype == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) {
|
||||
unset($conversations[$convid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5433,19 +5433,33 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
$user1 = self::getDataGenerator()->create_user();
|
||||
$user2 = self::getDataGenerator()->create_user();
|
||||
$user3 = self::getDataGenerator()->create_user();
|
||||
|
||||
$conversation = \core_message\api::create_conversation(
|
||||
$conversation1 = \core_message\api::create_conversation(
|
||||
\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
|
||||
[
|
||||
$user1->id,
|
||||
$user2->id
|
||||
],
|
||||
'Individual conversation'
|
||||
'Individual conversation 1'
|
||||
);
|
||||
|
||||
testhelper::send_fake_message_to_conversation($user1, $conversation->id, 'A');
|
||||
testhelper::send_fake_message_to_conversation($user2, $conversation->id, 'B');
|
||||
testhelper::send_fake_message_to_conversation($user1, $conversation->id, 'C');
|
||||
testhelper::send_fake_message_to_conversation($user1, $conversation1->id, 'A');
|
||||
testhelper::send_fake_message_to_conversation($user2, $conversation1->id, 'B');
|
||||
testhelper::send_fake_message_to_conversation($user1, $conversation1->id, 'C');
|
||||
|
||||
$conversation2 = \core_message\api::create_conversation(
|
||||
\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
|
||||
[
|
||||
$user1->id,
|
||||
$user3->id
|
||||
],
|
||||
'Individual conversation 2'
|
||||
);
|
||||
|
||||
testhelper::send_fake_message_to_conversation($user1, $conversation2->id, 'A');
|
||||
testhelper::send_fake_message_to_conversation($user3, $conversation2->id, 'B');
|
||||
testhelper::send_fake_message_to_conversation($user1, $conversation2->id, 'C');
|
||||
|
||||
$this->setUser($user1);
|
||||
|
||||
@ -5455,7 +5469,13 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
$result = core_message_external::get_conversations($user1->id, 0, 20, 1, false);
|
||||
$result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
|
||||
|
||||
$this->assertEmpty($result['conversations']);
|
||||
$conversation = $result['conversations'];
|
||||
|
||||
$this->assertCount(1, $conversation);
|
||||
|
||||
$conversation = reset($conversation);
|
||||
|
||||
$this->assertEquals($conversation2->id, $conversation['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user