- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/integrity/volatile/eventhandler.php
- Класс: Bitrix\Crm\Integrity\Volatile\EventHandler
- Вызов: EventHandler::stopDuplicateIndexAgents
protected function stopDuplicateIndexAgents()
{
$res = CAgent::GetList(
['ID' => 'DESC'],
[
'MODULE_ID' => 'crm',
'NAME' => '%Bitrix\\Crm\\Agent\\Duplicate\\Background\\%',
'ACTIVE' => 'Y',
]
);
if (is_object($res))
{
$types = [];
foreach ($this->volatileTypeIds as $id)
{
$types[DuplicateIndexType::resolveName($id)] = true;
}
$types = array_keys($types);
$regexp =
'/^(\\\\)?Bitrix\\\\Crm\\\\Agent\\\\Duplicate\\\\Background\\\\'
. '(Lead|Company|Contact)IndexRebuild::run\\((\\d+)\\);$/'
;
$matches = [];
$indexAgentHelper = Background\Helper::getInstance();
while ($row = $res->Fetch())
{
$agentName = $row['NAME'] ?? '';
if (preg_match($regexp, $agentName, $matches))
{
$entityTypeName = mb_strtoupper($matches[2]);
$userId = (int)$matches[3];
// Get agent and state
/** @var Background\IndexRebuild $agentClassName */
$agentClassName = $indexAgentHelper->getAgentClassName($entityTypeName, 'IndexRebuild');
$agent = $agentClassName::getInstance($userId);
$state = $agent->state()->getData();
if (is_array($state['TYPES'] ?? null) && !empty(array_intersect($types, $state['TYPES'])))
{
$agent->stop();
}
}
}
}
}