/**
  * @see Action::execute()
  */
 public function execute()
 {
     parent::execute();
     // count board
     $sql = "SELECT\tCOUNT(*) AS count\n\t\t\tFROM\twbb" . WBB_N . "_board";
     $row = WCF::getDB()->getFirstRow($sql);
     $count = $row['count'];
     // get board ids
     $boardIDs = '';
     $sql = "SELECT\t\tboardID\n\t\t\tFROM\t\twbb" . WBB_N . "_board\n\t\t\tORDER BY\tboardID";
     $result = WCF::getDB()->sendQuery($sql, $this->limit, $this->limit * $this->loop);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $boardIDs .= ',' . $row['boardID'];
         // update last post
         $board = new BoardEditor($row['boardID']);
         $board->setLastPosts();
     }
     if (empty($boardIDs)) {
         // clear board cache
         WCF::getCache()->clear(WBB_DIR . 'cache', 'cache.boardData.php');
         $this->calcProgress();
         $this->finish();
     }
     // update boards
     $sql = "UPDATE\twbb" . WBB_N . "_board board\n\t\t\tSET\tthreads = (\n\t\t\t\t\tSELECT\tCOUNT(*)\n\t\t\t\t\tFROM\twbb" . WBB_N . "_thread\n\t\t\t\t\tWHERE\tboardID = board.boardID\n\t\t\t\t\t\tAND isDeleted = 0\n\t\t\t\t\t\tAND isDisabled = 0\n\t\t\t\t),\n\t\t\t\tposts = (\n\t\t\t\t\tSELECT\tIFNULL(SUM(replies), 0) + COUNT(*)\n\t\t\t\t\tFROM\twbb" . WBB_N . "_thread thread\n\t\t\t\t\tWHERE\tboardID = board.boardID\n\t\t\t\t\t\tAND isDeleted = 0\n\t\t\t\t\t\tAND isDisabled = 0\n\t\t\t\t)\n\t\t\tWHERE\tboard.boardID IN (0" . $boardIDs . ")";
     WCF::getDB()->sendQuery($sql);
     $this->executed();
     $this->calcProgress($this->limit * $this->loop, $count);
     $this->nextLoop();
 }
 /**
  * Removes a thread.
  */
 public function removeThread()
 {
     self::resetCache();
     // refresh board last post
     $this->board->refresh();
     if ($this->thread->lastPostTime >= $this->board->getLastPostTime($this->thread->languageID)) {
         $this->board->setLastPosts();
     }
 }
 /**
  * Merges posts.
  */
 public function merge()
 {
     if ($this->post === null || empty($this->postIDs)) {
         throw new IllegalLinkException();
     }
     // remove target post from source
     $postIDArray = explode(',', $this->postIDs);
     if (($key = array_search($this->post->postID, $postIDArray)) !== false) {
         unset($postIDArray[$key]);
         $this->postIDs = implode(',', $postIDArray);
     }
     // get thread ids
     $threadIDs = PostEditor::getThreadIDs($this->postIDs);
     // get boards
     list($boards, $boardIDs) = ThreadEditor::getBoards($threadIDs);
     // check permissions
     $this->board->checkModeratorPermission('canMergePost');
     foreach ($boards as $board) {
         $board->checkModeratorPermission('canMergePost');
     }
     // remove user stats
     ThreadEditor::updateUserStats($threadIDs, 'delete');
     PostEditor::updateUserStats(ThreadEditor::getAllPostIDs($threadIDs), 'delete');
     // merge posts
     PostEditor::mergeAll($this->postIDs, $this->post->postID);
     PostEditor::unmarkAll();
     // handle threads (check for empty, deleted and hidden threads)
     ThreadEditor::checkVisibilityAll($threadIDs);
     // refresh last post, replies, attachments, polls in threads
     ThreadEditor::refreshAll($threadIDs);
     // re-add user stats
     ThreadEditor::updateUserStats($threadIDs, 'enable');
     PostEditor::updateUserStats(ThreadEditor::getAllPostIDs($threadIDs), 'enable');
     // refresh counts
     BoardEditor::refreshAll($boardIDs);
     // refresh last post in boards
     $this->board->setLastPosts();
     foreach ($boards as $board) {
         $board->setLastPosts();
     }
     HeaderUtil::redirect($this->url);
     exit;
 }