/**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     parent::execute();
     $users = $userIDs = array();
     foreach ($this->getObjectList() as $user) {
         $users[] = new UserEditor($user);
         $userIDs[] = $user->userID;
     }
     // update user ranks
     if (!empty($users)) {
         $action = new UserProfileAction($users, 'updateUserOnlineMarking');
         $action->executeAction();
     }
     if (!empty($userIDs)) {
         // update activity points
         UserActivityPointHandler::getInstance()->updateUsers($userIDs);
         // update like counter
         if (MODULE_LIKE) {
             $conditionBuilder = new PreparedStatementConditionBuilder();
             $conditionBuilder->add('user_table.userID IN (?)', array($userIDs));
             $sql = "UPDATE\twcf" . WCF_N . "_user user_table\n\t\t\t\t\tSET\tlikesReceived = (\n\t\t\t\t\t\t\tSELECT\tCOUNT(*)\n\t\t\t\t\t\t\tFROM\twcf" . WCF_N . "_like\n\t\t\t\t\t\t\tWHERE\tobjectUserID = user_table.userID\n\t\t\t\t\t\t\t\tAND likeValue = " . Like::LIKE . "\n\t\t\t\t\t\t)\n\t\t\t\t\t" . $conditionBuilder;
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute($conditionBuilder->getParameters());
         }
     }
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     $this->objectList->getConditionBuilder()->add('conversation_message.messageID BETWEEN ? AND ?', array($this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit));
     parent::execute();
     if (!$this->loopCount) {
         // reset search index
         SearchIndexManager::getInstance()->reset('com.woltlab.wcf.conversation.message');
     }
     // prepare statements
     $attachmentObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'com.woltlab.wcf.conversation.message');
     $sql = "SELECT\t\tCOUNT(*) AS attachments\n\t\t\tFROM\t\twcf" . WCF_N . "_attachment\n\t\t\tWHERE\t\tobjectTypeID = ?\n\t\t\t\t\tAND objectID = ?";
     $attachmentStatement = WCF::getDB()->prepareStatement($sql);
     foreach ($this->objectList as $message) {
         SearchIndexManager::getInstance()->add('com.woltlab.wcf.conversation.message', $message->messageID, $message->message, $message->subject ?: '', $message->time, $message->userID, $message->username);
         $editor = new ConversationMessageEditor($message);
         $data = array();
         // count attachments
         $attachmentStatement->execute(array($attachmentObjectType->objectTypeID, $message->messageID));
         $row = $attachmentStatement->fetchSingleRow();
         $data['attachments'] = $row['attachments'];
         // update embedded objects
         $data['hasEmbeddedObjects'] = MessageEmbeddedObjectManager::getInstance()->registerObjects('com.woltlab.wcf.conversation.message', $message->messageID, $message->message) ? 1 : 0;
         $editor->update($data);
     }
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     $this->objectList->getConditionBuilder()->add('post.postID BETWEEN ? AND ?', array($this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit));
     parent::execute();
     foreach ($this->objectList as $post) {
         //$post->message
     }
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     parent::execute();
     foreach ($this->objectList as $attachment) {
         try {
             $action = new AttachmentAction(array($attachment), 'generateThumbnails');
             $action->executeAction();
         } catch (SystemException $e) {
         }
     }
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     parent::execute();
     // reset search index on first cycle
     if (!$this->loopCount) {
         SearchIndexManager::getInstance()->reset('de.codequake.cms.page');
     }
     // re-create search index
     $pageAction = new PageAction($this->objectList->getObjects(), 'refreshSearchIndex', array('isBulkProcessing' => true));
     $pageAction->executeAction();
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     parent::execute();
     if (!count($this->objectList)) {
         return;
     }
     if (!$this->loopCount) {
         // remove the activity points
         UserActivityPointHandler::getInstance()->reset('de.voolia.news.activityPointEvent.news');
         // remove the entry from search index
         SearchIndexManager::getInstance()->reset('de.voolia.news.entry');
     }
     // get news attachments
     $attachmentObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'de.voolia.news.entry');
     $sql = "SELECT\t\tCOUNT(*) AS attachments\n\t\t\tFROM\t\twcf" . WCF_N . "_attachment\n\t\t\tWHERE\t\tobjectTypeID = ?\n\t\t\tAND\t\tobjectID = ?";
     $attachments = WCF::getDB()->prepareStatement($sql);
     // calculate the cumulative likes
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("objectID IN (?)", array($this->objectList->getObjectIDs()));
     $conditions->add("objectTypeID = ?", array(ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.like.likeableObject', 'de.voolia.news.likeableNews')));
     $sql = "SELECT\tobjectID,\n\t\t\t\tcumulativeLikes\n\t\t\tFROM\twcf" . WCF_N . "_like_object\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     $likes = array();
     while ($row = $statement->fetchArray()) {
         $likes[$row['objectID']] = $row['cumulativeLikes'];
     }
     // update the news entries
     $userItems = array();
     foreach ($this->objectList as $news) {
         // new EntryEditor
         $editor = new NewsEditor($news);
         // update search index
         SearchIndexManager::getInstance()->add('de.voolia.news.entry', $news->newsID, $news->message, $news->subject, $news->time, $news->userID, $news->username, $news->languageID);
         // news data
         $newsData = array();
         // likes
         $newsData['cumulativeLikes'] = isset($likes[$news->newsID]) ? $likes[$news->newsID] : 0;
         // attachments
         $attachments->execute(array($attachmentObjectType->objectTypeID, $news->newsID));
         $row = $attachments->fetchArray();
         $newsData['attachments'] = $row['attachments'];
         if ($news->userID) {
             if (!isset($userItems[$news->userID])) {
                 $userItems[$news->userID] = 0;
             }
             $userItems[$news->userID]++;
         }
         $editor->update($newsData);
     }
     // update activity points
     UserActivityPointHandler::getInstance()->fireEvents('de.voolia.news.activityPointEvent.news', $userItems, false);
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     parent::execute();
     if (!$this->loopCount) {
         // reset activity points
         UserActivityPointHandler::getInstance()->reset('de.incendium.linklist.activityPointEvent.entry');
         // reset search index
         SearchIndexManager::getInstance()->reset('de.incendium.linklist.entry');
     }
     if (!count($this->objectList)) {
         return;
     }
     // fetch cumulative likes
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("objectTypeID = ?", array(ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.like.likeableObject', 'de.incendium.linklist.likeableEntry')));
     $conditions->add("objectID IN (?)", array($this->objectList->getObjectIDs()));
     $sql = "SELECT\tobjectID, cumulativeLikes\n\t\t\tFROM\twcf" . WCF_N . "_like_object\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     $cumulativeLikes = array();
     while ($row = $statement->fetchArray()) {
         $cumulativeLikes[$row['objectID']] = $row['cumulativeLikes'];
     }
     // prepare statements
     $attachmentObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'de.incendium.linklist.entry');
     $sql = "SELECT\t\tCOUNT(*) AS attachments\n\t\t\tFROM\t\twcf" . WCF_N . "_attachment\n\t\t\tWHERE\t\tobjectTypeID = ?\n\t\t\t\t\tAND objectID = ?";
     $attachmentStatement = WCF::getDB()->prepareStatement($sql);
     $itemsToUser = array();
     foreach ($this->objectList as $entry) {
         $editor = new EntryEditor($entry);
         $data = array();
         // count attachments
         $attachmentStatement->execute(array($attachmentObjectType->objectTypeID, $entry->entryID));
         $row = $attachmentStatement->fetchArray();
         $data['attachments'] = $row['attachments'];
         // update cumulative likes
         $data['cumulativeLikes'] = isset($cumulativeLikes[$entry->entryID]) ? $cumulativeLikes[$entry->entryID] : 0;
         $editor->update($data);
         if ($entry->userID) {
             if (!isset($itemsToUser[$entry->userID])) {
                 $itemsToUser[$entry->userID] = 0;
             }
             $itemsToUser[$entry->userID]++;
         }
         // update search index
         SearchIndexManager::getInstance()->add('de.incendium.linklist.entry', $entry->entryID, $entry->message, $entry->subject, $entry->time, $entry->userID, $entry->username, $entry->languageID);
     }
     // update activity points
     UserActivityPointHandler::getInstance()->fireEvents('de.incendium.linklist.activityPointEvent.entry', $itemsToUser, false);
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     parent::execute();
     if (!$this->loopCount) {
         // reset cached users
         $sql = "UPDATE\twcf" . WCF_N . "_like_object\n\t\t\t\tSET\tcachedUsers = NULL";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute();
     }
     $sql = "SELECT\t\tuserID\n\t\t\tFROM\t\twcf" . WCF_N . "_like\n\t\t\tWHERE\t\tobjectID = ?\n\t\t\t\t\tAND objectTypeID = ?\n\t\t\t\t\tAND likeValue = ?\n\t\t\tORDER BY\ttime DESC";
     $statement = WCF::getDB()->prepareStatement($sql, 3);
     $userData = $userIDs = array();
     foreach ($this->objectList as $likeObject) {
         $userData[$likeObject->likeObjectID] = array();
         $statement->execute(array($likeObject->objectID, $likeObject->objectTypeID, Like::LIKE));
         while ($row = $statement->fetchArray()) {
             $userData[$likeObject->likeObjectID][] = $row['userID'];
             $userIDs[] = $row['userID'];
         }
     }
     if (empty($userIDs)) {
         return;
     }
     // fetch usernames
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("userID IN (?)", array($userIDs));
     $sql = "SELECT\tuserID, username\n\t\t\tFROM\twcf" . WCF_N . "_user\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     $usernames = array();
     while ($row = $statement->fetchArray()) {
         $usernames[$row['userID']] = $row['username'];
     }
     // update like objects
     $sql = "UPDATE\twcf" . WCF_N . "_like_object\n\t\t\tSET\tcachedUsers = ?\n\t\t\tWHERE\tlikeObjectID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     WCF::getDB()->beginTransaction();
     foreach ($userData as $likeObjectID => $data) {
         foreach ($data as &$value) {
             $value = array('userID' => $value, 'username' => $usernames[$value]);
         }
         unset($value);
         $statement->execute(array(serialize($data), $likeObjectID));
     }
     WCF::getDB()->commitTransaction();
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     parent::execute();
     if (!$this->loopCount) {
         // reset activity points
         UserActivityPointHandler::getInstance()->reset('com.woltlab.wcf.like.activityPointEvent.receivedLikes');
         // reset like object data
         $sql = "UPDATE\twcf" . WCF_N . "_like_object\n\t\t\t\tSET\tlikes = 0,\n\t\t\t\t\tdislikes = 0,\n\t\t\t\t\tcumulativeLikes = 0";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute();
     }
     $itemsToUser = array();
     $likeObjectData = array();
     foreach ($this->objectList as $like) {
         if ($like->objectUserID && $like->likeValue == Like::LIKE) {
             if (!isset($itemsToUser[$like->objectUserID])) {
                 $itemsToUser[$like->objectUserID] = 0;
             }
             $itemsToUser[$like->objectUserID]++;
         }
         if (!isset($likeObjectData[$like->objectTypeID])) {
             $likeObjectData[$like->objectTypeID] = array();
         }
         if (!isset($likeObjectData[$like->objectTypeID][$like->objectID])) {
             $likeObjectData[$like->objectTypeID][$like->objectID] = array('likes' => 0, 'dislikes' => 0, 'cumulativeLikes' => 0, 'objectUserID' => $like->objectUserID);
         }
         if ($like->likeValue == Like::LIKE) {
             $likeObjectData[$like->objectTypeID][$like->objectID]['likes']++;
         } else {
             $likeObjectData[$like->objectTypeID][$like->objectID]['dislikes']++;
         }
         $likeObjectData[$like->objectTypeID][$like->objectID]['cumulativeLikes'] += $like->likeValue;
     }
     // update activity points
     UserActivityPointHandler::getInstance()->fireEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', $itemsToUser, false);
     $sql = "INSERT INTO\t\t\twcf" . WCF_N . "_like_object\n\t\t\t\t\t\t\t(objectTypeID, objectID, objectUserID, likes, dislikes, cumulativeLikes)\n\t\t\tVALUES\t\t\t\t(?, ?, ?, ?, ?, ?)\n\t\t\tON DUPLICATE KEY UPDATE\t\tlikes = likes + VALUES(likes),\n\t\t\t\t\t\t\tdislikes = dislikes + VALUES(dislikes),\n\t\t\t\t\t\t\tcumulativeLikes = cumulativeLikes + VALUES(cumulativeLikes)";
     $statement = WCF::getDB()->prepareStatement($sql);
     WCF::getDB()->beginTransaction();
     foreach ($likeObjectData as $objectTypeID => $objects) {
         foreach ($objects as $objectID => $data) {
             $statement->execute(array($objectTypeID, $objectID, $data['objectUserID'], $data['likes'], $data['dislikes'], $data['cumulativeLikes']));
         }
     }
     WCF::getDB()->commitTransaction();
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     $this->objectList->getConditionBuilder()->add('conversation.conversationID BETWEEN ? AND ?', array($this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit));
     parent::execute();
     // prepare statements
     $sql = "SELECT\t\tmessageID, time, userID, username\n\t\t\tFROM\t\twcf" . WCF_N . "_conversation_message\n\t\t\tWHERE\t\tconversationID = ?\n\t\t\tORDER BY\ttime";
     $firstMessageStatement = WCF::getDB()->prepareStatement($sql, 1);
     $sql = "SELECT\t\ttime, userID, username\n\t\t\tFROM\t\twcf" . WCF_N . "_conversation_message\n\t\t\tWHERE\t\tconversationID = ?\n\t\t\tORDER BY\ttime DESC";
     $lastMessageStatement = WCF::getDB()->prepareStatement($sql, 1);
     $sql = "SELECT\tCOUNT(*) AS messages,\n\t\t\t\tSUM(attachments) AS attachments\n\t\t\tFROM\twcf" . WCF_N . "_conversation_message\n\t\t\tWHERE\tconversationID = ?";
     $statsStatement = WCF::getDB()->prepareStatement($sql);
     $sql = "SELECT\tCOUNT(*) AS participants\n\t\t\tFROM\twcf" . WCF_N . "_conversation_to_user conversation_to_user\n\t\t\tWHERE\tconversation_to_user.conversationID = ?\n\t\t\t\tAND conversation_to_user.hideConversation <> ?\n\t\t\t\tAND conversation_to_user.participantID <> ?\n\t\t\t\tAND conversation_to_user.isInvisible = ?";
     $participantCounterStatement = WCF::getDB()->prepareStatement($sql);
     $sql = "SELECT\t\tconversation_to_user.participantID AS userID, conversation_to_user.hideConversation, user_table.username\n\t\t\tFROM\t\twcf" . WCF_N . "_conversation_to_user conversation_to_user\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_user user_table\n\t\t\tON\t\t(user_table.userID = conversation_to_user.participantID)\n\t\t\tWHERE\t\tconversation_to_user.conversationID = ?\n\t\t\t\t\tAND conversation_to_user.participantID <> ?\n\t\t\t\t\tAND conversation_to_user.isInvisible = ?\n\t\t\tORDER BY\tuser_table.username";
     $participantStatement = WCF::getDB()->prepareStatement($sql, 5);
     $sql = "SELECT\tCOUNT(*) AS participants\n\t\t\tFROM\twcf" . WCF_N . "_conversation_to_user\n\t\t\tWHERE\tconversationID = ?\n\t\t\t\tAND participantID IS NOT NULL";
     $existingParticipantStatement = WCF::getDB()->prepareStatement($sql, 5);
     $obsoleteConversations = array();
     foreach ($this->objectList as $conversation) {
         $editor = new ConversationEditor($conversation);
         // check for obsolete conversations
         $obsolete = false;
         if ($conversation->isDraft) {
             if (!$conversation->userID) {
                 $obsolete = true;
             }
         } else {
             $existingParticipantStatement->execute(array($conversation->conversationID));
             $row = $existingParticipantStatement->fetchSingleRow();
             if (!$row['participants']) {
                 $obsolete = true;
             }
         }
         if ($obsolete) {
             $obsoleteConversations[] = $editor;
             continue;
         }
         // update data
         $data = array();
         // get first post
         $firstMessageStatement->execute(array($conversation->conversationID));
         if (($row = $firstMessageStatement->fetchSingleRow()) !== false) {
             $data['firstMessageID'] = $row['messageID'];
             $data['lastPostTime'] = $data['time'] = $row['time'];
             $data['userID'] = $row['userID'];
             $data['username'] = $row['username'];
         }
         // get last post
         $lastMessageStatement->execute(array($conversation->conversationID));
         if (($row = $lastMessageStatement->fetchSingleRow()) !== false) {
             $data['lastPostTime'] = $row['time'];
             $data['lastPosterID'] = $row['userID'];
             $data['lastPoster'] = $row['username'];
         }
         // get stats
         $statsStatement->execute(array($conversation->conversationID));
         $row = $statsStatement->fetchSingleRow();
         $data['replies'] = $row['messages'] ? $row['messages'] - 1 : 0;
         $data['attachments'] = $row['attachments'] ?: 0;
         // get number of participants
         $participantCounterStatement->execute(array($conversation->conversationID, Conversation::STATE_LEFT, $conversation->userID, 0));
         $row = $participantCounterStatement->fetchSingleRow();
         $data['participants'] = $row['participants'];
         // get participant summary
         $participantStatement->execute(array($conversation->conversationID, $conversation->userID, 0));
         $users = array();
         while ($row = $participantStatement->fetchArray()) {
             $users[] = $row;
         }
         $data['participantSummary'] = serialize($users);
         $editor->update($data);
     }
     // delete obsolete conversations
     if (!empty($obsoleteConversations)) {
         $action = new ConversationAction($obsoleteConversations, 'delete');
         $action->executeAction();
     }
 }