• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/search_reindex.php
  • Класс: CSocNetSearchReindex
  • Вызов: CSocNetSearchReindex::StepIndex
function StepIndex($arSteps, $current_step, $last_id, $timeout=0)
{
	global $DB;

	if(!CModule::IncludeModule('search'))
		return false;

	foreach ($_SESSION["BX_SOCNET_REINDEX_SESS_ID"] as $key => $value)
		$_SESSION["BX_SOCNET_REINDEX_SESS_ID"][$key] = $DB->ForSQL($value);

	if($timeout > 0)
		$this->_end_time = time()+$timeout;
	else
		$this->_end_time = 0;

	$this->_counter = 0;

	$this->_sess_id = $_SESSION["BX_SOCNET_REINDEX_SESS_ID"]["KEY"];

	do
	{
		$next_step = array_shift($arSteps);
	} while ($next_step != $current_step);

	if(count($arSteps) <= 0)
		$next_step = "end";
	else
		$next_step = array_shift($arSteps);

	switch($current_step)
	{

	case "init":
		$last_id = 0;
		break;

	case "groups":
		$last_id = $this->ReindexGroups($last_id);
		break;

	case "group_blogs":
		$blog_group = intval($this->_params["BLOG_GROUP_ID"]);
		if($blog_group)
			$last_id = $this->ReindexBlog("G", $last_id);
		break;

	case "user_blogs":
		$blog_group = intval($this->_params["BLOG_GROUP_ID"]);
		if($blog_group)
			$last_id = $this->ReindexBlog("U", $last_id);
		break;

	case "group_forums":
		$path_template = trim($this->_params["PATH_TO_GROUP_FORUM_MESSAGE"]);
		if($path_template <> '')
		{
			$last_id = $this->ReindexForum("G", $last_id, $path_template);
		}
		break;

	case "user_forums":
		$path_template = trim($this->_params["PATH_TO_USER_FORUM_MESSAGE"]);
		if($path_template <> '')
		{
			$last_id = $this->ReindexForum("U", $last_id, $path_template);
		}
		break;

	case "group_photos":
		$path_template = trim($this->_params["PATH_TO_GROUP_PHOTO_ELEMENT"]);
		$iblock = intval($this->_params["PHOTO_GROUP_IBLOCK_ID"]);

		if(mb_strlen($path_template) && $iblock)
			$last_id = $this->ReindexIBlock($iblock, "G", "photo", "view", $path_template, array("PREVIEW_TEXT", "PROPERTY_FORUM_TOPIC_ID"), $last_id);
		else
			$last_id = 0;
		break;

	case "user_photos":
		$path_template = trim($this->_params["PATH_TO_USER_PHOTO_ELEMENT"]);
		$iblock = intval($this->_params["PHOTO_USER_IBLOCK_ID"]);

		if(mb_strlen($path_template) && $iblock)
			$last_id = $this->ReindexIBlock($iblock, "U", "photo", "view", $path_template, array("PREVIEW_TEXT", "PROPERTY_FORUM_TOPIC_ID"), $last_id);
		else
			$last_id = 0;
		break;

	case "group_calendars":
		$path_template = trim($this->_params["PATH_TO_GROUP_CALENDAR_ELEMENT"]);
		$iblock = intval($this->_params["CALENDAR_GROUP_IBLOCK_ID"]);

		if(mb_strlen($path_template) && $iblock)
			$last_id = $this->ReindexIBlock($iblock, "G", "calendar", "view", $path_template, array("DETAIL_TEXT"), $last_id);
		else
			$last_id = 0;
		break;

	case "group_files":
		$path_template = trim($this->_params["PATH_TO_GROUP_FILES_ELEMENT"]);
		$iblock = intval($this->_params["FILES_GROUP_IBLOCK_ID"]);

		$property = mb_strtoupper(trim($this->_params["FILES_PROPERTY_CODE"]));
		if($property == '')
			$property = "FILE";
		$this->_file_property = "PROPERTY_".$property;

		if(mb_strlen($path_template) && $iblock)
			$last_id = $this->ReindexIBlock($iblock, "G", "files", "view", $path_template, array($this->_file_property, "PROPERTY_FORUM_TOPIC_ID"), $last_id);
		else
			$last_id = 0;
		break;

	case "group_wiki":
		if(CModule::IncludeModule("wiki"))
		{
			$path_template = trim($this->_params["PATH_TO_GROUP"])."wiki/#name#/";
			$iblock = intval(COption::GetOptionInt("wiki", "socnet_iblock_id"));

			if(mb_strlen($path_template) && $iblock)
				$last_id = $this->ReindexIBlock($iblock, "G", "wiki", "view", $path_template, array("DETAIL_TEXT"), $last_id);
			else
				$last_id = 0;
		}
		break;

	case "user_files":
		$path_template = trim($this->_params["PATH_TO_USER_FILES_ELEMENT"]);
		$iblock = intval($this->_params["FILES_USER_IBLOCK_ID"]);

		$property = mb_strtoupper(trim($this->_params["FILES_PROPERTY_CODE"]));
		if($property == '')
			$property = "FILE";
		$this->_file_property = "PROPERTY_".$property;

		if(mb_strlen($path_template) && $iblock)
			$last_id = $this->ReindexIBlock($iblock, "U", "files", "view", $path_template, array($this->_file_property, "PROPERTY_FORUM_TOPIC_ID"), $last_id);
		else
			$last_id = 0;
		break;

	case "delete_old":
		CSearch::DeleteOld($_SESSION["BX_SOCNET_REINDEX_SESS_ID"], "socialnetwork");
		$last_id = 0;
		break;

	default:
		$last_id = 0;
		break;
	}

	if($last_id > 0 || preg_match('/^.d/', $last_id))
		return array("step" => $current_step, "last_id" => $last_id);
	else
		return array("step" => $next_step, "last_id" => 0);
}