From 2cc70345cedfcf23da65211dbf003fd385909a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 16 Apr 2012 22:12:44 +0200 Subject: [PATCH] Properly delete position when a room is deleted. --- .../data/chat/room/ChatRoomEditor.class.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/file/lib/data/chat/room/ChatRoomEditor.class.php b/file/lib/data/chat/room/ChatRoomEditor.class.php index 8a1498a..2d9c407 100644 --- a/file/lib/data/chat/room/ChatRoomEditor.class.php +++ b/file/lib/data/chat/room/ChatRoomEditor.class.php @@ -30,6 +30,28 @@ public static function deleteAll(array $objectIDs = array()) { \wcf\system\language\I18nHandler::getInstance()->remove('wcf.chat.room.topic'.$objectID, $packageID); } + $sql = "SELECT + position + FROM + wcf".WCF_N."_chat_room + WHERE + roomID = ? + FOR UPDATE"; + $select = WCF::getDB()->prepareStatement($sql); + + $sql = "UPDATE + wcf".WCF_N."_chat_room + SET + position = position - 1 + WHERE + position > ?"; + $update = WCF::getDB()->prepareStatement($sql); + + foreach ($objectIDs as $objectID) { + $select->execute(array($objectID)); + $update->execute(array($select->fetchColumn())); + } + // The transaction is being committed in parent::deleteAll() // The beginTransaction() call in there is simply ignored. return parent::deleteAll($objectIDs);