- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/lib/item/workgroup.php
- Класс: BitrixSocialnetworkItemWorkgroup
- Вызов: Workgroup::setIndex
static function setIndex($params = array()): void
{
global $DB;
static $connection = null;
if (!is_array($params))
{
return;
}
$fields = (isset($params['fields']) ? $params['fields'] : array());
if (
!is_array($fields)
|| empty($fields)
)
{
return;
}
$groupId = (isset($fields['ID']) ? intval($fields['ID']) : 0);
if ($groupId <= 0)
{
return;
}
$content = self::getGroupContent(array(
'id' => $groupId,
'fields' => $fields
));
$content = self::prepareToken($content);
$event = new MainEvent(
'socialnetwork',
'onWorkgroupIndexGetContent',
array(
'groupId' => $groupId,
)
);
$event->send();
foreach($event->getResults() as $eventResult)
{
if ($eventResult->getType() == BitrixMainEventResult::SUCCESS)
{
$eventParams = $eventResult->getParameters();
if (
is_array($eventParams)
&& isset($eventParams['content'])
)
{
$eventContent = $eventParams['content'];
if (MainLoader::includeModule('search'))
{
$eventContent = CSearch::killTags($eventContent);
}
$eventContent = trim(str_replace(
array("r", "n", "t"),
" ",
$eventContent
));
$eventContent = self::prepareToken($eventContent);
if (!empty($eventContent))
{
$content .= ' '.$eventContent;
}
}
}
}
if (!empty($content))
{
if ($connection === null)
{
$connection = BitrixMainApplication::getConnection();
}
$value = $DB->forSql($content);
$encryptedValue = sha1($content);
$connection->query("UPDATE ".WorkgroupTable::getTableName()." SET SEARCH_INDEX = IF(SHA1(SEARCH_INDEX) = '{$encryptedValue}', SEARCH_INDEX, '{$value}') WHERE ID = {$groupId}");
}
}