/** * Copies all SQL data of the threads with the given thread ids. */ public static function copyAll($threadIDs, $boardID) { if (empty($threadIDs)) { return; } // copy 'thread' data $mapping = array(); $sql = "SELECT\t*\n\t\t\tFROM \twbb" . WBB_N . "_thread\n\t\t\tWHERE \tthreadID IN (" . $threadIDs . ")"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $thread = new ThreadEditor(null, $row); $mapping[$thread->threadID] = $thread->copy($boardID); } // copy 'thread_announcement' data $sql = "SELECT\t*\n\t\t\tFROM \twbb" . WBB_N . "_thread_announcement\n\t\t\tWHERE \tthreadID IN (" . $threadIDs . ")"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $sql = "INSERT INTO\twbb" . WBB_N . "_thread_announcement\n\t\t\t\t\t\t(boardID, threadID)\n\t\t\t\tVALUES \t\t(" . $row['boardID'] . ", " . $mapping[$row['threadID']] . ")"; WCF::getDB()->registerShutdownUpdate($sql); } // copy 'thread_rating' data $sql = "SELECT\t*\n\t\t\tFROM \twbb" . WBB_N . "_thread_rating\n\t\t\tWHERE \tthreadID IN (" . $threadIDs . ")"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $sql = "INSERT INTO\twbb" . WBB_N . "_thread_rating\n\t\t\t\t\t\t(threadID, rating, userID, ipAddress)\n\t\t\t\tVALUES\t\t(" . $mapping[$row['threadID']] . ", " . $row['rating'] . ",\n\t\t\t\t\t\t" . $row['userID'] . ", '" . escapeString($row['ipAddress']) . "')"; WCF::getDB()->registerShutdownUpdate($sql); } // copy 'thread_subscription' data $sql = "SELECT\t*\n\t\t\tFROM \twbb" . WBB_N . "_thread_subscription\n\t\t\tWHERE \tthreadID IN (" . $threadIDs . ")"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $sql = "INSERT INTO \twbb" . WBB_N . "_thread_subscription\n\t\t\t\t\t\t(userID, threadID, enableNotification, emails)\n\t\t\t\tVALUES\t\t(" . $row['userID'] . ", " . $mapping[$row['threadID']] . ",\n\t\t\t\t\t\t" . $row['enableNotification'] . ", " . $row['emails'] . ")"; WCF::getDB()->registerShutdownUpdate($sql); } // copy 'thread_visit' data $sql = "SELECT \t*\n\t\t\tFROM \twbb" . WBB_N . "_thread_visit\n\t\t\tWHERE \tthreadID IN (" . $threadIDs . ")"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $sql = "INSERT INTO \twbb" . WBB_N . "_thread_visit\n\t\t\t\t\t\t(threadID, userID, lastVisitTime)\n\t\t\t\tVALUES\t\t(" . $mapping[$row['threadID']] . ", " . $row['userID'] . ", " . $row['lastVisitTime'] . ")"; WCF::getDB()->registerShutdownUpdate($sql); } // update user posts & activity points self::updateUserStats($threadIDs, 'copy', $boardID); // copy posts (and polls, attachments) PostEditor::copyAll(self::getAllPostIds($threadIDs), null, $mapping, $boardID); // check prefixes self::checkPrefixes(implode(',', $mapping), $boardID); }
/** * Copies the marked posts. */ public function copy() { if ($this->thread == null) { throw new IllegalLinkException(); } $this->board->checkModeratorPermission('canCopyPost'); // get threadids $threadIDs = PostEditor::getThreadIDs($this->postIDs); // remove user stats ThreadEditor::updateUserStats($this->thread->threadID, 'delete'); PostEditor::updateUserStats(ThreadEditor::getAllPostIDs($this->thread->threadID), 'delete'); // copy posts PostEditor::copyAll($this->postIDs, $this->thread->threadID, null, $this->thread->boardID, false); PostEditor::unmarkAll(); // refresh thread $this->thread->refresh(); // re-add user stats ThreadEditor::updateUserStats($this->thread->threadID, 'enable'); PostEditor::updateUserStats(ThreadEditor::getAllPostIDs($this->thread->threadID), 'enable'); // refresh counts $this->board->refresh(); // set last post in board $this->board->setLastPosts(); // reset cache ThreadAction::resetCache(); HeaderUtil::redirect('index.php?page=Thread&threadID=' . $this->thread->threadID . SID_ARG_2ND_NOT_ENCODED); exit; }
/** * Copies and inserts the marked posts in a new thread. */ public function copyAndInsert() { if ($this->board == null) { throw new IllegalLinkException(); } $this->board->checkModeratorPermission('canCopyPost'); // create new thread $thread = ThreadEditor::createFromPosts($this->postIDs, $this->board->boardID); // move posts PostEditor::copyAll($this->postIDs, $thread->threadID, null, $this->board->boardID); PostEditor::unmarkAll(); // check thread $thread->checkVisibility(); // refresh $thread->refresh(); // set last post $this->board->refresh(); $this->board->setLastPosts(); self::resetCache(); HeaderUtil::redirect($this->url); exit; }