protected function writeXmlSitemap($eventArgs)
 {
     global $_CONFIG;
     $entity = $eventArgs->getEntity();
     if ($entity instanceof \Cx\Core\ContentManager\Model\Entity\Page && $entity->getType() != \Cx\Core\ContentManager\Model\Entity\Page::TYPE_ALIAS && $_CONFIG['xmlSitemapStatus'] == 'on') {
         \Cx\Core\PageTree\XmlSitemapPageTree::write();
     }
 }
Beispiel #2
0
 /**
  * Write all settings to the config file
  *
  */
 public static function updatePhpCache()
 {
     global $_ARRAYLANG, $_CONFIG;
     if (!\Cx\Lib\FileSystem\FileSystem::makeWritable(self::getSettingsFile())) {
         \Message::add(self::getSettingsFile() . ' ' . $_ARRAYLANG['TXT_SETTINGS_ERROR_WRITABLE'], \Message::CLASS_ERROR);
         return false;
     }
     //get values from ymlsetting
     \Cx\Core\Setting\Controller\Setting::init('Config', NULL, 'Yaml');
     $ymlArray = \Cx\Core\Setting\Controller\Setting::getArray('Config', null);
     $intMaxLen = 0;
     $ymlArrayValues = array();
     foreach ($ymlArray as $key => $ymlValue) {
         $_CONFIG[$key] = $ymlValue['value'];
         $ymlArrayValues[$ymlValue['group']][$key] = $ymlValue['value'];
         // special case to add legacy domainUrl configuration option
         if ($key == 'mainDomainId') {
             $domainRepository = new \Cx\Core\Net\Model\Repository\DomainRepository();
             $objMainDomain = $domainRepository->findOneBy(array('id' => $ymlArray[$key]['value']));
             if ($objMainDomain) {
                 $domainUrl = $objMainDomain->getName();
             } else {
                 $domainUrl = $_SERVER['SERVER_NAME'];
             }
             $ymlArrayValues[$ymlValue['group']]['domainUrl'] = $domainUrl;
             if ($_CONFIG['xmlSitemapStatus'] == 'on') {
                 \Cx\Core\PageTree\XmlSitemapPageTree::write();
             }
         }
         $intMaxLen = strlen($key) > $intMaxLen ? strlen($key) : $intMaxLen;
     }
     $intMaxLen += strlen('$_CONFIG[\'\']') + 1;
     //needed for formatted output
     // update environment
     \Env::set('config', $_CONFIG);
     $strHeader = "<?php\n";
     $strHeader .= "/**\n";
     $strHeader .= "* This file is generated by the \"settings\"-menu in your CMS.\n";
     $strHeader .= "* Do not try to edit it manually!\n";
     $strHeader .= "*/\n\n";
     $strFooter = "?>";
     //Write values
     $data = $strHeader;
     $strBody = '';
     foreach ($ymlArrayValues as $group => $sectionValues) {
         $strBody .= "/**\n";
         $strBody .= "* -------------------------------------------------------------------------\n";
         $strBody .= "* " . ucfirst($group) . "\n";
         $strBody .= "* -------------------------------------------------------------------------\n";
         $strBody .= "*/\n";
         foreach ($sectionValues as $sectionName => $sectionNameValue) {
             $strBody .= sprintf("%-" . $intMaxLen . "s", '$_CONFIG[\'' . $sectionName . '\']');
             $strBody .= "= ";
             $strBody .= (self::isANumber($sectionNameValue) ? $sectionNameValue : '"' . str_replace('"', '\\"', $sectionNameValue) . '"') . ";\n";
         }
         $strBody .= "\n";
     }
     $data .= $strBody;
     $data .= $strFooter;
     try {
         $objFile = new \Cx\Lib\FileSystem\File(self::getSettingsFile());
         $objFile->write($data);
         return true;
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
         \DBG::msg($e->getMessage());
     }
     return false;
 }