/**
  * @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);
         }
     }
 }