Exemple #1
0
 public static function delete($id)
 {
     //We know for sure that languages and sites can refer to the culture.
     //Other entities should place CultureOnBeforeDelete event handler.
     $result = new Entity\DeleteResult();
     $res = LanguageTable::getList(array('filter' => array('=CULTURE_ID' => $id)));
     while ($language = $res->fetch()) {
         $result->addError(new Entity\EntityError(Loc::getMessage("culture_err_del_lang", array("#LID#" => $language["LID"]))));
     }
     $res = \Freetrix\Main\SiteTable::getList(array('filter' => array('=CULTURE_ID' => $id)));
     while ($site = $res->fetch()) {
         $result->addError(new Entity\EntityError(Loc::getMessage("culture_err_del_site", array("#LID#" => $site["LID"]))));
     }
     if (!$result->isSuccess()) {
         return $result;
     }
     return parent::delete($id);
 }
Exemple #2
0
 protected function initializeSite()
 {
     $request = $this->getRequest();
     $currentDirectory = $request->getRequestedPageDirectory();
     $currentDomain = $request->getHttpHost(false);
     $site = SiteTable::getByDomainAndPath($currentDomain, $currentDirectory);
     if ($site === false) {
         $siteList = SiteTable::getList(array('filter' => array('ACTIVE' => 'Y'), 'order' => array('DEF' => 'DESC', 'SORT' => 'ASC'), 'select' => array('*', 'ID' => 'LID')));
         $site = $siteList->fetch();
     }
     if ($site === false) {
         throw new SystemException("Site not found");
     }
     $culture = Context\Culture::wakeUp($site["CULTURE_ID"]);
     if ($culture === null) {
         $culture = new Context\Culture();
     }
     $this->site = new Context\Site($site);
     $this->site->setCulture($culture);
     $this->setContextCulture($culture, $this->site->getLanguage());
 }
Exemple #3
0
 public static function reindexAll($maxExecutionTime = 0, $ns = array())
 {
     @set_time_limit(0);
     if (!is_array($ns)) {
         $ns = array();
     }
     if ($maxExecutionTime <= 0) {
         $nsOld = $ns;
         $ns = array("CLEAR" => "N", "ID" => "", "FLG" => "", "SESS_ID" => md5(uniqid("")), "max_execution_time" => $nsOld["max_execution_time"], "stepped" => $nsOld["stepped"], "max_file_size" => $nsOld["max_file_size"]);
         if ($nsOld["SITE_ID"] != "") {
             $ns["SITE_ID"] = $nsOld["SITE_ID"];
         }
     }
     $ns["CNT"] = intval($ns["CNT"]);
     $arSites = array();
     $filterRootPath = "";
     $db = SiteTable::getList(array("select" => array("LID", "DOC_ROOT", "DIR"), "filter" => array("ACTIVE" => "Y")));
     while ($ar = $db->fetch()) {
         if (empty($ar["DOC_ROOT"])) {
             $ar["DOC_ROOT"] = Application::getDocumentRoot();
         }
         $arSites[] = array("site_id" => $ar["LID"], "root" => $ar["DOC_ROOT"], "path" => IO\Path::combine($ar["DOC_ROOT"], $ar["DIR"]));
         if ($ns["SITE_ID"] != "" && $ns["SITE_ID"] == $ar["LID"]) {
             $filterRootPath = $ar["DOC_ROOT"];
         }
     }
     if ($ns["SITE_ID"] != "" && !empty($filterRootPath)) {
         $arSitesTmp = array();
         $arKeys = array_keys($arSites);
         foreach ($arKeys as $key) {
             if ($arSites[$key]["root"] == $filterRootPath) {
                 $arSitesTmp[] = $arSites[$key];
             }
         }
         $arSites = $arSitesTmp;
     }
     uasort($arSites, function ($a, $b) {
         $la = strlen($a["path"]);
         $lb = strlen($b["path"]);
         if ($la == $lb) {
             if ($a["site_id"] == $b["site_id"]) {
                 return 0;
             } else {
                 return $a["site_id"] > $b["site_id"] ? -1 : 1;
             }
         }
         return $la > $lb ? -1 : 1;
     });
     if ($ns["CLEAR"] != "Y") {
         $arAlreadyDeleted = array();
         foreach ($arSites as $site) {
             Component\ParametersTable::deleteBySiteId($site["site_id"]);
             if (!in_array($site["root"], $arAlreadyDeleted)) {
                 UrlRewriter::delete($site["site_id"], array("!ID" => ""));
                 $arAlreadyDeleted[] = $site["root"];
             }
         }
     }
     $ns["CLEAR"] = "Y";
     clearstatcache();
     $arAlreadyParsed = array();
     foreach ($arSites as $site) {
         if (in_array($site["root"], $arAlreadyParsed)) {
             continue;
         }
         $arAlreadyParsed[] = $site["root"];
         if ($maxExecutionTime > 0 && !empty($ns["FLG"]) && substr($ns["ID"] . "/", 0, strlen($site["root"] . "/")) != $site["root"] . "/") {
             continue;
         }
         UrlRewriter::recursiveReindex($site["root"], "/", $arSites, $maxExecutionTime, $ns);
         if ($maxExecutionTime > 0 && !empty($ns["FLG"])) {
             return $ns;
         }
     }
     return $ns["CNT"];
 }
