/**
  * @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()
 {
     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();
 }
Ejemplo n.º 3
0
 /**
  * Copies likes from one object id to another.
  */
 public function copy()
 {
     $sourceObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.like.likeableObject', $this->parameters['sourceObjectType']);
     $targetObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.like.likeableObject', $this->parameters['targetObjectType']);
     //
     // step 1) get data
     //
     // get like object
     $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_like_object\n\t\t\tWHERE\tobjectTypeID = ?\n\t\t\t\tAND objectID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($sourceObjectType->objectTypeID, $this->parameters['sourceObjectID']));
     $row = $statement->fetchArray();
     // no (dis-)likes at all
     if ($row === false) {
         return;
     }
     unset($row['likeObjectID']);
     $row['objectTypeID'] = $targetObjectType->objectTypeID;
     $row['objectID'] = $this->parameters['targetObjectID'];
     $newLikeObject = LikeObjectEditor::create($row);
     //
     // step 2) copy
     //
     $sql = "INSERT INTO\twcf" . WCF_N . "_like\n\t\t\t\t\t(objectID, objectTypeID, objectUserID, userID, time, likeValue)\n\t\t\tSELECT\t\t" . $this->parameters['targetObjectID'] . ", " . $targetObjectType->objectTypeID . ", objectUserID, userID, time, likeValue\n\t\t\tFROM\t\twcf" . WCF_N . "_like\n\t\t\tWHERE\t\tobjectTypeID = ?\n\t\t\t\t\tAND objectID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($sourceObjectType->objectTypeID, $this->parameters['sourceObjectID']));
     //
     // step 3) update owner
     //
     if ($newLikeObject->objectUserID) {
         $sql = "SELECT\tCOUNT(*) AS count\n\t\t\t\tFROM\twcf" . WCF_N . "_like\n\t\t\t\tWHERE\tobjectTypeID = ?\n\t\t\t\t\tAND objectID = ?\n\t\t\t\t\tAND likeValue = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($targetObjectType->objectTypeID, $this->parameters['targetObjectID'], Like::LIKE));
         $row = $statement->fetchArray();
         if ($row['count']) {
             // update received likes
             $userEditor = new UserEditor(new User($newLikeObject->objectUserID));
             $userEditor->updateCounters(array('likesReceived' => $row['count']));
             // add activity points
             UserActivityPointHandler::getInstance()->fireEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', array($newLikeObject->objectUserID => $row['count']));
         }
     }
 }
 /**
  * @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);
 }
 /**
  * Removes user activity events for entries and files.
  * 
  * @param	array<integer>		$entryData
  * @param	boolean			$ignoreFiles
  */
 protected function removeActivityEvents(array $entryData, $ignoreFiles = false)
 {
     $entryIDs = array_keys($entryData);
     $userToItems = array();
     foreach ($entryData as $userID) {
         if (!$userID) {
             continue;
         }
         if (!isset($userToItems[$userID])) {
             $userToItems[$userID] = 0;
         }
         $userToItems[$userID]++;
     }
     // remove file data
     UserActivityEventHandler::getInstance()->removeEvents('de.incendium.filebase.recentActivityEvent.entry', $entryIDs);
     UserActivityPointHandler::getInstance()->removeEvents('de.incendium.filebase.activityPointEvent.entry', $userToItems);
     // remove file data
     if (!$ignoreFiles) {
         $conditions = new PreparedStatementConditionBuilder();
         $conditions->add("entryID IN (?)", array($entryIDs));
         $sql = "SELECT\tfileID\n\t\t\t\tFROM\tfilebase" . WCF_N . "_file\n\t\t\t\t" . $conditions;
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute($conditions->getParameters());
         $fileIDs = array();
         while ($row = $statement->fetchArray()) {
             $fileIDs[] = $row['fileID'];
         }
         UserActivityEventHandler::getInstance()->removeEvents('de.incendium.filebase.recentActivityEvent.file', $fileIDs);
     }
 }
 /**
  * Removes user activity events for entries and files.
  * 
  * @param    array<integer>        $entryData
  * @param    boolean            $ignoreFiles
  */
 protected function removeActivityEvents(array $entryData)
 {
     $entryIDs = array_keys($entryData);
     $userToItems = array();
     foreach ($entryData as $userID) {
         if (!$userID) {
             continue;
         }
         if (!isset($userToItems[$userID])) {
             $userToItems[$userID] = 0;
         }
         $userToItems[$userID]++;
     }
     // remove entry data
     UserActivityEventHandler::getInstance()->removeEvents('de.incendium.linklist.recentActivityEvent.entry', $entryIDs);
     UserActivityPointHandler::getInstance()->removeEvents('de.incendium.linklist.activityPointEvent.entry', $userToItems);
 }
 /**
  * @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);
 }
Ejemplo n.º 8
0
 /**
  * Removes all likes for given objects.
  * 
  * @param	string			$objectType
  * @param	array<integer>		$objectIDs
  * @param	array<string>		$notificationObjectTypes
  */
 public function removeLikes($objectType, array $objectIDs, array $notificationObjectTypes = array())
 {
     $objectTypeObj = $this->getObjectType($objectType);
     // get like objects
     $likeObjectList = new LikeObjectList();
     $likeObjectList->getConditionBuilder()->add('like_object.objectTypeID = ?', array($objectTypeObj->objectTypeID));
     $likeObjectList->getConditionBuilder()->add('like_object.objectID IN (?)', array($objectIDs));
     $likeObjectList->readObjects();
     $likeObjects = $likeObjectList->getObjects();
     $likeObjectIDs = $likeObjectList->getObjectIDs();
     // reduce count of received users
     $users = array();
     foreach ($likeObjects as $likeObject) {
         if ($likeObject->likes) {
             if (!isset($users[$likeObject->objectUserID])) {
                 $users[$likeObject->objectUserID] = 0;
             }
             $users[$likeObject->objectUserID] += $likeObject->likes;
         }
     }
     foreach ($users as $userID => $receivedLikes) {
         $userEditor = new UserEditor(new User(null, array('userID' => $userID)));
         $userEditor->updateCounters(array('likesReceived' => $receivedLikes * -1));
     }
     // get like ids
     $likeList = new LikeList();
     $likeList->getConditionBuilder()->add('like_table.objectTypeID = ?', array($objectTypeObj->objectTypeID));
     $likeList->getConditionBuilder()->add('like_table.objectID IN (?)', array($objectIDs));
     $likeList->readObjects();
     if (count($likeList)) {
         $likeData = array();
         foreach ($likeList as $like) {
             $likeData[$like->likeID] = $like->userID;
         }
         // delete like notifications
         if (!empty($notificationObjectTypes)) {
             foreach ($notificationObjectTypes as $notificationObjectType) {
                 UserNotificationHandler::getInstance()->removeNotifications($notificationObjectType, $likeList->getObjectIDs());
             }
         } else {
             if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType . '.notification')) {
                 UserNotificationHandler::getInstance()->removeNotifications($objectType . '.notification', $likeList->getObjectIDs());
             }
         }
         // revoke activity points
         UserActivityPointHandler::getInstance()->removeEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', $likeData);
         // delete likes
         LikeEditor::deleteAll(array_keys($likeData));
     }
     // delete like objects
     if (!empty($likeObjectIDs)) {
         LikeObjectEditor::deleteAll($likeObjectIDs);
     }
     // delete activity events
     if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.recentActivityEvent')) {
         UserActivityEventHandler::getInstance()->removeEvents($objectTypeObj->objectType . '.recentActivityEvent', $objectIDs);
     }
 }
 /**
  * @see	\wcf\data\IDeleteAction::delete()
  */
 public function delete()
 {
     // delete news entries
     parent::delete();
     // collect data
     $newsIDs = $perUserCount = $pollIDs = array();
     foreach ($this->objects as $news) {
         $newsIDs[] = $news->newsID;
         if ($news->pollID) {
             $pollIDs[] = $news->pollID;
         }
         if (!$news->isDisabled) {
             if (!isset($perUserCount[$news->userID])) {
                 $perUserCount[$news->userID] = 0;
             }
             $perUserCount[$news->userID]++;
         }
     }
     if (!empty($newsIDs)) {
         // delete like data
         LikeHandler::getInstance()->removeLikes('de.voolia.news.likeableNews', $newsIDs);
         // delete comments
         CommentHandler::getInstance()->deleteObjects('de.voolia.news.comment', $newsIDs);
         // delete tag to object entries
         TagEngine::getInstance()->deleteObjects('de.voolia.news.entry', $newsIDs);
         // delete entry activity events
         UserActivityEventHandler::getInstance()->removeEvents('de.voolia.news.recentActivityEvent.news', $newsIDs);
         UserActivityPointHandler::getInstance()->removeEvents('de.voolia.news.activityPointEvent.news', $perUserCount);
         // delete entry from search index
         SearchIndexManager::getInstance()->delete('de.voolia.news.entry', $newsIDs);
         // remove object from moderation queue
         ModerationQueueActivationManager::getInstance()->removeModeratedContent('de.voolia.news.entry', $newsIDs);
     }
     // delete a poll
     if (!empty($pollIDs)) {
         PollManager::getInstance()->removePolls($pollIDs);
     }
     // reset the user storage data
     UserStorageHandler::getInstance()->resetAll('newsUnreadEntries');
     UserStorageHandler::getInstance()->resetAll('newsUnreadWatchedEntries');
     // reset the news cache
     NewsEditor::resetNewsStatsCache();
 }
Ejemplo n.º 10
0
 public function delete()
 {
     $newsIDs = array();
     $attachedNewsIDs = array();
     foreach ($this->objects as $news) {
         $newsIDs[] = $news->newsID;
         if ($news->attachments != 0) {
             $attachedNewsIDs[] = $news->newsID;
         }
     }
     // remove activity points
     UserActivityPointHandler::getInstance()->removeEvents('de.codequake.cms.activityPointEvent.news', $newsIDs);
     // remove attaches
     if (!empty($attachedNewsIDs)) {
         AttachmentHandler::removeAttachments('de.codequake.cms.news', $attachedNewsIDs);
     }
     // delete old search index entries
     if (!empty($objectIDs)) {
         SearchIndexManager::getInstance()->delete('de.codequake.cms.news', $newsIDs);
     }
     if (isset($this->parameters['unmarkItems'])) {
         $this->unmarkItems($newsIDs);
     }
     return parent::delete();
 }