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"]; }