• Модуль: rpa
  • Путь к файлу: ~/bitrix/modules/rpa/lib/command.php
  • Класс: BitrixRpaCommand
  • Вызов: Command::run
public function run(): Result
{
	$result = new Result();

	if($result->isSuccess() && $this->isCheckAccessEnabled())
	{
		$checkAccessResult = $this->checkAccess();
		if(!$checkAccessResult->isSuccess())
		{
			$result->addErrors($checkAccessResult->getErrors());
		}
	}

	if($result->isSuccess() && $this->isCheckStageEnabled())
	{
		$checkStageResult = $this->checkStage();
		if(!$checkStageResult->isSuccess())
		{
			$result->addErrors($checkStageResult->getErrors());
		}
	}

	if($result->isSuccess() && $this->isCheckFieldsEnabled())
	{
		$checkFieldsResult = $this->checkFields();
		if(!$checkFieldsResult->isSuccess())
		{
			$result->addErrors($checkFieldsResult->getErrors());
		}
	}

	if($result->isSuccess() && $this->isCheckTasksEnabled())
	{
		$checkTasksResult = $this->checkTasks();
		if(!$checkTasksResult->isSuccess())
		{
			$result->addErrors($checkTasksResult->getErrors());
		}
	}

	// some task could intercept execution - in this case there is not need to proceed
	if($this->isTerminated())
	{
		$this->item->fill();
		return $result;
	}

	if($result->isSuccess() && $this->isSaveToHistoryEnabled())
	{
		$historyRecord = ItemHistory::createByItem($this->item);
		if($this->scope)
		{
			$historyRecord->setScope($this->scope);
		}
	}

	$isDropSort = $this->item->isChanged('STAGE_ID');

	if($result->isSuccess())
	{
		$result = $this->save();
	}

	if($result->isSuccess() && $isDropSort)
	{
		ItemSortTable::removeForItem($this->item->getType()->getId(), $this->item->getId());
	}

	if($result->isSuccess() && $this->isSaveToHistoryEnabled())
	{
		/** @noinspection PhpUndefinedVariableInspection */
		$historyResult = $this->saveToHistory($historyRecord);
		if($historyResult->isSuccess())
		{
			$timeline = $historyRecord->createTimelineRecord();
			if($timeline)
			{
				$timelineResult = $timeline->save();
				if($timelineResult->isSuccess())
				{
					$this->sendTimelinePullEvent($timeline);
				}
				else
				{
					$result->addErrors($timelineResult->getErrors());
				}
			}
		}
		else
		{
			$result->addErrors($historyResult->getErrors());
		}
	}

	if($result->isSuccess())
	{
		$this->sendPullEvent();
	}

	if($result->isSuccess() && $this->isAutomationEnabled())
	{
		$eventType = $this->getItemEntityEventName('OnAfterUpdate');
		$eventId = EventManager::getInstance()->addEventHandler(
			$this->item->sysGetEntity()->getModule(),
			$eventType,
			[$this, 'updateItemFromUpdateEvent']
		);
		$automationResult = $this->runAutomation();
		if(!$automationResult->isSuccess())
		{
			$result->addErrors($automationResult->getErrors());
		}
		EventManager::getInstance()->removeEventHandler(Driver::MODULE_ID, $eventType, $eventId);
	}

	return $result;
}