- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/agent/history/leadstatushistorywithsupposed.php
- Класс: Bitrix\Crm\Agent\History\LeadStatusHistoryWithSupposed
- Вызов: LeadStatusHistoryWithSupposed::execute
public function execute(array &$option)
{
/*hack because in table b_option field `name` has length 50 */
if (static::class === LeadStatusHistoryWithSupposed::class || Option::get("crm", self::STATISTIC_PRE_CALCULATE_LEAD_SUPPOSED_HISTORY_FINISH, 'N') === 'Y')
{
return false;
}
if(!Application::getConnection()->isTableExists('b_crm_last_stored_lead_status_history_id'))
{
return false;
}
$lastStoredHistoryId = Option::get('crm', self::ANALYTICS_LEAD_SUPPOSED_HISTORY_LAST_EXECUTED_HISTORY_ID, 0);
$executedStepCount = Option::get("crm", self::ANALYTICS_LEAD_SUPPOSED_HISTORY_EXECUTED_STEP_COUNT, 0);
if ($executedStepCount == 0)
{
Option::set("crm", self::STATISTIC_PRE_CALCULATE_LEAD_SUPPOSED_HISTORY_FINISH, 'N');
$lastStoredHistoryId = $this->getLastStoredLeadStatusHistoryId();
}
$histories = $this->getHistories($lastStoredHistoryId);
if (empty($histories))
{
Option::delete("crm", ['name' => self::ANALYTICS_LEAD_SUPPOSED_HISTORY_LAST_EXECUTED_HISTORY_ID]);
Option::delete("crm", ['name' => self::ANALYTICS_LEAD_SUPPOSED_HISTORY_EXECUTED_STEP_COUNT]);
Option::set("crm", self::STATISTIC_PRE_CALCULATE_LEAD_SUPPOSED_HISTORY_FINISH, 'Y');
$this->dropLastStoredLeadIdTable();
return false;
}
$executedLeadIds = [];
foreach ($histories as $history)
{
$lastStoredHistoryId = $history['ID'];
$executedLeadIds[] = $history['OWNER_ID'];
}
$leadIds = array_unique($executedLeadIds);
foreach ($leadIds as $id)
{
LeadStatusHistoryWithSupposedEntry::register($id);
}
$executedStepCount++;
Option::set("crm", self::ANALYTICS_LEAD_SUPPOSED_HISTORY_LAST_EXECUTED_HISTORY_ID, $lastStoredHistoryId);
Option::set("crm", self::ANALYTICS_LEAD_SUPPOSED_HISTORY_EXECUTED_STEP_COUNT, $executedStepCount);
$option["steps"] = $executedStepCount;
$option["count"] = (int)(($this->getHistoryCount() / self::MAX_HISTORY_PER_ITERATION) + 1);
return true;
}