diff --git a/message/classes/api.php b/message/classes/api.php index 1554c5a8937..b96006ec14f 100644 --- a/message/classes/api.php +++ b/message/classes/api.php @@ -314,6 +314,7 @@ class api { // This user has no conversations so we can return early here. if (empty($conversationrecords)) { + $transaction->allow_commit(); return []; } @@ -440,7 +441,7 @@ class api { $unreadcounts = $DB->get_records_sql($unreadcountssql, [$userid]); // We can close off the transaction now. - $DB->commit_delegated_transaction($transaction); + $transaction->allow_commit(); // Now we need to order the messages back into the same order of the conversations. $orderedconvosigs = array_keys($conversationrecords); diff --git a/message/tests/api_test.php b/message/tests/api_test.php index 35660fc941e..35d15f5f661 100644 --- a/message/tests/api_test.php +++ b/message/tests/api_test.php @@ -333,6 +333,9 @@ class core_message_api_testcase extends core_message_messagelib_testcase { // The person doing the search. $this->setUser($user1); + // No conversations yet. + $this->assertEquals([], \core_message\api::get_conversations($user1->id)); + // Send some messages back and forth, have some different conversations with different users. $time = 1; $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);