/** * @see \wcf\data\DatabaseObjectList::readObjects() */ public function readObjects() { parent::readObjects(); $userIDs = array(); $eventGroups = array(); foreach ($this->objects as &$event) { $userIDs[] = $event->userID; $event = new ViewableUserActivityEvent($event); if (!isset($eventGroups[$event->objectTypeID])) { $objectType = UserActivityEventHandler::getInstance()->getObjectType($event->objectTypeID); $eventGroups[$event->objectTypeID] = array('className' => $objectType->className, 'objects' => array()); } $eventGroups[$event->objectTypeID]['objects'][] = $event; } unset($event); // set user profiles if (!empty($userIDs)) { $userIDs = array_unique($userIDs); $users = UserProfile::getUserProfiles($userIDs); foreach ($this->objects as $event) { $event->setUserProfile($users[$event->userID]); } } // parse events foreach ($eventGroups as $eventData) { $eventClass = call_user_func(array($eventData['className'], 'getInstance')); $eventClass->prepare($eventData['objects']); } }
public function publish() { foreach ($this->objects as $news) { $news->update(array('isDisabled' => 0)); // recent UserActivityEventHandler::getInstance()->fireEvent('de.codequake.cms.news.recentActivityEvent', $news->newsID, $news->languageID, $news->userID, $news->time); UserActivityPointHandler::getInstance()->fireEvent('de.codequake.cms.activityPointEvent.news', $news->newsID, $news->userID); // update search index SearchIndexManager::getInstance()->add('de.codequake.cms.news', $news->newsID, $news->message, $news->subject, $news->time, $news->userID, $news->username, $news->languageID); } // reset storage UserStorageHandler::getInstance()->resetAll('cmsUnreadNews'); }
/** * Returns the object type name. * * @return string */ public function getObjectTypeName() { return UserActivityEventHandler::getInstance()->getObjectType($this->objectTypeID)->objectType; }
/** * Sets like/dislike for an object, executing this method again with the same parameters * will revert the status (removing like/dislike). * * @return array */ protected function updateLike($likeValue) { $likeData = LikeHandler::getInstance()->like($this->likeableObject, WCF::getUser(), $likeValue); // handle activity event if (UserActivityEventHandler::getInstance()->getObjectTypeID($this->objectType->objectType . '.recentActivityEvent')) { if ($likeData['data']['liked'] == 1) { UserActivityEventHandler::getInstance()->fireEvent($this->objectType->objectType . '.recentActivityEvent', $this->parameters['data']['objectID'], $this->likeableObject->getLanguageID()); } else { UserActivityEventHandler::getInstance()->removeEvents($this->objectType->objectType . '.recentActivityEvent', array($this->parameters['data']['objectID'])); } } // get stats return array('likes' => $likeData['data']['likes'] === null ? 0 : $likeData['data']['likes'], 'dislikes' => $likeData['data']['dislikes'] === null ? 0 : $likeData['data']['dislikes'], 'cumulativeLikes' => $likeData['data']['cumulativeLikes'] === null ? 0 : $likeData['data']['cumulativeLikes'], 'isLiked' => $likeData['data']['liked'] == 1 ? 1 : 0, 'isDisliked' => $likeData['data']['liked'] == -1 ? 1 : 0, 'containerID' => $this->parameters['data']['containerID'], 'newValue' => $likeData['newValue'], 'oldValue' => $likeData['oldValue'], 'users' => $likeData['users']); }
/** * 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); }
/** * Removes all comments for given objects. * * @param string $objectType * @param array<integer> $objectIDs */ public function deleteObjects($objectType, array $objectIDs) { $objectTypeID = $this->getObjectTypeID($objectType); $objectTypeObj = $this->getObjectType($objectTypeID); // get comment ids $commentList = new CommentList(); $commentList->getConditionBuilder()->add('comment.objectTypeID = ?', array($objectTypeID)); $commentList->getConditionBuilder()->add('comment.objectID IN (?)', array($objectIDs)); $commentList->readObjectIDs(); $commentIDs = $commentList->getObjectIDs(); // no comments -> skip if (empty($commentIDs)) { return; } // get response ids $responseList = new CommentResponseList(); $responseList->getConditionBuilder()->add('comment_response.commentID IN (?)', array($commentIDs)); $responseList->readObjectIDs(); $responseIDs = $responseList->getObjectIDs(); // delete likes $notificationObjectTypes = array(); if (UserNotificationHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.like.notification')) { $notificationObjectTypes[] = $objectTypeObj->objectType . '.like.notification'; } LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment', $commentIDs, $notificationObjectTypes); // delete activity events if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.recentActivityEvent')) { UserActivityEventHandler::getInstance()->removeEvents($objectTypeObj->objectType . '.recentActivityEvent', $commentIDs); } // delete notifications if (UserNotificationHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.notification')) { UserNotificationHandler::getInstance()->removeNotifications($objectTypeObj->objectType . '.notification', $commentIDs); } if (!empty($responseIDs)) { // delete likes (for responses) $notificationObjectTypes = array(); if (UserNotificationHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.response.like.notification')) { $notificationObjectTypes[] = $objectTypeObj->objectType . '.response.like.notification'; } LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment.response', $responseIDs, $notificationObjectTypes); // delete activity events (for responses) if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.response.recentActivityEvent')) { UserActivityEventHandler::getInstance()->removeEvents($objectTypeObj->objectType . '.response.recentActivityEvent', $responseIDs); } // delete notifications (for responses) if (UserNotificationHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.response.notification')) { UserNotificationHandler::getInstance()->removeNotifications($objectTypeObj->objectType . '.response.notification', $responseIDs); } } // delete comments / responses CommentEditor::deleteAll($commentIDs); }
public function updateLike($oMbqEtForumPost) { if (is_array($oMbqEtForumPost)) { MbqError::alert('', __METHOD__ . ',line:' . __LINE__ . '.' . MBQ_ERR_INFO_NOT_ACHIEVE); } $oPost = $oMbqEtForumPost->mbqBind['oViewablePost']->getDecoratedObject(); //ref wcf\data\like\LikeAction\Like $objectType = LikeHandler::getInstance()->getObjectType('com.woltlab.wbb.likeablePost'); if ($objectType === null) { MbqError::alert('', '', '', MBQ_ERR_APP); } $objectTypeProvider = $objectType->getProcessor(); $likeableObject = $objectTypeProvider->getObjectByID($oMbqEtForumPost->postId->oriValue); $likeableObject->setObjectType($objectType); $likeData = LikeHandler::getInstance()->like($likeableObject, WCF::getUser(), Like::LIKE); // handle activity event if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType . '.recentActivityEvent')) { if ($likeData['data']['liked'] == 1) { UserActivityEventHandler::getInstance()->fireEvent($objectType->objectType . '.recentActivityEvent', $oMbqEtForumPost->postId->oriValue); } else { UserActivityEventHandler::getInstance()->removeEvents($objectType->objectType . '.recentActivityEvent', array($oMbqEtForumPost->postId->oriValue)); } } // change post data $user = WCF::getUser(); if ($likeData['data']['liked'] == 1) { $oMbqEtForumPost->isLiked->setOriValue(MbqBaseFdt::getFdt('MbqFdtForum.MbqEtForumPost.isLiked.range.yes')); $oMbqEtLike = MbqMain::$oClk->newObj('MbqEtLike'); $oMbqEtLike->key->setOriValue($oMbqEtForumPost->postId->oriValue); $oMbqEtLike->userId->setOriValue($user->__get('userID')); $oMbqEtLike->type->setOriValue(MbqBaseFdt::getFdt('MbqFdtLike.MbqEtLike.type.range.likeForumPost')); $oMbqEtLike->postTime->setOriValue($oPost->time); $oMbqRdEtUser = MbqMain::$oClk->newObj('MbqRdEtUser'); $oMbqEtLike->oMbqEtUser = $oMbqRdEtUser->initOMbqEtUser($user->__get('userID'), array('case' => 'byUserId')); $oMbqEtForumPost->objsMbqEtLike[$user->__get('userID')] = $oMbqEtLike; } else { $oMbqEtForumPost->isLiked->setOriValue(MbqBaseFdt::getFdt('MbqFdtForum.MbqEtForumPost.isLiked.range.no')); unset($oMbqEtForumPost->objsMbqEtLike[$user->__get('userID')]); } return $oMbqEtForumPost; }
/** * 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\AbstractDatabaseObjectAction::delete() */ public function delete() { $returnValues = parent::delete(); $followUserIDs = array(); foreach ($this->objects as $follow) { $followUserIDs[] = $follow->followUserID; // remove activity event UserActivityEventHandler::getInstance()->removeEvents('com.woltlab.wcf.user.recentActivityEvent.follow', array($follow->followUserID)); } // reset storage UserStorageHandler::getInstance()->reset($followUserIDs, 'followerUserIDs'); UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'followingUserIDs'); return $returnValues; }
/** * @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(); }
/** * Disables given files. */ public function disable() { $checkEntries = $fileIDs = array(); foreach ($this->objects as $file) { if (empty($this->parameters['ignoreEntries']) && !$file->getEntry()->isDisabled) { $checkEntries[] = $file->entryID; } $file->update(array('isDisabled' => 1)); $fileIDs[] = $file->fileID; $this->addFileData($file->getDecoratedObject(), 'isDisabled', 1); // add moderated content ModerationQueueActivationManager::getInstance()->addModeratedContent('de.incendium.filebase.file', $file->fileID); FileModificationLogHandler::getInstance()->disable($file->getDecoratedObject()); } // remove activity events UserActivityEventHandler::getInstance()->removeEvents('de.incendium.filebase.recentActivityEvent.file', $fileIDs); // delete notifications UserNotificationHandler::getInstance()->deleteNotifications('file', 'de.incendium.filebase.file', array(), $fileIDs); if (!empty($checkEntries)) { $checkEntries = array_unique($checkEntries); // rebuild data EntryEditor::rebuildEntryData($checkEntries); // disable entries if necessary $ignoreEntries = array(); $conditionBuilder = new PreparedStatementConditionBuilder(); $conditionBuilder->add('entryID IN (?)', array($checkEntries)); $conditionBuilder->add('isDisabled = ?', array(0)); $conditionBuilder->add('isDeleted = ?', array(0)); $sql = "SELECT\tentryID\n\t\t\t\tFROM\tfilebase" . WCF_N . "_file\n\t\t\t\t" . $conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); while ($row = $statement->fetchArray()) { $ignoreEntries[] = $row['entryID']; } $disableEntries = array_diff($checkEntries, $ignoreEntries); if (!empty($disableEntries)) { $entryAction = new EntryAction($disableEntries, 'disable', array('ignoreFiles' => true)); $entryAction->executeAction(); foreach ($disableEntries as $entryID) { $this->addEntryData($entryID, 'isDisabled', 1); $this->addEntryData($entryID, 'ignoreFiles', 1); } } } $this->unmarkItems(); return $this->getFileData(); }
/** * @see \wcf\data\AbstractDatabaseObjectAction::delete() */ public function delete() { if (empty($this->objects)) { $this->readObjects(); } if (empty($this->objects)) { return 0; } $ignoreCounters = !empty($this->parameters['ignoreCounters']); // read object type ids for comments $commentIDs = array(); foreach ($this->objects as $response) { $commentIDs[] = $response->commentID; } $commentList = new CommentList(); $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs)); $commentList->readObjects(); $comments = $commentList->getObjects(); // update counters $processors = $responseIDs = $updateComments = array(); foreach ($this->objects as $response) { $objectTypeID = $comments[$response->commentID]->objectTypeID; if (!isset($processors[$objectTypeID])) { $objectType = ObjectTypeCache::getInstance()->getObjectType($objectTypeID); $processors[$objectTypeID] = $objectType->getProcessor(); $responseIDs[$objectTypeID] = array(); } $responseIDs[$objectTypeID][] = $response->responseID; if (!$ignoreCounters) { $processors[$objectTypeID]->updateCounter($comments[$response->commentID]->objectID, -1); if (!isset($updateComments[$response->commentID])) { $updateComments[$response->commentID] = 0; } $updateComments[$response->commentID]++; } } // remove responses $count = parent::delete(); // update comment responses and cached response ids if (!$ignoreCounters) { foreach ($comments as $comment) { $commentEditor = new CommentEditor($comment); $commentEditor->updateResponseIDs(); $commentEditor->updateCounters(array('responses' => -1 * $updateComments[$comment->commentID])); } } $likeObjectIDs = array(); $notificationObjectTypes = array(); foreach ($responseIDs as $objectTypeID => $objectIDs) { // remove activity events $objectType = ObjectTypeCache::getInstance()->getObjectType($objectTypeID); if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.recentActivityEvent')) { UserActivityEventHandler::getInstance()->removeEvents($objectType->objectType . '.response.recentActivityEvent', $objectIDs); } // delete notifications if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.notification')) { UserNotificationHandler::getInstance()->removeNotifications($objectType->objectType . '.response.notification', $objectIDs); } $likeObjectIDs = array_merge($likeObjectIDs, $objectIDs); if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.like.notification')) { $notificationObjectTypes[] = $objectType->objectType . '.response.like.notification'; } } // remove likes if (!empty($likeObjectIDs)) { LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment.response', $likeObjectIDs, $notificationObjectTypes); } return $count; }
/** * Adds a response. * * @return array */ public function addResponse() { if (!empty($this->validationErrors)) { if (!empty($this->parameters['data']['username'])) { WCF::getSession()->register('username', $this->parameters['data']['username']); } WCF::getTPL()->assign('errorType', $this->validationErrors); $guestDialog = $this->getGuestDialog(); return array('useCaptcha' => $guestDialog['useCaptcha'], 'guestDialog' => $guestDialog['template']); } // create response $this->createdResponse = CommentResponseEditor::create(array('commentID' => $this->comment->commentID, 'time' => TIME_NOW, 'userID' => WCF::getUser()->userID ?: null, 'username' => WCF::getUser()->userID ? WCF::getUser()->username : $this->parameters['data']['username'], 'message' => $this->parameters['data']['message'])); // update response data $responseIDs = $this->comment->getResponseIDs(); if (count($responseIDs) < 5) { $responseIDs[] = $this->createdResponse->responseID; } $responses = $this->comment->responses + 1; // update comment $commentEditor = new CommentEditor($this->comment); $commentEditor->update(array('responseIDs' => serialize($responseIDs), 'responses' => $responses)); // update counter $this->commentProcessor->updateCounter($this->parameters['data']['objectID'], 1); // fire activity event $objectType = ObjectTypeCache::getInstance()->getObjectType($this->comment->objectTypeID); if ($this->createdResponse->userID && UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.recentActivityEvent')) { UserActivityEventHandler::getInstance()->fireEvent($objectType->objectType . '.response.recentActivityEvent', $this->createdResponse->responseID); } // fire notification event if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.notification')) { $notificationObjectType = UserNotificationHandler::getInstance()->getObjectTypeProcessor($objectType->objectType . '.notification'); $userID = $notificationObjectType->getOwnerID($this->comment->commentID); $notificationObject = new CommentResponseUserNotificationObject($this->createdResponse); if ($this->comment->userID != WCF::getUser()->userID) { UserNotificationHandler::getInstance()->fireEvent('commentResponse', $objectType->objectType . '.response.notification', $notificationObject, array($this->comment->userID), array('commentID' => $this->comment->commentID, 'objectID' => $this->comment->objectID, 'objectUserID' => $userID, 'userID' => $this->comment->userID)); } // notify the container owner if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.notification')) { if ($userID != $this->comment->userID && $userID != WCF::getUser()->userID) { UserNotificationHandler::getInstance()->fireEvent('commentResponseOwner', $objectType->objectType . '.response.notification', $notificationObject, array($userID), array('commentID' => $this->comment->commentID, 'objectID' => $this->comment->objectID, 'objectUserID' => $userID, 'userID' => $this->comment->userID)); } } } if (!$this->createdResponse->userID) { // save user name is session WCF::getSession()->register('username', $this->createdResponse->username); // save last comment time for flood control WCF::getSession()->register('lastCommentTime', $this->createdResponse->time); // reset captcha for future requests if ($this->captchaObjectType) { $this->captchaObjectType->getProcessor()->reset(); } } return array('commentID' => $this->comment->commentID, 'template' => $this->renderResponse($this->createdResponse), 'responses' => $responses); }