public function deletePMs($pmIDs)
 {
     require_once WCF_DIR . 'lib/data/message/attachment/AttachmentsEditor.class.php';
     // delete recipients
     $sql = "DELETE FROM wcf" . WCF_N . "_pm_to_user\n            WHERE       pmID IN (" . $pmIDs . ")";
     WCF::getDB()->sendQuery($sql);
     // delete messages
     $sql = "DELETE FROM wcf" . WCF_N . "_pm\n            WHERE       pmID IN (" . $pmIDs . ")";
     WCF::getDB()->sendQuery($sql);
     // delete pm hashes
     $sql = "DELETE FROM wcf" . WCF_N . "_pm_hash\n            WHERE       pmID IN (" . $pmIDs . ")";
     WCF::getDB()->sendQuery($sql);
     // delete attachments
     $attachments = new AttachmentsEditor($pmIDs, 'pm');
     $attachments->deleteAll();
 }
 /**
  * @see Cronjob::execute()
  */
 public function execute($data)
 {
     parent::execute($data);
     // delete old sessions
     Session::deleteExpiredSessions(TIME_NOW - SESSION_TIMEOUT);
     // delete old captchas
     $sql = "DELETE FROM\twcf" . WCF_N . "_captcha\n\t\t\tWHERE\t\tcaptchaDate < " . (TIME_NOW - 3600);
     WCF::getDB()->registerShutdownUpdate($sql);
     // delete post cache
     $sql = "DELETE FROM\twbb" . WBB_N . "_post_cache\n\t\t\tWHERE\t\tthreadID IN (\n\t\t\t\t\t\tSELECT\tthreadID\n\t\t\t\t\t\tFROM\twbb" . WBB_N . "_thread\n\t\t\t\t\t\tWHERE\tlastPostTime < " . (TIME_NOW - 86400 * 7) . "\n\t\t\t\t\t)";
     WCF::getDB()->registerShutdownUpdate($sql);
     // delete searches
     $sql = "DELETE FROM\twcf" . WCF_N . "_search\n\t\t\tWHERE\t\tsearchDate < " . (TIME_NOW - 7200);
     WCF::getDB()->registerShutdownUpdate($sql);
     // delete orphaned attachments
     $sql = "SELECT\tattachmentID\n\t\t\tFROM\twcf" . WCF_N . "_attachment\n\t\t\tWHERE\tcontainerID = 0\n\t\t\t\tAND uploadTime < " . (TIME_NOW - 43200);
     $result = WCF::getDB()->sendQuery($sql);
     if (WCF::getDB()->countRows($result) > 0) {
         require_once WCF_DIR . 'lib/data/message/attachment/AttachmentsEditor.class.php';
         $attachmentIDs = '';
         while ($row = WCF::getDB()->fetchArray($result)) {
             if (!empty($attachmentIDs)) {
                 $attachmentIDs .= ',';
             }
             $attachmentIDs .= $row['attachmentID'];
             // delete files
             AttachmentsEditor::deleteFile($row['attachmentID']);
         }
         if (!empty($attachmentIDs)) {
             $sql = "DELETE FROM\twcf" . WCF_N . "_attachment\n\t\t\t\t\tWHERE\t\tattachmentID IN (" . $attachmentIDs . ")";
             WCF::getDB()->registerShutdownUpdate($sql);
         }
     }
     // delete post / pm hashes
     $sql = "DELETE FROM\twbb" . WBB_N . "_post_hash\n\t\t\tWHERE\t\ttime < " . (TIME_NOW - 3600);
     WCF::getDB()->registerShutdownUpdate($sql);
     $sql = "DELETE FROM\twcf" . WCF_N . "_pm_hash\n\t\t\tWHERE\t\ttime < " . (TIME_NOW - 3600);
     WCF::getDB()->registerShutdownUpdate($sql);
     // delete bad user data
     $sql = "DELETE FROM\twbb" . WBB_N . "_user\n\t\t\tWHERE\t\tuserID NOT IN (\n\t\t\t\t\t\tSELECT\tuserID\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_user\n\t\t\t\t\t)";
     WCF::getDB()->registerShutdownUpdate($sql);
     // optimize tables to save some memory (mysql only)
     if (WCF::getDB()->getDBType() == 'MySQLDatabase' || WCF::getDB()->getDBType() == 'MySQLiDatabase' || WCF::getDB()->getDBType() == 'MySQLPDODatabase') {
         $sql = "OPTIMIZE TABLE\twcf" . WCF_N . "_session_data, wcf" . WCF_N . "_acp_session_data, wcf" . WCF_N . "_search";
         WCF::getDB()->registerShutdownUpdate($sql);
     }
     // clean up last post cache
     if (PROFILE_SHOW_LAST_POSTS) {
         $sql = "SELECT\t\tuserID, COUNT(*) AS counter\n\t\t\t\tFROM\t\twbb" . WBB_N . "_user_last_post\n\t\t\t\tGROUP BY \tuserID\n\t\t\t\tHAVING \t\tcounter > 20";
         $result = WCF::getDB()->sendQuery($sql);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $sql = "DELETE FROM\twbb" . WBB_N . "_user_last_post\n\t\t\t\t\tWHERE\t\tuserID = " . $row['userID'] . "\n\t\t\t\t\tORDER BY\ttime\n\t\t\t\t\tLIMIT\t\t" . ($row['counter'] - 20);
             WCF::getDB()->registerShutdownUpdate($sql);
         }
     }
 }
 /**
  * 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);
             }
         }
     }
 }