Exemple #1
0
	function RecurseIndex($path=Array(), $max_execution_time = 0, &$NS)
	{
		global $APPLICATION;

		if(!is_array($path))
			return 0;

		$site = $path[0];
		$path = $path[1];

		$DOC_ROOT = CSite::GetSiteDocRoot($site);
		$abs_path = $DOC_ROOT.$path;

		$io = CBXVirtualIo::GetInstance();

		if(!$io->DirectoryExists($abs_path))
			return 0;

		$f = $io->GetFile($abs_path);
		if(!$f->IsReadable())
			return 0;

		$d = $io->GetDirectory($abs_path);
		foreach($d->GetChildren() as $dir_entry)
		{
			$path_file = $path."/".$dir_entry->GetName();

			if($dir_entry->IsDirectory())
			{
				if($path_file == "/bitrix")
					continue;

				//this is not first step and we had stopped here, so go on to reindex
				if(
					$max_execution_time <= 0
					|| strlen($NS["MODULE"]) <= 0
					|| (
						$NS["MODULE"]=="main"
						&& substr($NS["ID"]."/", 0, strlen($site."|".$path_file."/")) == $site."|".$path_file."/"
					)
				)
				{
					if(CSearch::CheckPath($path_file."/") !== false)
					{
						if(CSearch::RecurseIndex(Array($site, $path_file), $max_execution_time, $NS)===false)
							return false;
					}
				}
				else //all done
				{
					continue;
				}
			}
			else
			{
				//not the first step and we found last file from previous one
				if(
					$max_execution_time > 0
					&& strlen($NS["MODULE"]) > 0
					&& $NS["MODULE"]=="main"
					&& $NS["ID"] == $site."|".$path_file
					)
				{
					$NS["MODULE"] = "";
				}
				elseif(strlen($NS["MODULE"]) <= 0)
				{
					$ID = CSearch::ReindexFile(Array($site, $path_file), $NS["SESS_ID"]);
					if(IntVal($ID)>0)
					{
						$NS["CNT"] = IntVal($NS["CNT"]) + 1;
					}

					if(
						$max_execution_time > 0
						&& (getmicrotime() - START_EXEC_TIME > $max_execution_time)
					)
					{
						$NS["MODULE"] = "main";
						$NS["ID"] = $site."|".$path_file;
						return false;
					}
				}
			}
		}

		return true;
	}