/**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     parent::execute();
     if (!$this->loopCount) {
         // reset activity points
         UserActivityPointHandler::getInstance()->reset('de.incendium.filebase.activityPointEvent.entry');
         // reset search index
         SearchIndexManager::getInstance()->reset('de.incendium.filebase.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.filebase.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.filebase.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.filebase.entry', $entry->entryID, $entry->message, $entry->subject, $entry->time, $entry->userID, $entry->username, $entry->languageID);
     }
     // update activity points
     UserActivityPointHandler::getInstance()->fireEvents('de.incendium.filebase.activityPointEvent.entry', $itemsToUser, false);
 }
 /**
  * @see	\wcf\data\AbstractDatabaseObjectAction::create()
  */
 public function create()
 {
     $data = $this->parameters['data'];
     if (!isset($data['lastChangeTime'])) {
         $data['lastChangeTime'] = $data['time'];
     }
     // count attachments
     if (isset($this->parameters['attachmentHandler']) && $this->parameters['attachmentHandler'] !== null) {
         $data['attachments'] = count($this->parameters['attachmentHandler']);
         if ($data['attachments']) {
             $attachments = $this->parameters['attachmentHandler']->getAttachmentList()->getObjects();
             $attachment = reset($attachments);
             $data['coverID'] = $attachment->attachmentID;
         }
     }
     // 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']);
         }
     }
     // save entry
     $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']);
     // add entry file
     $fileData['entryID'] = $entry->entryID;
     $fileData['isDisabled'] = $entry->isDisabled;
     $fileData['subject'] = $this->parameters['fileSubject'];
     $action = new EntryFileAction(array(), 'create', array('data' => $fileData, 'entry' => $entry, 'isFirstFile' => true, 'fileUpload' => $this->parameters['fileUpload']));
     $resultValues = $action->executeAction();
     // update last file id
     $entryEditor->update(array('lastFileID' => $resultValues['returnValues']->fileID));
     // update search index
     SearchIndexManager::getInstance()->add('de.incendium.filebase.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);
     }
     // 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.filebase.entry', $entry->entryID, $this->parameters['tags'], $languageID);
     }
     // trigger publication
     if (!$entry->isDisabled) {
         $action = new EntryAction(array($entryEditor), 'triggerPublication');
         $action->executeAction();
     }
     return $entry;
 }
 /**
  * @see	\wcf\data\like\object\ILikeObject::updateLikeCounter()
  */
 public function updateLikeCounter($cumulativeLikes)
 {
     // update cumulative likes
     $editor = new EntryEditor($this->getDecoratedObject());
     $editor->update(array('cumulativeLikes' => $cumulativeLikes));
 }
 /**
  * Restores given files.
  */
 public function restore()
 {
     // update entries
     $fileIDs = $entryIDs = array();
     foreach ($this->objects as $file) {
         // ignore files already restored
         if (!$file->isDeleted) {
             continue;
         }
         $parameters = array();
         $entryEditor = new EntryEditor($file->getEntry());
         $entryIDs[] = $file->entryID;
         $fileIDs[] = $file->fileID;
         // restore entry if at least one file is accessible
         if ($entryEditor->isDeleted) {
             $parameters['deleteTime'] = 0;
             $parameters['isDeleted'] = 0;
             EntryModificationLogHandler::getInstance()->restore($file->getEntry());
             $this->addEntryData($entryEditor->entryID, 'isDeleted', 0);
             $this->addEntryData($entryEditor->entryID, 'ignoreFiles', 1);
         }
         // update entry
         if (!empty($parameters)) {
             $entryEditor->update($parameters);
         }
         // restore file
         $file->update(array('deleteTime' => 0, 'isDeleted' => 0));
         FileModificationLogHandler::getInstance()->restore($file->getDecoratedObject());
         if (isset($this->parameters['unmarkItems'])) {
             $fileIDs[] = $file->fileID;
         }
         $this->addFileData($file->getDecoratedObject(), 'isDeleted', 0);
     }
     if (!empty($entryIDs)) {
         $entryIDs = array_unique($entryIDs);
         EntryEditor::rebuildEntryData($entryIDs);
     }
     if (!empty($fileIDs)) {
         $this->unmarkItems($fileIDs);
     }
     return $this->getFileData();
 }