• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/integration/bizproc/automation/rest.php
  • Класс: BitrixTasksIntegrationBizprocAutomationRest
  • Вызов: Rest::addTrigger
static function addTrigger(array $params, $server)
{
	/** @var CRestServer $server */
	$clientId = $server ? $server->getClientId() : null;

	if (!$clientId)
	{
		throw new AccessException('Application context required');
	}

	$fields = array_change_key_case($params[0], CASE_UPPER);

	self::validateTriggerCode($fields['CODE']);
	self::validateTriggerName($fields['NAME']);

	$app = AppTable::getList(
		array(
			'filter' => array(
				'=CLIENT_ID' => $clientId
			),
			'select' => array('ID')
		)
	)->fetch();

	$exists = TriggerEntityAppTable::getList(array(
		'filter' => array(
			'=APP_ID' => $app['ID'],
			'=CODE' => $fields['CODE']
		),
		'select' => array('ID')
	))->fetch();

	if ($exists)
	{
		$updateResult = TriggerEntityAppTable::update($exists['ID'], array('NAME' => $fields['NAME']));
		return [$updateResult->isSuccess()];
	}

	$fields = array(
		'APP_ID' => $app['ID'],
		'CODE' => $fields['CODE'],
		'NAME' => $fields['NAME'],
		'DATE_CREATE' => new DateTime()
	);

	$addResult = TriggerEntityAppTable::add($fields);

	return [$addResult->isSuccess()];
}