• Модуль: translate
  • Путь к файлу: ~/bitrix/modules/translate/lib/index/pathlangcollection.php
  • Класс: BitrixTranslateIndexPathLangCollection
  • Вызов: PathLangCollection::collect
public function collect(TranslateFilter $filter = null, TranslateControllerITimeLimit $timer = null, TranslateFilter $seek = null): int
{
	self::configure();

	if (isset($filter, $filter->path))
	{
		$relPath = $filter->path;
	}
	else
	{
		$relPath = TranslateConfig::getDefaultPath();
	}
	$relPath = '/'. trim($relPath, '/');

	// If it is lang folder, do nothing
	if (basename($relPath) == 'lang')
	{
		IndexInternalsPathLangTable::add(['PATH' => $relPath]);

		return 1;
	}

	$seekAncestors = [];
	if (isset($seek, $seek->path))
	{
		$seekAncestors = explode('/', trim($seek->path, '/'));
		$seek->lookForSeek = true;
	}

	if (self::$useTranslationRepository)
	{
		$checkLanguages = self::$translationEnabledLanguages;
		if (isset($filter, $filter->langId))
		{
			$checkLanguages = array_intersect($filter->langId, $checkLanguages);
		}
	}

	$pathDepthLevel = count(explode('/', trim($relPath, '/'))) - 1;

	$cache = [];
	$processedItemCount = 0;

	/**
	 * @param string $relPath
	 * @param bool $isTop
	 *
	 * @return Generator|string
	 */
	$lookForLangDirectory = function ($startRoot, $relPath, $depthLevel, $isTop = false)
		use (&$lookForLangDirectory, &$cache, $checkLanguages, &$seek, $seekAncestors, &$processedItemCount)
	{
		$childrenList = [];

		$mergeChildrenList = function($childrenList0, $langId = '') use (&$childrenList)
		{
			foreach ($childrenList0 as $childPath)
			{
				$name = basename($childPath);
				if (in_array($name, TranslateIGNORE_FS_NAMES))
				{
					continue;
				}
				if (isset($childrenList[$name]))
				{
					continue;
				}

				if (self::$useTranslationRepository && $langId != '')
				{
					$childPath = str_replace(
						self::$translationRepositoryRoot. '/'. $langId,
						self::$documentRoot. '/bitrix/modules',
						$childPath
					);
				}

				$childrenList[$name] = $childPath;
			}
		};

		$mergeChildrenList(TranslateIOFileSystemHelper::getFolderList($startRoot. $relPath));

		if (self::$useTranslationRepository)
		{
			foreach ($checkLanguages as $langId)
			{
				$path1 = LocalizationTranslation::convertLangPath($startRoot. $relPath, $langId);
				if ($path1 != $startRoot)
				{
					$mergeChildrenList(TranslateIOFileSystemHelper::getFolderList($path1), $langId);
				}
			}
		}

		if (!empty($childrenList))
		{
			$ignoreDev = implode('|', TranslateIGNORE_MODULE_NAMES);
			foreach ($childrenList as $childPath)
			{
				$name = basename($childPath);
				$relChildPath = str_replace($startRoot, '', $childPath);

				if (in_array($name, TranslateIGNORE_FS_NAMES))
				{
					continue;
				}
				if (in_array($relChildPath, TranslateIGNORE_BX_NAMES))
				{
					continue;
				}
				// /bitrix/modules/[smth]/dev/
				if (preg_match("#/bitrix/modules/[^/]+/({$ignoreDev})$#", $relChildPath))
				{
					continue;
				}

				$isLang = ($name == 'lang');

				if ($seek !== null && $seek->lookForSeek === true)
				{
					if ($seekAncestors[$depthLevel + 1] == $name)
					{
						if ($relChildPath == $seek->path)
						{
							if (self::$verbose)
							{
								echo "Seek folder: {$relChildPath}n";
							}
							$seek->lookForSeek = false;// found
							continue;
						}

						if (!$isLang)
						{
							foreach ($lookForLangDirectory($startRoot, $relChildPath, $depthLevel + 1) as $subChildPath)// go deeper
							{
							}
						}
					}

					continue;
				}

				if ($isLang)
				{
					$cache[] = [
						'PATH' => $relChildPath,
					];

					if (count($cache) >= 50)
					{
						IndexInternalsPathLangTable::bulkAdd($cache);
						$processedItemCount += count($cache);
						$cache = [];
					}
				}
				else
				{
					foreach ($lookForLangDirectory($startRoot, $relChildPath, $depthLevel + 1) as $subChildPath)// go deeper
					{
						yield $subChildPath;
					}
				}

				if ($isLang)
				{
					yield $relChildPath;
				}
			}
		}

		if ($isTop && count($cache) > 0)
		{
			IndexInternalsPathLangTable::bulkAdd($cache);
			$processedItemCount += count($cache);
			$cache = [];
		}
	};

	foreach ($lookForLangDirectory(self::$documentRoot, $relPath, $pathDepthLevel, true) as $langPath)
	{
		if (self::$verbose)
		{
			if (!$langPath instanceof Generator)
			{
				echo "Lang folder: {$langPath}n";
			}
		}
		if ($timer !== null)
		{
			if ($timer->hasTimeLimitReached())
			{
				$seek->nextPath = $langPath;
				break;
			}
		}
		// check user abortion
		if (connection_status() !== CONNECTION_NORMAL)
		{
			throw new MainSystemException('Process has been broken course user aborted connection.');
		}
	}

	if (count($cache) > 0)
	{
		IndexInternalsPathLangTable::bulkAdd($cache);
		$processedItemCount += count($cache);
	}

	return $processedItemCount;
}