• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/urlrewriter.php
  • Класс: BitrixMainUrlRewriter
  • Вызов: UrlRewriter::reindexAll
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 (!empty($nsOld["SITE_ID"]))
			$ns["SITE_ID"] = $nsOld["SITE_ID"];
	}
	$ns["CNT"] = intval($ns["CNT"] ?? 0);

	$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" => IOPath::combine($ar["DOC_ROOT"], $ar["DIR"])
		);

		if (!empty($ns["SITE_ID"]) && $ns["SITE_ID"] == $ar["LID"])
			$filterRootPath = $ar["DOC_ROOT"];
	}

	if (!empty($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 = mb_strlen($a["path"]);
			$lb = mb_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)
		{
			ComponentParametersTable::deleteBySiteId($site["site_id"]);
			if (!in_array($site["root"], $arAlreadyDeleted))
			{
				static::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"])
			&& mb_substr($ns["ID"]."/", 0, mb_strlen($site["root"]."/")) != $site["root"]."/")
		{
			continue;
		}

		static::recursiveReindex($site["root"], "/", $arSites, $maxExecutionTime, $ns);

		if ($maxExecutionTime > 0 && !empty($ns["FLG"]))
			return $ns;
	}

	return $ns["CNT"];
}