From deea3dcc198d73106689fd114d82d1c8b037b805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 3 May 2013 20:02:18 +0200 Subject: [PATCH] Fix cronjob --- file/lib/data/room/RoomAction.class.php | 14 ++++++++++ file/lib/page/NewMessagesPage.class.php | 9 ++----- .../system/cronjob/CleanupCronjob.class.php | 26 ++----------------- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/file/lib/data/room/RoomAction.class.php b/file/lib/data/room/RoomAction.class.php index c1ff418..8350c59 100644 --- a/file/lib/data/room/RoomAction.class.php +++ b/file/lib/data/room/RoomAction.class.php @@ -210,6 +210,20 @@ public function leave() { \wcf\system\nodePush\NodePushHandler::getInstance()->sendMessage('be.bastelstu.chat.join'); } + /** + * Forces dead users to leave the chat. + */ + public function removeDeadUsers() { + $deadUsers = Room::getDeadUsers(); + + foreach ($deadUsers as $deadUser) { + $roomAction = new self(array(), 'leave', array( + 'user' => $deadUser + )); + $roomAction->executeAction(); + } + } + /** * Validates permissions. */ diff --git a/file/lib/page/NewMessagesPage.class.php b/file/lib/page/NewMessagesPage.class.php index e59a78b..34ffde5 100644 --- a/file/lib/page/NewMessagesPage.class.php +++ b/file/lib/page/NewMessagesPage.class.php @@ -65,13 +65,8 @@ public function readData() { $this->readMessages(); $this->users = $this->room->getUsers(); - $deadUsers = data\room\Room::getDeadUsers(); - foreach ($deadUsers as $deadUser) { - $roomAction = new data\room\RoomAction(array(), 'leave', array( - 'user' => $deadUser - )); - $roomAction->executeAction(); - } + $roomAction = new data\room\RoomAction(array(), 'removeDeadUsers'); + $roomAction->executeAction(); } /** diff --git a/file/lib/system/cronjob/CleanupCronjob.class.php b/file/lib/system/cronjob/CleanupCronjob.class.php index 460399b..47e6a03 100644 --- a/file/lib/system/cronjob/CleanupCronjob.class.php +++ b/file/lib/system/cronjob/CleanupCronjob.class.php @@ -24,29 +24,7 @@ public function execute(\wcf\data\cronjob\Cronjob $cronjob) { $suspensionAction->executeAction(); // kill dead users - $deadUsers = \chat\util\ChatUtil::getDiedUsers(); - foreach ($deadUsers as $deadUser) { - if (!$deadUser) continue; - - $user = new \wcf\data\user\User($deadUser['userID']); - if (CHAT_DISPLAY_JOIN_LEAVE) { - $userData['color'] = \chat\util\ChatUtil::readUserData('color', $user); - - $messageAction = new data\message\MessageAction(array(), 'create', array( - 'data' => array( - 'roomID' => $deadUser['roomID'], - 'sender' => $user->userID, - 'username' => $user->username, - 'time' => TIME_NOW, - 'type' => data\message\Message::TYPE_LEAVE, - 'message' => '', - 'color1' => $userData['color'][1], - 'color2' => $userData['color'][2] - ) - )); - $messageAction->executeAction(); - } - \chat\util\ChatUtil::writeUserData(array('roomID' => null), $user); - } + $roomAction = new data\room\RoomAction(array(), 'removeDeadUsers'); + $roomAction->executeAction(); } }