/** * Returns the pagegroup requested for history. */ protected function getPageGroupForHistory() { static $oPageGroupForHistory = null, $bInitialized = false; // only initialize first time for performances saving if (!$bInitialized) { $nPageGroupId = (int) AnwEnv::_GET("pagegroup"); if ($nPageGroupId > 0) { $oPageGroupTmp = new AnwPageGroup($nPageGroupId); if ($oPageGroupTmp->exists()) { $oPageGroupForHistory = $oPageGroupTmp; } } } return $oPageGroupForHistory; }
function run() { //find TO revision try { //retrieve pagegroup $nPageGroupId = (int) AnwEnv::_GET("pagegroup", AnwEnv::_POST("pagegroup")); if (!$nPageGroupId) { //special case: we may have passed a pageid (ie: from lastchanges, for better performances avoiding loading pagegroup info) $nPageId = (int) AnwEnv::_GET("page"); if ($nPageId) { $oExistingPageTmp = AnwPage::getLastPageRevision($nPageId); //high queries consuming, not 100% cached... if ($oExistingPageTmp->exists()) { $nPageGroupId = $oExistingPageTmp->getPageGroup()->getId(); } unset($oExistingPageTmp); } if (!$nPageGroupId) { throw new AnwBadCallException(); } } $oPageGroup = new AnwPageGroup($nPageGroupId); if (!$oPageGroup->exists()) { throw new AnwBadCallException("pagegroup not found for revert"); } //get valid changeid $aoPageGroupChangesById = AnwStorage::getLastChanges(false, 0, null, null, null, null, $oPageGroup); $nRevToChangeId = (int) AnwEnv::_GET("revto", AnwEnv::_POST("revto")); //may be null when coming from action_revertpage if (!$nRevToChangeId || !array_key_exists($nRevToChangeId, $aoPageGroupChangesById)) { //get last changeid from this pagegroup $oChangeReference = reset($aoPageGroupChangesById); $nRevToChangeId = $oChangeReference->getChangeId(); } } catch (AnwException $e) { throw new AnwBadCallException(); } $this->setTitle($this->t_("title")); $aaRevertPlan = $this->generateRevertPlan($oPageGroup, $nRevToChangeId); if (AnwEnv::_POST("submit") && $nRevToChangeId > 0) { $this->doRevert($oPageGroup, $aaRevertPlan); } else { $this->showFormRevert($oPageGroup, $aaRevertPlan, $nRevToChangeId); } }
static function createNewPage($oContentClass, $sPageName, $sPageLang, $sChangeComment = "", $oContent = null, $nTime = null) { AnwStorage::transactionStart(); try { //create pagegroup $oPageGroup = new AnwPageGroup(); $oPageGroup->create($oContentClass); //create empty content if none if (!$oContent) { $oContent = new AnwContentPage($oContentClass); } $bSecurityChecks = true; if (!$nTime) { $nTime = time(); } $oNewPage = self::doCreatePage($oPageGroup, $sPageName, $sPageLang, $oContent, -1, $bSecurityChecks, AnwChange::TYPE_PAGE_CREATION, $nTime, $sChangeComment); AnwStorage::transactionCommit(); } catch (AnwException $e) { AnwStorage::transactionRollback(); throw $e; } return $oNewPage; }
private static function getPageGroupFromData($aoDataPageGroup) { $nPageGroupId = $aoDataPageGroup[0]->PageGroupId; $nPageGroupContentClass = $aoDataPageGroup[0]->PageGroupContentClass; $aoPages = array(); foreach ($aoDataPageGroup as $oDataPage) { if ($oDataPage->PageId) { //warning : PageContent may be NULL when using performance+memory boost $oPage = self::getPageFromData($oDataPage); $sPageLang = $oPage->getLang(); $aoPages[$sPageLang] = $oPage; } } $oPageGroup = AnwPageGroup::rebuildPageGroup($nPageGroupId, $nPageGroupContentClass, $aoPages); return $oPageGroup; }
protected static function getCategoriesPages($oContent, $oPage) { $anCategoriesPageGroupIds = $oContent->getContentFieldValues(self::FIELD_CATEGORIES); $aoCategoriesPage = array(); foreach ($anCategoriesPageGroupIds as $nCategoryPageGroupId) { try { $oCategoryPageGroup = new AnwPageGroup($nCategoryPageGroupId, self::NEWS_CLASS); if ($oCategoryPageGroup->exists()) { //get category in current lang if available $oPageNews = $oCategoryPageGroup->getPreferedPage($oPage->getLang()); $aoCategoriesPage[] = $oPageNews; } } catch (AnwException $e) { } } return $aoCategoriesPage; }