/** * @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.incendium.cms.news.activityPointEvent.entry'); // remove the entry from search index SearchIndexManager::getInstance()->reset('de.incendium.cms.news.entry'); } // get news attachments $attachmentObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'de.incendium.cms.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.incendium.cms.like.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 $entry) { // new EntryEditor $editor = new EntryEditor($entry); // update search index SearchIndexManager::getInstance()->add('de.incendium.cms.news.entry', $entry->entryID, $entry->message, $entry->subject, $entry->time, $entry->userID, $entry->username, $entry->languageID); // news data $newsData = array(); // likes $newsData['cumulativeLikes'] = isset($likes[$entry->entryID]) ? $likes[$entry->entryID] : 0; // attachments $attachments->execute(array($attachmentObjectType->objectTypeID, $entry->entryID)); $row = $attachments->fetchArray(); $newsData['attachments'] = $row['attachments']; if ($entry->userID) { if (!isset($userItems[$entry->userID])) { $userItems[$entry->userID] = 0; } $userItems[$entry->userID]++; } $editor->update($newsData); } // update activity points UserActivityPointHandler::getInstance()->fireEvents('de.incendium.cms.news.activityPointEvent.entry', $userItems, false); }
/** * @see \wcf\data\like\object\ILikeObject::updateLikeCounter() */ public function updateLikeCounter($cumulativeLikes) { // update cumulative likes $entryEditor = new EntryEditor($this->getDecoratedObject()); $entryEditor->update(array('cumulativeLikes' => $cumulativeLikes)); }
/** * @see \wcf\form\IForm::save() */ public function save() { MessageForm::save(); // save the news entry $data = array('subject' => $this->subject, 'message' => $this->text, 'languageID' => $this->languageID, 'enableBBCodes' => $this->enableBBCodes, 'enableHtml' => $this->enableHtml, 'enableSmilies' => $this->enableSmilies, 'isFeatured' => $this->isFeatured); // delayed publication if ($this->enableDelayedPublication) { $data['isPublished'] = 0; $dateTime = \DateTime::createFromFormat('Y-m-d H:i', $this->publicationDate, WCF::getUser()->getTimeZone()); $data['publicationDate'] = $dateTime->getTimestamp(); } else { $data['isPublished'] = 1; $data['publicationDate'] = 0; } if (WCF::getSession()->getPermission('user.news.canEditEntryDate')) { $data['time'] = $this->entryDateObj->getTimestamp(); } $entryData = array('attachmentHandler' => $this->attachmentHandler, 'categoryIDs' => $this->categoryIDs, 'isEdit' => true, 'editReason' => $this->editReason, 'data' => $data); if (MODULE_TAGGING) { $entryData['tags'] = $this->tags; } // save poll if ($this->canCreatePoll()) { $pollID = PollManager::getInstance()->save($this->entry->entryID); if ($pollID) { $entryEditor = new EntryEditor($this->entry); $entryEditor->update(array('pollID' => $pollID)); } } $this->objectAction = new EntryAction(array($this->entry), 'update', $entryData); $this->objectAction->executeAction(); $this->saved(); HeaderUtil::redirect(LinkHandler::getInstance()->getLink('NewsEntry', array('application' => 'cms', 'object' => $this->entry))); exit; }
/** * @see \wcf\system\comment\manager\ICommentManager::updateCounter() */ public function updateCounter($objectID, $value) { $entry = new Entry($objectID); $editor = new EntryEditor($entry); // update counter for news comments $editor->updateCounters(array('comments' => $value)); }
/** * @see \wcf\form\IForm::save() */ public function save() { parent::save(); $data = array('subject' => $this->subject, 'time' => TIME_NOW, 'message' => $this->text, 'userID' => WCF::getUser()->userID ?: null, 'username' => WCF::getUser()->userID ? WCF::getUser()->username : $this->username, 'languageID' => $this->languageID, 'enableBBCodes' => $this->enableBBCodes, 'enableHtml' => $this->enableHtml, 'enableSmilies' => $this->enableSmilies, 'isDisabled' => WCF::getSession()->getPermission('user.news.canCreateEntryWithoutModeration') ? 0 : 1, 'isDeleted' => 0, 'isFeatured' => $this->isFeatured, 'views' => 0); // delayed publication if ($this->enableDelayedPublication) { $data['isPublished'] = 0; $dateTime = \DateTime::createFromFormat('Y-m-d H:i', $this->publicationDate, WCF::getUser()->getTimeZone()); $data['publicationDate'] = $dateTime->getTimestamp(); } $entryData = array('attachmentHandler' => $this->attachmentHandler, 'categoryIDs' => $this->categoryIDs, 'data' => $data); if (MODULE_TAGGING) { $entryData['tags'] = $this->tags; } $this->objectAction = new EntryAction(array(), 'create', $entryData); $resultValues = $this->objectAction->executeAction(); $this->entry = $resultValues['returnValues']; // quotes MessageQuoteManager::getInstance()->saved(); // polls if ($this->canCreatePoll()) { $pollID = PollManager::getInstance()->save($this->entry->entryID); if ($pollID) { $entryEditor = new EntryEditor($this->entry); $entryEditor->update(array('pollID' => $pollID)); } } $this->saved(); if ($this->entry->isDisabled) { HeaderUtil::delayedRedirect(LinkHandler::getInstance()->getLink('NewsOverview', array('application' => 'cms')), WCF::getLanguage()->get('cms.news.form.moderation.redirect'), 30); } else { HeaderUtil::redirect(LinkHandler::getInstance()->getLink('NewsEntry', array('application' => 'cms', 'object' => $this->entry))); } exit; }
/** * @see \wcf\data\AbstractDatabaseObjectAction::create() */ public function create() { // create entry $data = $this->parameters['data']; // count attachments if (isset($this->parameters['attachmentHandler']) && $this->parameters['attachmentHandler'] !== null) { $data['attachments'] = count($this->parameters['attachmentHandler']); } // handle ip address if (LOG_IP_ADDRESS) { // add ip address if (!isset($data['ipAddress'])) { $data['ipAddress'] = WCF::getSession()->ipAddress; } } else { // do not track ip address if (isset($data['ipAddress'])) { unset($data['ipAddress']); } } $entry = call_user_func(array($this->className, 'create'), $data); $entryEditor = new EntryEditor($entry); // handle categories $entryEditor->updateCategoryIDs($this->parameters['categoryIDs']); $entryEditor->setCategoryIDs($this->parameters['categoryIDs']); // update search index SearchIndexManager::getInstance()->add('de.incendium.cms.news.entry', $entry->entryID, $entry->message, $entry->subject, $entry->time, $entry->userID, $entry->username, $entry->languageID); // update attachments if (isset($this->parameters['attachmentHandler']) && $this->parameters['attachmentHandler'] !== null) { $this->parameters['attachmentHandler']->updateObjectID($entry->entryID); } // save embedded objects if (MessageEmbeddedObjectManager::getInstance()->registerObjects('de.incendium.cms.news.entry', $entry->entryID, $entry->message)) { $entryEditor->update(array('hasEmbeddedObjects' => 1)); } // set language id (cannot be zero) $languageID = !isset($this->parameters['data']['languageID']) || $this->parameters['data']['languageID'] === null ? LanguageFactory::getInstance()->getDefaultLanguageID() : $this->parameters['data']['languageID']; // save tags if (!empty($this->parameters['tags'])) { TagEngine::getInstance()->addObjectTags('de.incendium.cms.news.entry', $entry->entryID, $this->parameters['tags'], $languageID); } if (!$entry->isDisabled && $entry->isPublished) { $action = new EntryAction(array($entryEditor), 'triggerPublication'); $action->executeAction(); } // mark entry for moderated content if ($entry->isDisabled) { ModerationQueueActivationManager::getInstance()->addModeratedContent('de.incendium.cms.news.entry', $entry->entryID); } return $entry; }