Exemplo n.º 1
0
 static function clearCache()
 {
     $sCacheFile = self::filenameCachedComponentsMapping();
     AnwUtils::unlink($sCacheFile, ANWPATH_CACHESYSTEM);
 }
Exemplo n.º 2
0
 static function cacheUnlink($sFilename, $sSafeTestRootDirectory)
 {
     if (AnwEnv::hasSymLink()) {
         // linux way
         @AnwUtils::unlink($sFilename, $sSafeTestRootDirectory);
     } else {
         // windows way
         if (is_dir($sFilename)) {
             @AnwUtils::rmdirFiles($sFilename, $sSafeTestRootDirectory);
         }
     }
 }
Exemplo n.º 3
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);
 }