• Модуль: bizproc
  • Путь к файлу: ~/bitrix/modules/bizproc/lib/automation/engine/template.php
  • Класс: BitrixBizprocAutomationEngineTemplate
  • Вызов: Template::validateUpdatedRobots
private function validateUpdatedRobots(array $robots, CBPWorkflowTemplateUser $user): ErrorCollection
{
	$errors = new ErrorCollection();
	$loader = CBPWorkflowTemplateLoader::GetLoader();
	$originalRobots = $this->getRobots();

	$isSameRobot = function ($lhsRobot, $rhsRobot) {
		return $lhsRobot->getName() === $rhsRobot->getName();
	};

	/**@var Robot $robot */
	foreach ($robots as $robot)
	{
		if (is_array($robot))
		{
			$robot = new Robot($robot);
		}
		if (!($robot instanceof Robot))
		{
			$errors->setError(new Error('Robots array is incorrect'));
		}
		if (!$errors->isEmpty())
		{
			break;
		}

		$indexOfFoundRobot = -1;
		foreach ($originalRobots as $index => $originalRobot)
		{
			if ($isSameRobot($robot, $originalRobot))
			{
				$indexOfFoundRobot = $index;
				break;
			}
		}

		if ($indexOfFoundRobot < 0 || !$this->areRobotsEqual($robot, $originalRobots[$indexOfFoundRobot]))
		{
			if ($robot->isActivated())
			{
				$sequence = $this->convertRobotToSequenceActivity($robot);
				foreach ($loader->ValidateTemplate($sequence, $user) as $rawError)
				{
					$errors->setError(new Error(trim($rawError['message'])));
				}
			}
			unset($originalRobots[$indexOfFoundRobot]);
		}
	}

	return $errors;
}