diff --git a/public/main/forum/forumfunction.inc.php b/public/main/forum/forumfunction.inc.php index 29be69492e..dfbdc28f50 100644 --- a/public/main/forum/forumfunction.inc.php +++ b/public/main/forum/forumfunction.inc.php @@ -897,16 +897,16 @@ function deletePost(CForumPost $post): void */ function getLastPostOfThread(int $threadId): array { - $table_posts = Database::get_course_table(TABLE_FORUM_POST); - $sql = "SELECT iid, post_date FROM $table_posts - WHERE threadId = $threadId - ORDER BY post_date DESC LIMIT 1"; - $result = Database::query($sql); - if (Database::num_rows($result) > 0) { - return Database::fetch_array($result); + $post = Container::getForumPostRepository()->findOneBy(['thread' => $threadId], ['postDate' => 'DESC']); + + if (null === $post) { + return []; } - return []; + return [ + 'iid' => $post->getIid(), + 'post_date' => $post->getPostDate()->format('Y-m-d H:i:s'), + ]; } /** diff --git a/tests/behat/features/toolForum.feature b/tests/behat/features/toolForum.feature index 668e464ad4..8ea9c783c1 100644 --- a/tests/behat/features/toolForum.feature +++ b/tests/behat/features/toolForum.feature @@ -53,7 +53,7 @@ Feature: Forum tool Then I follow "Delete" And I confirm the popup And wait for the page to be loaded - Then I should see "deleted" + Then I should see "Thread deleted" # This test is commented because to quote a message is necessary load HTML code inside of textarea. # And this breaks the page for Behat