/** * @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\cronjob\ICronjob::execute() */ public function execute(Cronjob $cronjob) { // publish pages $sql = "SELECT\tpageID\n\t\t\tFROM\tcms" . WCF_N . "_page\n\t\t\tWHERE\tisPublished = 0\n\t\t\t\tAND publicationDate <= ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(TIME_NOW)); $pageIDs = array(); while ($row = $statement->fetchArray()) { $pageIDs[] = $row['pageID']; } $action = new PageAction($pageIDs, 'publish'); $action->executeAction(); // disable pages $sql = "SELECT\tpageID\n\t\t\tFROM\tcms" . WCF_N . "_page\n\t\t\tWHERE\tisDisabled = 0\n\t\t\t\tAND deactivationDate BETWEEN 1 AND ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(TIME_NOW)); $pageIDs = array(); while ($row = $statement->fetchArray()) { $pageIDs[] = $row['pageID']; } $action = new PageAction($pageIDs, 'disable'); $action->executeAction(); }
/** * @see \wcf\data\AbstractDatabaseObjectAction::update() */ public function update() { // set default values for last editor if (!isset($this->parameters['data']['lastEditorID'])) { $this->parameters['data']['lastEditorID'] = WCF::getUser()->userID; $this->parameters['data']['lastEditorName'] = WCF::getUser()->username; } // set default value for last edit time if (!isset($this->parameters['data']['lastEditTime'])) { $this->parameters['data']['lastEditTime'] = TIME_NOW; } // perform update parent::update(); $pageIDs = $publishedPageIDs = array(); foreach ($this->objects as $pageEditor) { $pageIDs[] = $pageEditor->pageID; // update stylesheets if (isset($this->parameters['stylesheetIDs'])) { $pageEditor->updateStylesheetIDs($this->parameters['stylesheetIDs']); } if (!$pageEditor->isPublished) { $publishedPageIDs[] = $pageEditor->pageID; } } // delete subscriptions if subscribing isn't allowed anymore if (isset($this->parameters['data']['allowSubscribing']) && !$this->parameters['data']['allowSubscribing']) { UserObjectWatchHandler::getInstance()->deleteObjects('de.codequake.cms.page', $pageIDs); } // trigger new publications if (isset($this->parameters['data']['isPublished']) && $this->parameters['data']['isPublished'] == 1 && !empty($publishedPageIDs)) { $action = new PageAction($publishedPageIDs, 'triggerPublication'); $action->executeAction(); } }
/** * @see \wcf\form\IForm::save() */ public function save() { parent::save(); $data = array('title' => $this->title, 'pageID' => $this->pageID, 'parentID' => $this->parentID ?: null, 'cssClasses' => $this->cssClasses, 'showOrder' => $this->showOrder, 'position' => $this->position, 'contentData' => $this->contentData, 'contentTypeID' => $this->objectType->objectTypeID); $this->objectAction = new ContentAction(array(), 'create', array('data' => $data)); $returnValues = $this->objectAction->executeAction(); $contentID = $returnValues['returnValues']->contentID; $contentData = $returnValues['returnValues']->contentData; $update = array(); // save polls if ($this->objectType->objectType == 'de.codequake.cms.content.type.poll') { $pollID = PollManager::getInstance()->save($returnValues['returnValues']->contentID); if ($pollID) { $contentData['pollID'] = $pollID; } } if (!I18nHandler::getInstance()->isPlainValue('title')) { I18nHandler::getInstance()->save('title', 'cms.content.title' . $contentID, 'cms.content', PACKAGE_ID); $update['title'] = 'cms.content.title' . $contentID; } foreach ($this->objectType->getProcessor()->multilingualFields as $field) { if (!I18nHandler::getInstance()->isPlainValue($field)) { I18nHandler::getInstance()->save($field, 'cms.content.' . $field . $contentID, 'cms.content', PACKAGE_ID); $contentData[$field] = 'cms.content.' . $field . $contentID; } } $update['contentData'] = serialize($contentData); if (!empty($update)) { $editor = new ContentEditor($returnValues['returnValues']); $editor->update($update); } // create revision $objectAction = new PageAction(array($this->pageID), 'createRevision', array('action' => 'content.create')); $objectAction->executeAction(); // update search index $objectAction = new PageAction(array($returnValues['returnValues']->pageID), 'refreshSearchIndex'); $objectAction->executeAction(); $this->saved(); HeaderUtil::redirect(LinkHandler::getInstance()->getLink('ContentList', array('application' => 'cms', 'pageID' => $this->pageID))); }
/** * @see \wcf\data\ISortableAction::updatePosition() */ public function updatePosition() { WCF::getDB()->beginTransaction(); $pageIDs = array(); foreach ($this->parameters['data']['structure'] as $parentID => $contentIDs) { $position = 1; foreach ($contentIDs as $contentID) { if (!in_array($this->objects[$contentID]->pageID, $pageIDs)) { $pageIDs[] = $this->objects[$contentID]->pageID; } $this->objects[$contentID]->update(array('parentID' => $parentID != 0 ? $this->objects[$parentID]->contentID : null, 'showOrder' => $position++)); } } WCF::getDB()->commitTransaction(); // create revision $pageAction = new PageAction($pageIDs, 'createRevision', array('action' => 'content.updatePosition')); $pageAction->executeAction(); }
/** * Restores a specific revision. */ public function restore() { // get available languages $availableLanguages = LanguageFactory::getInstance()->getLanguages(); $revision = $this->getSingleObject(); WCF::getDB()->beginTransaction(); $pageData = base64_decode($revision->data); $pageData = @unserialize($pageData); $i18nfields = array(); // save i18n foreach ($pageData as $key => $data) { if (($key == 'title' || $key == 'description' || $key == 'metaDescription' || $key == 'metaKeywords') && is_array($data)) { $langData = array(); foreach ($availableLanguages as $lang) { if (isset($data[$lang->countryCode])) { $langData[$lang->languageID] = $data[$lang->countryCode]; } else { $langData[$lang->languageID] = ''; } } I18nHandler::getInstance()->setValues($key, $langData); $i18nfields[] = $key; $pageData[$key] = ''; } } // restore page $pageAction = new PageAction(array($revision->pageID), 'update', array('data' => $pageData)); $pageAction->executeAction(); // save i18n foreach ($pageData as $key => $data) { if (($key == 'title' || $key == 'description' || $key == 'metaDescription' || $key == 'metaKeywords') && in_array($key, $i18nfields)) { $this->saveI18nValue(new Page($revision->pageID), 'page', $key); } } // restore contents $contentData = base64_decode($revision->contentData); $contentData = @unserialize($contentData); $contentList = new ContentList(); $contentList->getConditionBuilder()->add('content.pageID = ?', array($revision->pageID)); $contentList->readObjects(); $existingContentIDs = $contentList->getObjectIDs(); $oldContents = array(); foreach ($contentData as $data) { $oldContents[$data['contentID']] = $data; } // delete contents that where created after the revision $orphanedElementIDs = array_diff($existingContentIDs, array_keys($oldContents)); if (!empty($orphanedElementIDs)) { $contentAction = new ContentAction($orphanedElementIDs, 'delete'); $contentAction->executeAction(); } foreach ($oldContents as $oldContent) { $objectType = ObjectTypeCache::getInstance()->getObjectType($oldContent['contentTypeID']); if (in_array($oldContent['contentID'], $existingContentIDs)) { // content this exists => update $i18ntitle = false; if (is_array($oldContent['title'])) { $langData = array(); foreach ($availableLanguages as $lang) { if (isset($oldContent['title'][$lang->countryCode])) { $langData[$lang->languageID] = $oldContent['title'][$lang->countryCode]; } else { $langData[$lang->languageID] = ''; } } I18nHandler::getInstance()->setValues($key, $langData); $i18ntitle = true; $oldContent['title'] = ''; } $i18nfields = array(); foreach ($objectType->getProcessor()->multilingualFields as $field) { if (isset($oldContent['contentData'][$field]) && is_array($oldContent['contentData'][$field])) { $langData = array(); foreach ($availableLanguages as $lang) { if (isset($oldContent['contentData'][$field][$lang->countryCode])) { $langData[$lang->languageID] = $oldContent['contentData'][$field][$lang->countryCode]; } else { $langData[$lang->languageID] = ''; } } I18nHandler::getInstance()->setValues($field, $langData); $i18nfields[] = $field; $oldContent['contentData'][$field] = ''; } } $contentAction = new ContentAction(array($oldContent['contentID']), 'update', array('data' => $oldContent)); $contentAction->executeAction(); if ($i18ntitle) { $this->saveI18nValue(new Content($oldContent['contentID']), 'content', 'title'); } foreach ($objectType->getProcessor()->multilingualFields as $field) { if (in_array($field, $i18nfields)) { $this->saveI18nValue(new Content($oldContent['contentID']), 'content', $field, true); } } } else { // content was deleted => re-create $i18ntitle = false; if (is_array($oldContent['title'])) { $langData = array(); foreach ($availableLanguages as $lang) { if (isset($oldContent['title'][$lang->countryCode])) { $langData[$lang->languageID] = $oldContent['title'][$lang->countryCode]; } else { $langData[$lang->languageID] = ''; } } I18nHandler::getInstance()->setValues($field, $langData); $i18ntitle = true; $oldContent['title'] = ''; } $i18nfields = array(); foreach ($objectType->getProcessor()->multilingualFields as $field) { if (isset($oldContent['contentData'][$field])) { $langData = array(); foreach ($availableLanguages as $lang) { if (isset($oldContent['contentData'][$field][$lang->countryCode])) { $langData[$lang->languageID] = $oldContent['contentData'][$field][$lang->countryCode]; } else { $langData[$lang->languageID] = ''; } } I18nHandler::getInstance()->setValues($key, $langData); $i18nfields[] = $field; $oldContent['contentData'][$field] = ''; } } $contentAction = new ContentAction(array($oldContent['contentID']), 'create', array('data' => $oldContent)); $contentAction->executeAction(); if ($i18ntitle) { $this->saveI18nValue(new Content($oldContent['contentID']), 'content', 'title'); } foreach ($objectType->getProcessor()->multilingualFields as $field) { if (in_array($field, $i18nfields)) { $this->saveI18nValue(new Content($oldContent['contentID']), 'content', $field, true); } } } } WCF::getDB()->commitTransaction(); }
/** * @see \wcf\form\IForm::save() */ public function save() { parent::save(); $data = array('title' => $this->title, 'alias' => $this->alias, 'description' => $this->description, 'metaDescription' => $this->metaDescription, 'metaKeywords' => $this->metaKeywords, 'allowIndexing' => $this->allowIndexing, 'parentID' => $this->parentID ?: null, 'showOrder' => $this->showOrder, 'invisible' => $this->invisible, 'menuItemID' => $this->menuItemID ?: null, 'isCommentable' => $this->isCommentable, 'availableDuringOfflineMode' => $this->availableDuringOfflineMode, 'allowSubscribing' => $this->allowSubscribing, 'styleID' => $this->styleID ?: null, 'sidebarOrientation' => $this->sidebarOrientation); // publication if ($this->enableDelayedPublication) { $data['isPublished'] = 0; $dateTime = \DateTime::createFromFormat('Y-m-d H:i', $this->publicationDate, WCF::getUser()->getTimeZone()); $data['publicationDate'] = $dateTime->getTimestamp(); } if ($this->enableDelayedDeactivation) { $dateTime = \DateTime::createFromFormat('Y-m-d H:i', $this->deactivationDate, WCF::getUser()->getTimeZone()); $data['deactivationDate'] = $dateTime->getTimestamp(); } $pageData = array('data' => $data, 'stylesheetIDs' => $this->stylesheetIDs); $this->objectAction = new PageAction(array(), 'create', $pageData); $returnValues = $this->objectAction->executeAction(); $pageEditor = new PageEditor($returnValues['returnValues']); $updateData = array(); // save ACL ACLHandler::getInstance()->save($pageEditor->pageID, $this->objectTypeID); // save multilingual inputs if (!I18nHandler::getInstance()->isPlainValue('title')) { $updateData['title'] = 'cms.page.title' . $pageEditor->pageID; I18nHandler::getInstance()->save('title', $updateData['title'], 'cms.page'); } if (!I18nHandler::getInstance()->isPlainValue('description')) { $updateData['description'] = 'cms.page.description' . $pageEditor->pageID; I18nHandler::getInstance()->save('description', $updateData['description'], 'cms.page'); } if (!I18nHandler::getInstance()->isPlainValue('metaDescription')) { $updateData['metaDescription'] = 'cms.page.metaDescription' . $pageEditor->pageID; I18nHandler::getInstance()->save('metaDescription', $updateData['metaDescription'], 'cms.page'); } if (!I18nHandler::getInstance()->isPlainValue('metaKeywords')) { $updateData['metaKeywords'] = 'cms.page.metaKeywords' . $pageEditor->pageID; I18nHandler::getInstance()->save('metaKeywords', $updateData['metaKeywords'], 'cms.page'); } // create menu item for page if ($this->createMenuItem) { // set menu item of parent page as parent menu item if ($pageEditor->getParentPage() !== null && $pageEditor->getParentPage()->menuItemID) { $parentMenuItem = new PageMenuItem($pageEditor->getParentPage()->menuItemID); } $menuItemData = array('className' => 'cms\\system\\menu\\page\\CMSPageMenuItemProvider', 'menuItemController' => 'cms\\page\\PagePage', 'menuItemLink' => 'id=' . $pageEditor->pageID, 'menuPosition' => 'header', 'packageID' => PACKAGE_ID, 'parentMenuItem' => isset($parentMenuItem) && $parentMenuItem->menuItemID ? $parentMenuItem->menuItem : '', 'showOrder' => 0); $menuItemAction = new PageMenuItemAction(array(), 'create', array('data' => $menuItemData)); $menuItemReturnValues = $menuItemAction->executeAction(); $menuItem = $menuItemReturnValues['returnValues']; // save multilingual title I18nHandler::getInstance()->register('menuItemTitle'); I18nHandler::getInstance()->setValues('menuItemTitle', I18nHandler::getInstance()->getValues('title')); $menuItemData = array('menuItem' => 'wcf.page.menuItem' . $menuItem->menuItemID); I18nHandler::getInstance()->save('menuItemTitle', $menuItemData['menuItem'], 'wcf.page'); $menuItemEditor = new PageMenuItemEditor($menuItem); $menuItemEditor->update($menuItemData); // save menu item with page $updateData['menuItemID'] = $menuItem->menuItemID; } // save new information $pageEditor->update($updateData); // create revision $objectAction = new PageAction(array($pageEditor->pageID), 'createRevision', array('action' => 'create')); $objectAction->executeAction(); // update search index $objectAction = new PageAction(array($pageEditor->pageID), 'refreshSearchIndex'); $objectAction->executeAction(); $this->saved(); WCF::getTPL()->assign('success', true); // reset values $this->alias = $this->deactivationDate = $this->description = $this->metaDescription = $this->metaKeywords = $this->publicationDate = ''; $this->enableDelayedDeactivation = $this->enableDelayedPublication = $this->invisible = $this->menuItemID = $this->parentID = $this->showOrder = $this->styleID = 0; $this->stylesheetIDs = array(); $this->allowIndexing = CMS_PAGES_DEFAULT_ALLOW_INDEXING; $this->allowSubscribing = CMS_PAGES_DEFAULT_ALLOW_SUBSCRIBING; $this->availableDuringOfflineMode = CMS_PAGES_DEFAULT_OFFLINE; $this->createMenuItem = CMS_PAGES_DEFAULT_MENU_ITEM; $this->isCommentable = CMS_PAGES_DEFAULT_COMMENTS; $this->sidebarOrientation = CMS_PAGES_DEFAULT_SIDEBAR; I18nHandler::getInstance()->reset(); ACLHandler::getInstance()->disableAssignVariables(); }
/** * @see \wcf\form\IForm::save() */ public function save() { AbstractForm::save(); // save multilingual inputs $languageVariable = 'cms.page.title' . $this->pageID; if (I18nHandler::getInstance()->isPlainValue('title')) { I18nHandler::getInstance()->remove($languageVariable); } else { I18nHandler::getInstance()->save('title', $languageVariable, 'cms.page'); $this->title = $languageVariable; } $languageVariable = 'cms.page.description' . $this->pageID; if (I18nHandler::getInstance()->isPlainValue('description')) { I18nHandler::getInstance()->remove($languageVariable); } else { I18nHandler::getInstance()->save('description', $languageVariable, 'cms.page'); $this->description = $languageVariable; } $languageVariable = 'cms.page.metaDescription' . $this->pageID; if (I18nHandler::getInstance()->isPlainValue('metaDescription')) { I18nHandler::getInstance()->remove($languageVariable); } else { I18nHandler::getInstance()->save('metaDescription', $languageVariable, 'cms.page'); $this->metaDescription = $languageVariable; } $languageVariable = 'cms.page.metaKeywords' . $this->pageID; if (I18nHandler::getInstance()->isPlainValue('metaKeywords')) { I18nHandler::getInstance()->remove($languageVariable); } else { I18nHandler::getInstance()->save('metaKeywords', $languageVariable, 'cms.page'); $this->metaKeywords = $languageVariable; } $data = array('title' => $this->title, 'alias' => $this->alias, 'description' => $this->description, 'metaDescription' => $this->metaDescription, 'metaKeywords' => $this->metaKeywords, 'allowIndexing' => $this->allowIndexing, 'parentID' => $this->parentID ?: null, 'showOrder' => $this->showOrder, 'invisible' => $this->invisible, 'menuItemID' => $this->menuItemID ?: null, 'isCommentable' => $this->isCommentable, 'availableDuringOfflineMode' => $this->availableDuringOfflineMode, 'allowSubscribing' => $this->allowSubscribing, 'styleID' => $this->styleID ?: null, 'sidebarOrientation' => $this->sidebarOrientation); // publication if ($this->enableDelayedPublication) { $data['isPublished'] = 0; $data['publicationDate'] = @strtotime($this->publicationDate); } else { $data['isPublished'] = 1; } if ($this->enableDelayedDeactivation) { $data['isDisabled'] = 0; $data['deactivationDate'] = @strtotime($this->publicationDate); } $pageData = array('data' => $data, 'stylesheetIDs' => $this->stylesheetIDs); $this->objectAction = new PageAction(array($this->pageID), 'update', $pageData); $this->objectAction->executeAction(); // save ACL ACLHandler::getInstance()->save($this->pageID, $this->objectTypeID); // create revision $objectAction = new PageAction(array($this->pageID), 'createRevision', array('action' => 'update')); $objectAction->executeAction(); // update search index $objectAction = new PageAction(array($this->pageID), 'refreshSearchIndex'); $objectAction->executeAction(); $this->saved(); WCF::getTPL()->assign('success', true); }
/** * @see \wcf\form\IForm::save() */ public function save() { AbstractForm::save(); if ($this->objectType->objectType == 'de.codequake.cms.content.type.poll') { $this->contentData['pollID'] = PollManager::getInstance()->save($this->contentID); } // save multilingual inputs $languageVariable = 'cms.content.title' . $this->contentID; if (I18nHandler::getInstance()->isPlainValue('title')) { I18nHandler::getInstance()->remove($languageVariable); } else { I18nHandler::getInstance()->save('title', $languageVariable, 'cms.content', PACKAGE_ID); $this->title = $languageVariable; } foreach ($this->objectType->getProcessor()->multilingualFields as $field) { $languageVariable = 'cms.content.' . $field . $this->contentID; if (I18nHandler::getInstance()->isPlainValue($field)) { I18nHandler::getInstance()->remove($languageVariable); } else { I18nHandler::getInstance()->save($field, $languageVariable, 'cms.content', PACKAGE_ID); $this->contentData[$field] = $languageVariable; } } $data = array('title' => $this->title, 'pageID' => $this->pageID, 'parentID' => $this->parentID ?: null, 'cssClasses' => $this->cssClasses, 'showOrder' => $this->showOrder, 'position' => $this->position, 'contentData' => $this->contentData, 'contentTypeID' => $this->objectType->objectTypeID); $this->objectAction = new ContentAction(array($this->contentID), 'update', array('data' => $data)); $this->objectAction->executeAction(); // create revision if ($this->pageID == $this->content->pageID) { $objectAction = new PageAction(array($this->pageID), 'createRevision', array('action' => 'content.update')); $objectAction->executeAction(); } else { $objectAction = new PageAction(array($this->pageID), 'createRevision', array('action' => 'content.create')); $objectAction->executeAction(); $objectAction = new PageAction(array($this->content->pageID), 'createRevision', array('action' => 'content.delete')); $objectAction->executeAction(); } // update search index $objectAction = new PageAction(array($this->pageID), 'refreshSearchIndex'); $objectAction->executeAction(); $this->saved(); HeaderUtil::redirect(LinkHandler::getInstance()->getLink('ContentList', array('application' => 'cms', 'pageID' => $this->pageID))); }