- Модуль: bizproc
- Путь к файлу: ~/bitrix/modules/bizproc/lib/automation/engine/templatestunnel.php
- Класс: BitrixBizprocAutomationEngineTemplatesTunnel
- Вызов: TemplatesTunnel::copyRobots
public function copyRobots(array $robotNames, int $userId): Result
{
if ($this->srcTemplate->isExternalModified() || $this->dstTemplate->isExternalModified())
{
$result = new Result();
$result->setData([
'copied' => [],
'denied' => [],
]);
return $result;
}
$copyingRobots = $this->srcTemplate->getRobotsByNames($robotNames);
$partitioned = $this->partitionByDescription($this->dstTemplate->getDocumentType(), $copyingRobots);
$newRobots = [];
/** @var Robot $robot */
foreach ($partitioned['available'] as $robot)
{
$draftRobot = new Robot([
'Name' => Robot::generateName(),
'Type' => $robot->getType(),
'Activated' => $robot->isActivated() ? 'Y' : 'N',
'Properties' => $robot->getProperties(),
]);
$delayInterval = $robot->getDelayInterval();
$condition = $robot->getCondition();
if ($delayInterval && !$delayInterval->isNow())
{
$draftRobot->setDelayInterval($delayInterval);
$draftRobot->setDelayName(Robot::generateName());
}
if ($condition)
{
$draftRobot->setCondition($robot->getCondition());
}
if ($robot->isExecuteAfterPrevious())
{
$draftRobot->setExecuteAfterPrevious();
}
$newRobots[] = $draftRobot;
}
if ($newRobots)
{
$result = $this->dstTemplate->save(
array_merge($this->dstTemplate->getRobots(), $newRobots),
$userId
);
}
else
{
$result = new Result();
}
if ($result->isSuccess())
{
$result->setData([
'copied' => $partitioned['available'],
'denied' => $partitioned['unavailable'],
]);
}
return $result;
}