• Модуль: rpa
  • Путь к файлу: ~/bitrix/modules/rpa/lib/controller/stage.php
  • Класс: BitrixRpaControllerStage
  • Вызов: Stage::processPossibleNextStages
protected function processPossibleNextStages(BitrixRpaModelStage $stage, array $possibleNextStages): Result
{
	$result = new Result();

	$currentSettings = StageToStageTable::getList([
		'filter' => [
			'=STAGE_ID' => $stage->getId(),
		],
	])->fetchAll();

	$skipAdding = [];
	foreach($currentSettings as $currentSetting)
	{
		$isFound = false;
		foreach($possibleNextStages as $id)
		{
			if((int) $currentSetting['STAGE_TO_ID'] === (int) $id)
			{
				$isFound = true;
				break;
			}
		}
		if(!$isFound)
		{
			StageToStageTable::delete($currentSetting['ID']);
		}
		else
		{
			$skipAdding[$currentSetting['STAGE_TO_ID']] = $currentSetting['STAGE_TO_ID'];
		}
	}

	foreach($possibleNextStages as $id)
	{
		if(!isset($skipAdding[$id]))
		{
			$addResult = StageToStageTable::add([
				'STAGE_ID' => $stage->getId(),
				'STAGE_TO_ID' => $id,
			]);
			if($addResult->isSuccess())
			{
				$result->addErrors($addResult->getErrors());
			}
		}
	}

	return $result;
}