CCrmLeadRestProxy::innerAdd

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmLeadRestProxy
  4. innerAdd
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmLeadRestProxy
  • Вызов: CCrmLeadRestProxy::innerAdd
protected function innerAdd(&$fields, &$errors, array $params = null)
{
	$isImportMode = is_array($params) && isset($params['IMPORT']) && $params['IMPORT'];

	if(!($isImportMode ? CCrmLead::CheckImportPermission() : CCrmLead::CheckCreatePermission()))
	{
		$errors[] = 'Access denied.';
		return false;
	}

	$diskQuotaRestriction = \Bitrix\Crm\Restriction\RestrictionManager::getDiskQuotaRestriction();
	if (!$diskQuotaRestriction->hasPermission())
	{
		$errors[] = $diskQuotaRestriction->getErrorMessage();
		return false;
	}

	$entity = self::getEntity();
	$options = [];
	if(!$this->isRequiredUserFieldCheckEnabled())
	{
		$options['DISABLE_REQUIRED_USER_FIELD_CHECK'] = true;
	}
	if(is_array($params) && isset($params['REGISTER_SONET_EVENT']))
	{
		$options['REGISTER_SONET_EVENT'] = mb_strtoupper($params['REGISTER_SONET_EVENT']) === 'Y';
	}
	if($isImportMode)
	{
		$options['ALLOW_SET_SYSTEM_FIELDS'] = true;
		$fields['PERMISSION'] = 'IMPORT';
	}
	$result = $entity->Add($fields, true, $options);
	if($result <= 0)
	{
		$errors[] = $entity->LAST_ERROR;
	}
	else
	{
		self::traceEntity(\CCrmOwnerType::Lead, $result, $fields);
		if (self::isBizProcEnabled() && !$isImportMode)
		{
			CCrmBizProcHelper::AutoStartWorkflows(
				CCrmOwnerType::Lead,
				$result,
				CCrmBizProcEventType::Create,
				$errors
			);
		}
		//Region automation
		$starter = new \Bitrix\Crm\Automation\Starter(\CCrmOwnerType::Lead, $result);
		$starter->setContextToRest()->setUserId($this->getCurrentUserID())->runOnAdd();
		//End region
	}

	return $result;
}

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