protected function initializeAdditional()
 {
     $sInitLog = "";
     //-----------------------------
     // create default home page
     //-----------------------------
     $oContentClass = AnwContentClasses::getContentClass('page');
     $sPageName = AnwComponent::globalCfgHomePage();
     $sPageLang = AnwComponent::globalCfgLangDefault();
     $sChangeComment = "Installation assistant";
     $oContent = new AnwContentPage($oContentClass);
     $sHomeTitle = $this->t_("local_homepage_title", array(), $sPageLang);
     $sHomeHead = $this->tpl()->homePageHead($sPageLang);
     $sHomeBody = $this->tpl()->homePageBody($sPageLang, ANWIKI_WEBSITE);
     $oContent->setContentFieldValues(AnwIContentClassPageDefault_page::FIELD_TITLE, array($sHomeTitle));
     $oContent->setContentFieldValues(AnwIContentClassPageDefault_page::FIELD_HEAD, array($sHomeHead));
     $oContent->setContentFieldValues(AnwIContentClassPageDefault_page::FIELD_BODY, array($sHomeBody));
     $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sPageLang, $sChangeComment, $oContent);
     $sInitLog .= $this->t_("initlog_pagecreated", array('pagename' => $sPageName)) . '<br/>';
     //-----------------------------
     // create default menu
     //-----------------------------
     $oContentClass = AnwContentClasses::getContentClass('menu');
     $sPageName = 'en/_include/menu';
     //TODO
     $sPageLang = Anwi18n::langExists('en') ? 'en' : AnwComponent::globalCfgLangDefault();
     //TODO
     $sChangeComment = "Installation assistant";
     $oContent = new AnwContentPage($oContentClass);
     //menu title
     $sMenuTitle = $this->t_("local_menu_title", array(), $sPageLang);
     $oContent->setContentFieldValues(AnwIContentClassPageDefault_menu::FIELD_TITLE, array($sMenuTitle));
     //items
     $oContentFieldItems = $oContentClass->getContentField(AnwIContentClassPageDefault_menu::FIELD_ITEMS);
     $oSubContentItem = new AnwContentPage($oContentFieldItems);
     //main link
     $oContentFieldMainLink = $oContentFieldItems->getContentField(AnwIContentFieldPage_menu_menuItem::FIELD_MAINLINK);
     $oSubContentMainLink = new AnwContentPage($oContentFieldMainLink);
     $sMainLinkTitle = $this->t_("local_menu_mainlink_title", array(), $sPageLang);
     $oSubContentMainLink->setContentFieldValues(AnwIPage_link::FIELD_TITLE, array($sMainLinkTitle));
     $oSubContentMainLink->setContentFieldValues(AnwIPage_link::FIELD_URL, array(AnwComponent::globalCfgHomePage()));
     $oSubContentMainLink->setContentFieldValues(AnwIPage_link::FIELD_TARGET, array(AnwIPage_link::TARGET_SELF));
     $oSubContentItem->setSubContents(AnwIContentFieldPage_menu_menuItem::FIELD_MAINLINK, array($oSubContentMainLink));
     $oContent->setSubContents(AnwIContentClassPageDefault_menu::FIELD_ITEMS, array($oSubContentItem));
     $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sPageLang, $sChangeComment, $oContent);
     $sInitLog .= $this->t_("initlog_pagecreated", array('pagename' => $sPageName)) . '<br/>';
     return $sInitLog;
 }
Exemplo n.º 2
0
 /**
  * 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);
 }
Exemplo n.º 3
0
 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"));
 }
Exemplo n.º 4
0
 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();
 }