Exemple #4
0
 /**
  * Function clears entire component cache.
  *
  * <p>Note: parameters must exactly match to startResultCache call.</p>
  * @param string $componentName
  * @param string $siteId
  * @return void
  *
  */
 public static final function clearComponentCache($componentName, $siteId = "")
 {
     /** @global CCacheManager $CACHE_MANAGER */
     global $CACHE_MANAGER;
     $componentRelativePath = CComponentEngine::MakeComponentPath($componentName);
     if ($componentRelativePath != "") {
         $obCache = new CPHPCache();
         $obCache->CleanDir($componentRelativePath, "cache");
         BXClearCache(true, $componentRelativePath);
         if ($siteId == "") {
             $rsSite = \Freetrix\Main\SiteTable::getList(array('order' => array('SORT' => 'ASC')));
             while ($site = $rsSite->fetch()) {
                 $componentCachePath = "/" . $site["LID"] . $componentRelativePath;
                 $obCache = new CPHPCache();
                 $obCache->CleanDir($componentCachePath, "cache");
                 BXClearCache(true, $componentCachePath);
             }
         } else {
             $componentCachePath = "/" . $siteId . $componentRelativePath;
             $obCache = new CPHPCache();
             $obCache->CleanDir($componentCachePath, "cache");
             BXClearCache(true, $componentCachePath);
         }
         if (defined("FX_COMP_MANAGED_CACHE")) {
             $CACHE_MANAGER->ClearByTag($componentName);
         }
     }
 }
Exemple #5
0
 protected static function actionAdd($name, $arFields)
 {
     if ($name == 'ADDELEMENT') {
         if (!self::checkElement($arFields)) {
             return;
         }
         // we don't have the GLOBAL_ACTIVE flag in $arFields so we should check it manually
         if (is_array($arFields['IBLOCK_SECTION']) && count($arFields['IBLOCK_SECTION']) > 0) {
             $arNewSections = array();
             $arFilter = array('ID' => $arFields['IBLOCK_SECTION'], 'IBLOCK_ID' => $arFields['IBLOCK_ID'], 'GLOBAL_ACTIVE' => 'Y');
             $dbRes = \CIBlockSection::getList(array(), $arFilter, false, array('ID'));
             while ($ar = $dbRes->fetch()) {
                 $arNewSections[] = $ar['ID'];
             }
             if (count($arNewSections) <= 0) {
                 // element is added to inactive sections
                 return;
             }
             $arFields['IBLOCK_SECTION'] = $arNewSections;
         }
     } elseif ($name == 'ADDSECTION') {
         $dbRes = \CIBlockSection::getList(array(), array('ID' => $arFields['ID'], 'GLOBAL_ACTIVE' => 'Y'), false, array('ID'));
         if (!$dbRes->fetch()) {
             // section is added to inactive branch
             return;
         }
     }
     $arSitemaps = SitemapIblockTable::getByIblock($arFields, $name == 'ADDSECTION' ? SitemapIblockTable::TYPE_SECTION : SitemapIblockTable::TYPE_ELEMENT);
     $arFields['TIMESTAMP_X'] = ConvertTimeStamp(false, "FULL");
     if (isset($arFields['IBLOCK_SECTION']) && is_array($arFields['IBLOCK_SECTION']) && count($arFields['IBLOCK_SECTION']) > 0) {
         $arFields['IBLOCK_SECTION_ID'] = min($arFields['IBLOCK_SECTION']);
     }
     if (count($arSitemaps) > 0) {
         $arSiteDirs = array();
         $dbSite = SiteTable::getList(array('select' => array('LID', 'DIR')));
         while ($arSite = $dbSite->fetch()) {
             $arSiteDirs[$arSite['LID']] = $arSite['DIR'];
         }
         foreach ($arSitemaps as $arSitemap) {
             $arFields['LANG_DIR'] = $arSiteDirs[$arSitemap['SITE_ID']];
             $rule = array('url' => $name == 'ADDSECTION' ? \CIBlock::replaceDetailUrl($arSitemaps[0]['SECTION_PAGE_URL'], $arFields, false, "S") : \CIBlock::replaceDetailUrl($arSitemaps[0]['DETAIL_PAGE_URL'], $arFields, false, "E"), 'lastmod' => MakeTimeStamp($arFields['TIMESTAMP_X']));
             $fileName = str_replace(array('#IBLOCK_ID#', '#IBLOCK_CODE#', '#IBLOCK_XML_ID#'), array($arFields['IBLOCK_ID'], $arSitemap['IBLOCK_CODE'], $arSitemap['IBLOCK_XML_ID']), $arSitemap['SITEMAP_FILE_IBLOCK']);
             $sitemapFile = new SitemapFile($fileName, $arSitemap);
             $sitemapFile->appendIblockEntry($rule['url'], $rule['lastmod']);
             $sitemapIndex = new SitemapIndex($arSitemap['SITEMAP_FILE'], $arSitemap);
             $sitemapIndex->appendIndexEntry($sitemapFile);
             if ($arSitemap['ROBOTS'] == 'Y') {
                 $robotsFile = new RobotsFile($arSitemap['SITE_ID']);
                 $robotsFile->addRule(array(RobotsFile::SITEMAP_RULE, $sitemapIndex->getUrl()));
             }
         }
     }
 }