/** * Copies all SQL data of the posts with the given posts ids. */ public static function copyAll($postIDs, $threadID, $threadMapping = null, $boardID = 0, $updateUserStats = true) { if (empty($postIDs)) { return; } // copy 'post' data $postMapping = array(); $sql = "SELECT\t*\n\t\t\tFROM \twbb" . WBB_N . "_post\n\t\t\tWHERE \tpostID IN (" . $postIDs . ")"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $post = new PostEditor(null, $row); $postMapping[$post->postID] = $post->copy($threadID ? $threadID : $threadMapping[$row['threadID']]); } // refresh first post ids require_once WBB_DIR . 'lib/data/thread/ThreadEditor.class.php'; ThreadEditor::refreshFirstPostIDAll($threadID ? $threadID : implode(',', $threadMapping)); // update user posts and activity points if ($updateUserStats) { self::updateUserStats(implode(',', $postMapping), 'copy', $boardID); } // copy 'post_cache' data $sql = "SELECT\t*\n\t\t\tFROM \twbb" . WBB_N . "_post_cache\n\t\t\tWHERE \tpostID IN (" . $postIDs . ")"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $sql = "INSERT INTO \twbb" . WBB_N . "_post_cache\n\t\t\t\t\t\t(postID, threadID, messageCache)\n\t\t\t\tVALUES\t\t(" . $postMapping[$row['postID']] . ",\n\t\t\t\t\t\t" . ($threadID ? $threadID : $threadMapping[$row['threadID']]) . ",\n\t\t\t\t\t\t'" . escapeString($row['messageCache']) . "')"; WCF::getDB()->sendQuery($sql); } // copy 'post_report' data $sql = "SELECT \t*\n\t\t\tFROM \twbb" . WBB_N . "_post_report\n\t\t\tWHERE \tpostID IN (" . $postIDs . ")"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $sql = "INSERT INTO \twbb" . WBB_N . "_post_report\n\t\t\t\t\t\t(postID, userID, report, reportTime)\n\t\t\t\tVALUES\t\t(" . $postMapping[$row['postID']] . ",\n\t\t\t\t\t\t" . $row['userID'] . ",\n\t\t\t\t\t\t'" . escapeString($row['report']) . "',\n\t\t\t\t\t\t" . $row['reportTime'] . ")"; WCF::getDB()->sendQuery($sql); } // copy polls require_once WCF_DIR . 'lib/data/message/poll/PollEditor.class.php'; $pollMapping = PollEditor::copyAll($postIDs, $postMapping); if (is_array($pollMapping)) { foreach ($pollMapping as $oldPollID => $newPollID) { $sql = "UPDATE\t\twbb" . WBB_N . "_post\n\t\t\t\t\tSET \t\tpollID = " . $newPollID . "\n\t\t\t\t\tWHERE \t\tpollID = " . $oldPollID . "\n\t\t\t\t\t\t\tAND postID NOT IN (SELECT messageID FROM wcf" . WCF_N . "_poll WHERE pollID = " . $oldPollID . ")"; WCF::getDB()->sendQuery($sql); } } // copy attachments require_once WCF_DIR . 'lib/data/message/attachment/AttachmentsEditor.class.php'; $attachment = new AttachmentsEditor($postIDs); $attachmentMapping = $attachment->copyAll($postMapping); // update inline attachments if (count($attachmentMapping) > 0) { $sql = "SELECT\tpostID, message\n\t\t\t\tFROM\twbb" . WBB_N . "_post\n\t\t\t\tWHERE\tpostID IN (" . implode(',', array_keys($attachmentMapping)) . ")\n\t\t\t\t\tAND message LIKE '%[attach%'"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $messageChanged = false; foreach ($attachmentMapping[$row['postID']] as $oldAttachmentID => $newAttachmentID) { $row['message'] = StringUtil::replaceIgnoreCase('[attach=' . $oldAttachmentID . ']', '[attach=' . $newAttachmentID . ']', $row['message']); $row['message'] = StringUtil::replaceIgnoreCase('[attach]' . $oldAttachmentID . '[/attach]', '[attach]' . $newAttachmentID . '[/attach]', $row['message']); $messageChanged = true; } if ($messageChanged) { // update message $sql = "UPDATE\twbb" . WBB_N . "_post\n\t\t\t\t\t\tSET\tmessage = '" . escapeString($row['message']) . "'\n\t\t\t\t\t\tWHERE\tpostID = " . $row['postID']; WCF::getDB()->sendQuery($sql); // delete post cache $sql = "DELETE FROM\twbb" . WBB_N . "_post_cache\n\t\t\t\t\t\tWHERE\t\tpostID = " . $row['postID']; WCF::getDB()->sendQuery($sql); } } } }