LeadManualOpportunityAgent::doRun

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. LeadManualOpportunityAgent
  4. doRun
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/agent/opportunity/leadmanualopportunityagent.php
  • Класс: Bitrix\Crm\Agent\Opportunity\LeadManualOpportunityAgent
  • Вызов: LeadManualOpportunityAgent::doRun
static function doRun()
{
	$instance = static::getInstance();
	if ($instance === null)
	{
		return false;
	}

	if (!$instance->isEnabled())
	{
		return false;
	}

	$progressData = $instance->getProgressData();

	$offsetId = isset($progressData['LAST_ITEM_ID']) ? (int)($progressData['LAST_ITEM_ID']) : 0;
	$limit = (int)Option::get('crm', '~CRM_LEAD_MANUAL_OPPORTUNITY_INITIATED_LIMIT', 50);
	if ($limit <= 0)
	{
		$instance->markAsDisabled();
		return false;
	}
	$items = $instance->getItems($offsetId, $limit);
	if (!count($items))
	{
		$instance->markAsDisabled();
		return false;
	}

	$leadId = $offsetId;

	$connection = Application::getConnection();
	$tableName = \CCrmLead::TABLE_NAME;
	foreach ($items as $item)
	{
		$leadId = (int)$item['ID'];
		if ($item['IS_MANUAL_OPPORTUNITY'] === 'N' && $item['OPPORTUNITY'] > 0)
		{
			$productCount = \CCrmProductRow::GetRowQuantity('L', $leadId);
			if (!$productCount)
			{
				$connection->query("UPDATE {$tableName} SET IS_MANUAL_OPPORTUNITY='Y' WHERE ID={$leadId}");
			}
		}
	}
	$instance->setProgressData(['LAST_ITEM_ID' => $leadId]);
	return true;
}

Добавить комментарий