From 4631be32ebcd668278c61ee5820bfcf16a809ef0 Mon Sep 17 00:00:00 2001 From: cescobedo Date: Wed, 21 Jul 2021 12:15:20 +0200 Subject: [PATCH] MDL-66266 core_message: Final deprecation of 3.8 api functions Final deprecation of: - can_post_message - get_individual_conversations_between_users --- message/classes/api.php | 75 ++-------------- message/tests/api_test.php | 170 +------------------------------------ message/upgrade.txt | 6 ++ 3 files changed, 15 insertions(+), 236 deletions(-) diff --git a/message/classes/api.php b/message/classes/api.php index f9f3fb42273..3f74c8ecb67 100644 --- a/message/classes/api.php +++ b/message/classes/api.php @@ -1538,27 +1538,13 @@ class api { } /** - * Determines if a user is permitted to send another user a private message. - * If no sender is provided then it defaults to the logged in user. - * * @deprecated since 3.8 - * @todo Final deprecation in MDL-66266 - * @param \stdClass $recipient The user object. - * @param \stdClass|null $sender The user object. - * @return bool true if user is permitted, false otherwise. */ - public static function can_post_message($recipient, $sender = null) { - global $USER; - - debugging('\core_message\api::can_post_message is deprecated, please use ' . - '\core_message\api::can_send_message instead.', DEBUG_DEVELOPER); - - if (is_null($sender)) { - // The message is from the logged in user, unless otherwise specified. - $sender = $USER; - } - - return self::can_send_message($recipient->id, $sender->id); + public static function can_post_message() { + throw new \coding_exception(' + \core_message\api::can_post_message is deprecated and + no longer used, please use + \core_message\api::can_send_message instead.'); } /** @@ -2063,56 +2049,11 @@ class api { } /** - * Returns the conversations between sets of users. - * - * The returned array of results will be in the same order as the requested - * arguments, null will be returned if there is no conversation for that user - * pair. - * - * For example: - * If we have 6 users with ids 1, 2, 3, 4, 5, 6 where only 2 conversations - * exist. One between 1 and 2 and another between 5 and 6. - * - * Then if we call: - * $conversations = get_individual_conversations_between_users([[1,2], [3,4], [5,6]]); - * - * The conversations array will look like: - * [, null, ]; - * - * Where null is returned for the pairing of [3, 4] since no record exists. - * * @deprecated since 3.8 - * @param array $useridsets An array of arrays where the inner array is the set of user ids - * @return stdClass[] Array of conversation records */ - public static function get_individual_conversations_between_users(array $useridsets) : array { - global $DB; - - debugging('\core_message\api::get_individual_conversations_between_users is deprecated and no longer used', - DEBUG_DEVELOPER); - - if (empty($useridsets)) { - return []; - } - - $hashes = array_map(function($userids) { - return helper::get_conversation_hash($userids); - }, $useridsets); - - list($inorequalsql, $params) = $DB->get_in_or_equal($hashes); - array_unshift($params, self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL); - $where = "type = ? AND convhash ${inorequalsql}"; - $conversations = array_fill(0, count($hashes), null); - $records = $DB->get_records_select('message_conversations', $where, $params); - - foreach (array_values($records) as $record) { - $index = array_search($record->convhash, $hashes); - if ($index !== false) { - $conversations[$index] = $record; - } - } - - return $conversations; + public static function get_individual_conversations_between_users() { + throw new \coding_exception('\core_message\api::get_individual_conversations_between_users ' . + ' is deprecated and no longer used.'); } /** diff --git a/message/tests/api_test.php b/message/tests/api_test.php index 3b367fbf7b4..dfcdf5c1634 100644 --- a/message/tests/api_test.php +++ b/message/tests/api_test.php @@ -39,7 +39,7 @@ use \core_message\tests\helper as testhelper; * @copyright 2016 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_message_api_testcase extends core_message_messagelib_testcase { +class core_message_api_test extends core_message_messagelib_testcase { public function test_mark_all_read_for_user_touser() { $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1')); @@ -3265,26 +3265,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase { $this->assertTrue(\core_message\api::can_send_message($student->id, $teacher->id, true)); } - /** - * Test that calling to can_post_message() now shows debugging. MDL-65093. - * - * @deprecated since 3.8 - * @todo Final deprecation in MDL-66266 - */ - public function test_can_post_emits_debugging() { - // Create some users. - $user1 = self::getDataGenerator()->create_user(); - $user2 = self::getDataGenerator()->create_user(); - - // Set as the first user. - $this->setUser($user1); - - // With the default privacy setting, users can't message them. - $this->assertFalse(\core_message\api::can_post_message($user2)); - $this->assertDebuggingCalled('\core_message\api::can_post_message is deprecated, please use ' . - '\core_message\api::can_send_message instead.', DEBUG_DEVELOPER); - } - /** * Verify the expected behaviour of the can_send_message_to_conversation() method for authenticated users with default settings. */ @@ -5197,154 +5177,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase { ); } - - /** - * Test an empty array returned when no args given. - */ - public function test_get_individual_conversations_between_users_no_user_sets() { - $this->assertEmpty(\core_message\api::get_individual_conversations_between_users([])); - $this->assertDebuggingCalled(); - } - - /** - * Test a conversation is not returned if there is none. - */ - public function test_get_individual_conversations_between_users_no_conversation() { - $generator = $this->getDataGenerator(); - $user1 = $generator->create_user(); - $user2 = $generator->create_user(); - - $this->assertEquals( - [null], - \core_message\api::get_individual_conversations_between_users([[$user1->id, $user2->id]]) - ); - $this->assertDebuggingCalled(); - } - - /** - * Test the result set includes null if there is no conversation between users. - */ - public function test_get_individual_conversations_between_users_partial_conversations() { - $generator = $this->getDataGenerator(); - $user1 = $generator->create_user(); - $user2 = $generator->create_user(); - $user3 = $generator->create_user(); - $type = \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL; - - $conversation1 = \core_message\api::create_conversation($type, [$user1->id, $user2->id]); - $conversation2 = \core_message\api::create_conversation($type, [$user1->id, $user3->id]); - - $results = \core_message\api::get_individual_conversations_between_users([ - [$user1->id, $user2->id], - [$user2->id, $user3->id], - [$user1->id, $user3->id] - ]); - $this->assertDebuggingCalled(); - - $result = array_map(function($result) { - if ($result) { - return $result->id; - } else { - return $result; - } - }, $results); - - $this->assertEquals( - [$conversation1->id, null, $conversation2->id], - $result - ); - } - - /** - * Test all conversations are returned if each set has a conversation. - */ - public function test_get_individual_conversations_between_users_all_conversations() { - $generator = $this->getDataGenerator(); - $user1 = $generator->create_user(); - $user2 = $generator->create_user(); - $user3 = $generator->create_user(); - $type = \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL; - - $conversation1 = \core_message\api::create_conversation($type, [$user1->id, $user2->id]); - $conversation2 = \core_message\api::create_conversation($type, [$user2->id, $user3->id]); - $conversation3 = \core_message\api::create_conversation($type, [$user1->id, $user3->id]); - - $results = \core_message\api::get_individual_conversations_between_users([ - [$user1->id, $user2->id], - [$user2->id, $user3->id], - [$user1->id, $user3->id] - ]); - $this->assertDebuggingCalled(); - - $result = array_map(function($result) { - if ($result) { - return $result->id; - } else { - return $result; - } - }, $results); - - $this->assertEquals( - [$conversation1->id, $conversation2->id, $conversation3->id], - $result - ); - } - - /** - * Test that the results are ordered to match the order of the parameters. - */ - public function test_get_individual_conversations_between_users_ordering() { - $generator = $this->getDataGenerator(); - $user1 = $generator->create_user(); - $user2 = $generator->create_user(); - $user3 = $generator->create_user(); - $type = \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL; - - $conversation1 = \core_message\api::create_conversation($type, [$user1->id, $user2->id]); - $conversation2 = \core_message\api::create_conversation($type, [$user2->id, $user3->id]); - $conversation3 = \core_message\api::create_conversation($type, [$user1->id, $user3->id]); - - $results = \core_message\api::get_individual_conversations_between_users([ - [$user1->id, $user2->id], - [$user2->id, $user3->id], - [$user1->id, $user3->id] - ]); - $this->assertDebuggingCalled(); - - $result = array_map(function($result) { - if ($result) { - return $result->id; - } else { - return $result; - } - }, $results); - - $this->assertEquals( - [$conversation1->id, $conversation2->id, $conversation3->id], - $result - ); - - $results = \core_message\api::get_individual_conversations_between_users([ - [$user2->id, $user3->id], - [$user1->id, $user2->id], - [$user1->id, $user3->id] - ]); - $this->assertDebuggingCalled(); - - $result = array_map(function($result) { - if ($result) { - return $result->id; - } else { - return $result; - } - }, $results); - - $this->assertEquals( - [$conversation2->id, $conversation1->id, $conversation3->id], - $result - ); - } - /** * Test returning members in a conversation with no contact requests. */ diff --git a/message/upgrade.txt b/message/upgrade.txt index 01a9490a4f4..4c35810a664 100644 --- a/message/upgrade.txt +++ b/message/upgrade.txt @@ -1,6 +1,12 @@ This files describes API changes in /message/ messaging system, information provided here is intended especially for developers. +=== 4.0 === + +The following functions have been finally deprecated and can not be used anymore: + * can_post_message() + * get_individual_conversations_between_users() + === 3.11.2 === * The `message_page_type_list` method was previouly deprecated, however it was still