private function doRevert($oPageGroup, $aaRevertPlan) { $nTime = time(); // simulation $aoAllFutureContents = array(); foreach ($aaRevertPlan['REVERT'] as $aoRevertPages) { $oPageCurrent = $aoRevertPages[0]; $oPageForRevert = $aoRevertPages[1]; if (isset($aoAllFutureContents[$oPageForRevert->getLang()])) { throw new AnwUnexpectedException("already have a content for this lang"); } $aoAllFutureContents[$oPageForRevert->getLang()] = $oPageForRevert->getContent(); } foreach ($aaRevertPlan['RESTORE'] as $oPageForRestore) { if (isset($aoAllFutureContents[$oPageForRestore->getLang()])) { throw new AnwUnexpectedException("already have a content for this lang"); } $aoAllFutureContents[$oPageForRestore->getLang()] = $oPageForRestore->getContent(); } foreach ($aaRevertPlan['KEEP'] as $oPageKept) { if (isset($aoAllFutureContents[$oPageKept->getLang()])) { throw new AnwUnexpectedException("already have a content for this lang"); } $aoAllFutureContents[$oPageKept->getLang()] = $oPageKept->getContent(); } // make sure that everything is in order... (or throws an exception) AnwPage::checkSimilarContents($aoAllFutureContents); // now, apply changes AnwStorage::transactionStart(); try { //important, firstly delete pages which needs it, to avoid conflicts when reverting or creating pages foreach ($aaRevertPlan['DELETE'] as $oPageForDelete) { $sChangeComment = "delete for revert"; $oPageForDelete->delete($nTime, $sChangeComment); } foreach ($aaRevertPlan['REVERT'] as $aoRevertPages) { $oPageCurrent = $aoRevertPages[0]; $oPageForRevert = $aoRevertPages[1]; $sChangeComment = "revert to old revision"; $oPageCurrent->revertToRevision($oPageForRevert, $nTime, $sChangeComment); } foreach ($aaRevertPlan['RESTORE'] as $oPageForRestore) { $sChangeComment = "restore for revert"; $oPageForRestore->restoreArchive($nTime, $sChangeComment); } AnwStorage::transactionCommit(); } catch (AnwException $e) { AnwStorage::transactionRollback(); throw $e; } // redirect to reverted page if possible $oPageGroup->refresh(); if (count($oPageGroup->getPages()) > 0) { $oPageRedirect = $oPageGroup->getPreferedPage(); AnwUtils::redirect(AnwUtils::link($oPageRedirect)); } else { // no page available, go home AnwUtils::redirect(); } }
private function saveTranslation() { try { $asAvailableLangs = $this->getoPage()->getPageGroup()->getAvailableLangs(); //check permissions : translate foreach ($asAvailableLangs as $sLang) { if (AnwEnv::_POST($this->getChkName($sLang))) { $sTranslationName = AnwEnv::_POST($this->getInputName($sLang), ""); if (!AnwCurrentSession::isActionAllowed($sTranslationName, 'translate', $sLang)) { throw new AnwAclException("permission translate denied"); } } } $oPageTranslation = null; AnwStorage::transactionStart(); try { foreach ($asAvailableLangs as $sLang) { if (AnwEnv::_POST($this->getChkName($sLang))) { $sTranslationName = AnwEnv::_POST($this->getInputName($sLang), ""); //create translation $oPageTranslation = $this->getoPage()->createNewTranslation($sTranslationName, $sLang); } } AnwStorage::transactionCommit(); } catch (AnwException $e) { AnwStorage::transactionRollback(); throw $e; } if ($oPageTranslation) { // redirect to last created translation AnwUtils::redirect(AnwUtils::link($oPageTranslation)); } else { // no translation was created, show form again $this->showForm(); } } catch (AnwBadPageNameException $e) { $this->showForm($this->g_("err_badpagename")); } catch (AnwBadLangException $e) { $this->showForm($this->g_("err_badlang")); } catch (AnwPageAlreadyExistsException $e) { $this->showForm($this->g_("err_pagealreadyexists")); } catch (AnwAclException $e) { $this->showForm($this->g_("err_nopermission")); } catch (AnwLangExistsForPageGroupException $e) { $this->showForm($this->g_("err_langexistsforpagegroup")); } }
function deletePages($nTime = null) { if (!$nTime) { $nTime = time(); } $aoPages = $this->getPages(); AnwStorage::transactionStart(); try { foreach ($aoPages as $oPage) { $oPage->delete($nTime); } AnwStorage::transactionCommit(); } catch (AnwException $e) { AnwStorage::transactionRollback(); throw $e; } }
protected function runInitialization() { AnwStorage::transactionStart(); try { $sInitializationLog = $this->getComponentToInitialize()->initializeComponent(); if (!$this->getComponentToInitialize()->isComponentInitialized()) { throw new AnwUnexpectedException("Component is still not initialized!"); } //run additional initialization $sInitializationLog .= $this->initializeAdditional(); $this->out .= $this->tpl()->showInitResult($this->linkStepNext(), $sInitializationLog); AnwStorage::transactionCommit(); //update step status $this->getActionInstall()->updateStepStatusNext(); } catch (AnwComponentInitializeException $e) { $this->showInitializationConfirm($e->getMessage()); } catch (AnwException $e) { AnwStorage::transactionRollback(); throw $e; } }
private function createPageProcess($sLang, $sContentClass) { $sPageName = $this->getPageName(); if (!AnwCurrentSession::isActionAllowed($sPageName, 'create', $sLang)) { throw new AnwAclException("permission create denied"); } $oContentClass = AnwContentClasses::getContentClass($sContentClass); AnwStorage::transactionStart(); try { //create page $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sLang); //should we create translations for this new page? $asAvailableLangs = $oPage->getPageGroup()->getAvailableLangs(); //check permissions : translate foreach ($asAvailableLangs as $sLang) { if (AnwEnv::_POST($this->getChkName($sLang))) { $sTranslationName = AnwEnv::_POST($this->getInputName($sLang), ""); if (!AnwCurrentSession::isActionAllowed($sTranslationName, 'translate', $sLang)) { throw new AnwAclException("permission translate denied"); } } } foreach ($asAvailableLangs as $sLang) { if (AnwEnv::_POST($this->getChkName($sLang))) { $sTranslationName = AnwEnv::_POST($this->getInputName($sLang), ""); //create translation $oPageTranslation = $oPage->createNewTranslation($sTranslationName, $sLang); } } AnwStorage::transactionCommit(); } catch (AnwException $e) { AnwStorage::transactionRollback(); throw $e; } AnwUtils::redirect(AnwUtils::link($oPage, "edit")); }
/** * Import selected files. * */ private function doImport($sUploadedFile, $asSelectedPages, $bContinueOnErrors) { // we will display the import result after running the whole import // that's why we save the output in a temporary buffer during this process $sOutBuffer = ""; //load XML from file $aaData = $this->getDataFromXmlFile(self::tmpFilename($sUploadedFile)); //delete tmp file AnwUtils::unlink(self::tmpFilename($sUploadedFile), ANWPATH_TMP); $nCountImportErrors = 0; $nCountImportSuccess = 0; $bMustRollback = false; // only when $bContinueOnErrors = false // MAIN TRANSACTION - only when $bContinueOnErrors = false if ($bContinueOnErrors) { // won't revert whole import if errors $bMainTransaction = false; // will commit immediately each imported content $bSubTransaction = true; } else { // will revert whole import if errors $bMainTransaction = true; // won't commit immediately each imported content $bSubTransaction = false; } if ($bMainTransaction) { AnwStorage::transactionStart(); } try { foreach ($aaData['PAGEGROUPS'] as $aaDataGroup) { $sOutBuffer .= $this->tpl()->rowGroupOpen(); $oFirstPage = null; $oContentClass = AnwContentClasses::getContentClass($aaDataGroup['CONTENTCLASS']); foreach ($aaDataGroup['PAGES'] as $aaDataPage) { $asNotices = array(); $sOriginalPageName = $aaDataPage['NAME']; $sPageName = AnwEnv::_POST($this->getInputPageName($sOriginalPageName)); $sPageLang = AnwEnv::_POST($this->getInputPageLang($sOriginalPageName)); if (!$sPageName || !$sPageLang) { throw new AnwUnexpectedException("PageName or PageLang not found for imported content: " . $sOriginalPageName); } $sPageContent = $aaDataPage['CONTENT']; //do we want to import this page? if (in_array($sOriginalPageName, $asSelectedPages) && $sPageName && $sPageLang) { //check pagename and content $asNotices = $this->checkPermissions($sPageName, $sPageLang, $sPageContent); if (count($asNotices) == 0) { // SUB TRANSACTION - only when $bContinueOnErrors = true if ($bSubTransaction) { AnwStorage::transactionStart(); } try { // create the new page $oContent = $oContentClass->rebuildContentFromXml($sPageContent); if (!$oFirstPage) { $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sPageLang, "", $oContent); } else { $oPage = $oFirstPage->createNewTranslation($sPageName, $sPageLang, "", $oContent); } if ($bSubTransaction) { AnwStorage::transactionCommit(); } // wait for everything to be completed before affecting $oFirstPage, in case of it fails if (!$oFirstPage) { $oFirstPage = $oPage; } } catch (AnwException $e) { // special errors management, see FS#62 $asNotices[] = $this->t_("notice_unknown") . " (" . $e->getMessage() . ")"; //print $e->getFile().'!'.$e->getLine();print_r($e->getTrace()); if ($bMainTransaction) { // we will have to rollback, but we still continue to get the whole report $bMustRollback = true; } if ($bSubTransaction) { AnwStorage::transactionRollback(); } AnwDebug::reportError($e); } } // import result if (count($asNotices) == 0) { $nCountImportSuccess++; // at least we got a success! $sOutBuffer .= $this->tpl()->rowTranslationProcess_success($oPage->link()); } else { $nCountImportErrors++; $sOutBuffer .= $this->tpl()->rowTranslationProcess_failed($sPageName, $sPageLang, $asNotices); } } else { $sOutBuffer .= $this->tpl()->rowTranslationProcess_skipped($sPageName, $sPageLang); } } $sOutBuffer .= $this->tpl()->rowGroupClose(); } if ($bMainTransaction) { if (!$bMustRollback) { AnwStorage::transactionCommit(); } else { AnwStorage::transactionRollback(); } } } catch (AnwException $e) { AnwStorage::transactionRollback(); throw $e; } // output, with import results before the detailled report $this->out .= $this->tpl()->beginProcess(); if ($nCountImportErrors > 0) { if ($nCountImportSuccess > 0) { if ($bContinueOnErrors) { $this->out .= $this->tpl()->importResultErrorsContinued($nCountImportSuccess, $nCountImportErrors); } else { $this->out .= $this->tpl()->importResultErrorsCancelled($nCountImportSuccess, $nCountImportErrors); } } else { $this->out .= $this->tpl()->importResultFailed($nCountImportErrors); } } else { $this->out .= $this->tpl()->importResultSuccess($nCountImportSuccess); } $this->out .= $this->tpl()->importDetails($sOutBuffer); }
private function saveDuplication() { $this->out .= $this->tpl()->beginProcessDuplication($this->getoPage()->getName(), $this->getoPage()->getLang()); $aoTranslations = $this->getoPage()->getPageGroup()->getPages($this->getoPage()); //which pages should we duplicate? $aaPagesForDuplication = array(); $oPage = $this->getoPage(); $aaPagesForDuplication[] = array('LANG' => $oPage->getLang(), 'NAME' => AnwEnv::_POST($this->getInputName($oPage), ""), 'CONTENT' => $oPage->getContent()->toXmlString()); foreach ($aoTranslations as $oTranslation) { if (AnwEnv::_POST($this->getChkName($oTranslation))) { $aaPagesForDuplication[] = array('LANG' => $oTranslation->getLang(), 'NAME' => AnwEnv::_POST($this->getInputName($oTranslation), ""), 'CONTENT' => $oTranslation->getContent()->toXmlString()); } } AnwStorage::transactionStart(); try { $oFirstPage = null; $oContentClass = $this->getoPage()->getPageGroup()->getContentClass(); //duplicate each page foreach ($aaPagesForDuplication as $asPageForDuplication) { $asNotices = array(); $sPageName = $asPageForDuplication['NAME']; $sPageLang = $asPageForDuplication['LANG']; $sPageContent = $asPageForDuplication['CONTENT']; $asNotices = $this->checkPermissions($sPageName, $sPageLang, $sPageContent); if (count($asNotices) == 0) { $oContent = $oContentClass->rebuildContentFromXml($sPageContent); if (!$oFirstPage) { $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sPageLang, "", $oContent); $oFirstPage = $oPage; } else { $oPage = $oFirstPage->createNewTranslation($sPageName, $sPageLang, "", $oContent); } $this->out .= $this->tpl()->rowProcessDuplication_success($oPage->link()); } else { $this->out .= $this->tpl()->rowProcessDuplication_failed($sPageName, $sPageLang, $asNotices); } } AnwStorage::transactionCommit(); } catch (AnwException $e) { AnwStorage::transactionRollback(); throw $e; } $this->out .= $this->tpl()->endProcessDuplication(); }
private function saveTranslations($sAddLang) { try { if (!Anwi18n::langExists($sAddLang)) { throw new AnwBadLangException(); } $this->out .= $this->tpl()->startProcess(); $bSomethingDone = false; $aoPageGroups = AnwStorage::getPageGroups(false, null, null); AnwStorage::transactionStart(); try { foreach ($aoPageGroups as $oPageGroup) { $aoPages = $oPageGroup->getPages(); $bChecked = AnwEnv::_POST($this->getChkName($oPageGroup)); if (!isset($aoPages[$sAddLang]) && $bChecked) { $sTranslationName = AnwEnv::_POST($this->getInputName($oPageGroup)); //check permissions : translate if (!AnwCurrentSession::isActionAllowed($sTranslationName, 'translate', $sAddLang)) { throw new AnwAclException("permission translate denied"); } //find PageRef $nPageRefId = (int) AnwEnv::_POST($this->getInputRef($oPageGroup)); $oPageRef = new AnwPageById($nPageRefId); if (isset($aoPages[$oPageRef->getLang()]) && $oPageRef->getId() == $aoPages[$oPageRef->getLang()]->getId()) { //create translation $oPageTranslation = $oPageRef->createNewTranslation($sTranslationName, $sAddLang); $this->out .= $this->tpl()->newTranslationCreated($sAddLang, $oPageTranslation->link()); $bSomethingDone = true; } } } AnwStorage::transactionCommit(); } catch (AnwException $e) { AnwStorage::transactionRollback(); throw $e; } $sUrlContinue = $this->linkMe(array("addlang" => $sAddLang)); if (!$bSomethingDone) { AnwUtils::redirect($sUrlContinue); } $this->out .= $this->tpl()->endProcess($sUrlContinue); } catch (AnwBadPageNameException $e) { $this->showForm($sAddLang, $this->g_("err_badpagename")); } catch (AnwBadLangException $e) { $this->showForm($sAddLang, $this->g_("err_badlang")); } catch (AnwPageAlreadyExistsException $e) { $this->showForm($sAddLang, $this->g_("err_pagealreadyexists")); } catch (AnwAclException $e) { $this->showForm($sAddLang, $this->g_("err_nopermission")); } catch (AnwLangExistsForPageGroupException $e) { $this->showForm($sAddLang, $this->g_("err_langexistsforpagegroup")); } }
function delete($nTime = null, $sChangeComment = "") { if (!$nTime) { $nTime = time(); } //update some attributes $this->touchInfos($nTime); //get new change ID $nChangeType = AnwChange::TYPE_PAGE_DELETION; $oChange = new AnwChange($nChangeType, $this, $nTime, $sChangeComment); AnwStorage::transactionStart(); try { //save AnwStorage::deletePage($this, $oChange); //notify change $this->notifyChanged(); AnwStorage::transactionCommit(); } catch (AnwException $e) { AnwStorage::transactionRollback(); throw $e; } }