- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/item/replicator.php
- Класс: BitrixTasksItemReplicator
- Вызов: Replicator::produceFrom
public function produceFrom($sourceId, $userId = 0, array $parameters = array())
{
$result = new ReplicatorResult();
$converter = $this->getConverter();
$itemClass = static::getItemClass(); // todo: check $itemClass here
$targetClass = $converter->getTargetItemClass();
$targetClass::enterBatchState();
// create ROOT item
$srcInstance = $itemClass::getInstance($sourceId, $userId);
$dstInstance = null;
$conversionResult = $srcInstance->transformWith($converter);
if($conversionResult->isSuccess()) // was able to produce an item
{
$dstInstance = $conversionResult->getInstance();
$dstInstance->mixData($parameters);
$saveResult = $dstInstance->save();
if(!$saveResult->isSuccess()) // but was not able to save it
{
$dstInstance->abortTransformation($this->getConverter()); // rolling back possible temporal data creation
}
$result->setInstance($dstInstance);
// there could be warnings
$result->getErrors()->load($saveResult->getErrors());
}
else
{
$result->getErrors()->load($conversionResult->getErrors());
}
// create SUB items
if($dstInstance && $result->isSuccess())
{
// the result of creating sub-items
$subResult = $this->produceSubItemsFrom($srcInstance, $dstInstance, $parameters, $userId);
$sIResults = $subResult->getData();
// save sub-item collection
$result->setSubInstanceResult($sIResults);
// get all errors from $subResult, but as warnings
$result->loadErrors($subResult->getErrors()->transform(array('TYPE' => Error::TYPE_WARNING)));
$this->doPostActions($srcInstance, $parameters);
}
$targetClass::leaveBatchState();
return $result;
}