- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/copy/entitycopier.php
- Класс: BitrixMainCopyEntityCopier
- Вызов: EntityCopier::copy
public function copy(ContainerCollection $containerCollection)
{
$this->result->setData([]);
$result = [];
foreach ($containerCollection as $container)
{
$entityId = $this->getEntityIdToCopy($container);
if (!$entityId)
{
continue;
}
$fields = $this->getFields($container, $entityId);
if (empty($fields))
{
$result = $this->addToResultByName($result, [$entityId => false], $this->implementerName);
}
else
{
$dictionary = $this->getDictionary($container, $fields);
$fields = $this->prepareFieldsToCopy($container, $fields);
$copiedEntityId = $this->addEntity($container, $fields);
if (!$copiedEntityId)
{
$result = $this->addToResultByName($result, [$entityId => false], $this->implementerName);
$this->result->addErrors($this->implementer->getErrors());
continue;
}
$copyChildrenResult = $this->copyChildren($container, $entityId, $copiedEntityId);
if ($copyChildrenResult->getErrors())
{
$this->result->addErrors($copyChildrenResult->getErrors());
}
$result = $this->addToResult($result, $copyChildrenResult->getData());
$result = $this->addToResultByName($result, [$entityId => $copiedEntityId], $this->implementerName);
$this->setCopiedEntityId($container, $copiedEntityId);
$this->setDictionary($container, $dictionary);
}
}
$this->startCopyEntities($containerCollection);
$result = $this->addToResult($result, $this->result->getData());
$this->result->setData($result);
return $this->result;
}