- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/util/replicator/task/fromtask.php
- Класс: BitrixTasksUtilReplicatorTaskFromTask
- Вызов: FromTask::produceSub
public function produceSub($source, $destination, array $parameters = array(), $userId = 0)
{
$result = new Result();
Task::enterBatchState();
if(!$userId)
{
$userId = User::getId();
}
$source = $this->getSourceInstance($source, $userId);
$destination = $this->getDestinationInstance($destination, $userId);
$created = new Collection();
$data = $this->getSubItemData($source->getId(), $result, $userId);
if($result->isSuccess() && !empty($data)) // has sub-tasks
{
$srcToDst = array($source->getId() => $destination->getId());
$notSaved = array();
foreach($data['TREE'] as $childId => $parentId)
{
if(!isset($parameters['COPY_DESTINATION_ITEM']) && $childId == $destination->getId()) // do not copy self one more time as a sub-task
{
continue;
}
if(isset($notSaved[$parentId])) // if parent was not saved, child can not be saved too
{
$notSaved[$childId] = true;
continue;
}
$saveResult = $this->saveItemFromSource($data['DATA'][$childId], ['PARENT_ID' => $srcToDst[$parentId]], $userId);
if($saveResult->isSuccess())
{
$srcToDst[$childId] = $saveResult->getInstance()->getId();
}
else
{
$notSaved[$childId] = true;
}
$created->push($saveResult);
}
if(!empty($notSaved))
{
$result->addError('SUB_ITEMS_CREATION_FAILURE', 'Some of the sub-tasks was not properly created');
}
}
Task::leaveBatchState();
$result->setData($created);
return $result;
}