Task::onTriggered

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. Task
  4. onTriggered
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/activity/provider/tasks/task.php
  • Класс: Bitrix\Crm\Activity\Provider\Tasks\Task
  • Вызов: Task::onTriggered
static function onTriggered(int $taskId, array &$currentTaskFields, array &$previousTaskFields): bool
{
	if ($taskId <= 0 || !Loader::includeModule('tasks'))
	{
		return false;
	}

	$itemIterator = \CTasks::getByID($taskId, false);
	$task = $itemIterator->fetch();
	if (!$task)
	{
		return false;
	}

	$isStatusChanged = (isset($currentTaskFields['STATUS'])
		&& (string)$currentTaskFields['STATUS']
		!== (string)$previousTaskFields['STATUS']);
	$listIterator = \CCrmActivity::getList(
		[],
		[
			'=TYPE_ID' => \CCrmActivityType::Provider,
			'=PROVIDER_ID' => self::getId(),
			// '=PROVIDER_TYPE_ID' => self::getProviderTypeId(),
			'=ASSOCIATED_ENTITY_ID' => $taskId,
			'CHECK_PERMISSIONS' => 'N',
		]
	);

	$isFound = false;
	$taskBindings = [];

	while ($activity = $listIterator->fetch())
	{
		$isFound = true;
		self::legacySetBindings($task, $activity);
		if (isset($activity['BINDINGS']) && count($activity['BINDINGS']) > 0)
		{
			\CCrmActivity::update($activity['ID'], $activity, false, true, self::UPDATE_OPTIONS);
			\CCrmLiveFeed::syncTaskEvent($activity, $task);
			$taskBindings = $activity['BINDINGS'];
		}
	}

	if (!$isFound)
	{
		return true;
	}

	if ($isStatusChanged && $taskBindings)
	{
		TaskStatusTrigger::execute($taskBindings, ['TASK' => $task]);
	}

	return true;
}

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