CBPRestActivity::onExternalEvent

  1. Bitrix24 API (v. 23.675.0)
  2. bizproc
  3. CBPRestActivity
  4. onExternalEvent
  • Модуль: bizproc
  • Путь к файлу: ~/bitrix/modules/bizproc/classes/general/restactivity.php
  • Класс: CBPRestActivity
  • Вызов: CBPRestActivity::onExternalEvent
public function onExternalEvent($eventParameters = [])
{
	if ($this->executionStatus === CBPActivityExecutionStatus::Closed)
	{
		return;
	}

	$onAgent = (array_key_exists('SchedulerService', $eventParameters) && $eventParameters['SchedulerService'] === 'OnAgent');
	if ($onAgent)
	{
		$this->IsTimeout = 1;
		$this->Unsubscribe($this);
		$this->workflow->CloseActivity($this);

		return;
	}

	if ($this->eventId !== (string)$eventParameters['EVENT_ID'])
	{
		return;
	}

	$this->WriteToTrackingService(
		!empty($eventParameters['LOG_MESSAGE']) && is_string($eventParameters['LOG_MESSAGE'])
			? $eventParameters['LOG_MESSAGE']
			: Loc::getMessage('BPRA_DEFAULT_LOG_MESSAGE')
	);

	if (!empty($eventParameters['RETURN_VALUES']))
	{
		$activityData = self::getRestActivityData();
		$whiteList = array();
		if (!empty($activityData['RETURN_PROPERTIES']))
		{
			foreach ($activityData['RETURN_PROPERTIES'] as $name => $property)
			{
				$whiteList[mb_strtoupper($name)] = $name;
			}
		}

		/** @var CBPDocumentService $documentService */
		$documentService = $this->workflow->GetService('DocumentService');
		$eventParameters['RETURN_VALUES'] = array_change_key_case(
			(array)$eventParameters['RETURN_VALUES'],
			CASE_UPPER
		);
		foreach ($eventParameters['RETURN_VALUES'] as $name => $value)
		{
			if (!isset($whiteList[$name]))
			{
				continue;
			}

			$property = $activityData['RETURN_PROPERTIES'][$whiteList[$name]];
			if ($property && $value)
			{
				$property = static::normalizeProperty($property);
				$fieldTypeObject = $documentService->getFieldTypeObject($this->GetDocumentType(), $property);
				if ($fieldTypeObject)
				{
					$fieldTypeObject->setDocumentId($this->GetDocumentId());
					$value = $fieldTypeObject->internalizeValue($this->GetName(), $value);
				}

				$map = $this->getDebugInfo(
					[$name => $value],
					[$name => $property]
				);
				$this->writeDebugInfo($map);
			}

			$this->__set($whiteList[$name], $value);
		}
	}

	if (empty($eventParameters['LOG_ACTION']))
	{
		$this->Unsubscribe($this);
		$this->workflow->CloseActivity($this);
	}
}

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