Example #1
0
	function ReindexModule($MODULE_ID, $bFull=false)
	{
		global $APPLICATION;
		$DB = CDatabase::GetModuleConnection('search');

		if($bFull)
			CSearch::DeleteForReindex($MODULE_ID);

		$NS=Array("CLEAR"=>"N", "MODULE"=>"", "ID"=>"", "SESS_ID"=>md5(uniqid("")));
		//for every who wants to be reindexed
		foreach(GetModuleEvents("search", "OnReindex", true) as $arEvent)
		{
			if($arEvent["TO_MODULE_ID"]!=$MODULE_ID) continue;

			$oCallBack = new CSearchCallback;
			$oCallBack->MODULE = $arEvent["TO_MODULE_ID"];
			$oCallBack->CNT = &$NS["CNT"];
			$oCallBack->SESS_ID = $NS["SESS_ID"];
			$r = &$oCallBack;

			$arResult = ExecuteModuleEventEx($arEvent, array($NS, $r, "Index"));
			if(is_array($arResult)) //old way
			{
				foreach($arResult as $arFields)
				{
					$ID = $arFields["ID"];
					if(strlen($ID) > 0)
					{
						unset($arFields["ID"]);
						$NS["CNT"]++;
						CSearch::Index($arEvent["TO_MODULE_ID"], $ID, $arFields, false, $NS["SESS_ID"]);
					}
				}
			}
			else  //new way
			{
				return Array("MODULE"=>$arEvent["TO_MODULE_ID"], "CNT"=>$oCallBack->CNT, "ID"=>$arResult, "CLEAR"=>$NS["CLEAR"], "SESS_ID"=>$NS["SESS_ID"]);
			}
		}

		if(!$bFull)
			CSearch::DeleteOld($NS["SESS_ID"], $MODULE_ID, $NS["SITE_ID"]);
	}
Example #2
0
 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 (strlen($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 (strlen($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 (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 (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 (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_tasks":
             $path_template = trim($this->_params["PATH_TO_GROUP_TASK_ELEMENT"]);
             $iblock = intval($this->_params["TASK_IBLOCK_ID"]);
             if (strlen($path_template) && $iblock) {
                 $last_id = $this->ReindexGroupTasks($iblock, $path_template, $last_id);
             } else {
                 $last_id = 0;
             }
             break;
         case "user_tasks":
             $path_template = trim($this->_params["PATH_TO_USER_TASK_ELEMENT"]);
             if (strlen($path_template) && CModule::IncludeModule("iblock")) {
                 $iblock = intval($this->_params["TASK_IBLOCK_ID"]);
                 $rsSection = CIBlockSection::GetList(array(), array("GLOBAL_ACTIVE" => "Y", "EXTERNAL_ID" => "users_tasks", "IBLOCK_ID" => $iblock, "SECTION_ID" => 0), false);
                 $arSection = $rsSection->Fetch();
             } else {
                 $arSection = false;
             }
             if ($arSection) {
                 $last_id = $this->ReindexUserTasks($arSection, $path_template, $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 = strtoupper(trim($this->_params["FILES_PROPERTY_CODE"]));
             if (strlen($property) <= 0) {
                 $property = "FILE";
             }
             $this->_file_property = "PROPERTY_" . $property;
             if (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 (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 = strtoupper(trim($this->_params["FILES_PROPERTY_CODE"]));
             if (strlen($property) <= 0) {
                 $property = "FILE";
             }
             $this->_file_property = "PROPERTY_" . $property;
             if (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);
     }
 }