public function copyInfoAction()
{
$transactionId = time();
$pasteJobs = [];
Session::useSession(function ($session) use($transactionId) {
$session->{$transactionId} = ["idMapping" => []];
}, "pimcore_copy");
if ($this->getParam("type") == "recursive" || $this->getParam("type") == "recursive-update-references") {
$document = Document::getById($this->getParam("sourceId"));
// first of all the new parent
$pasteJobs[] = [["url" => "/admin/document/copy", "params" => ["sourceId" => $this->getParam("sourceId"), "targetId" => $this->getParam("targetId"), "type" => "child", "enableInheritance" => $this->getParam("enableInheritance"), "transactionId" => $transactionId, "saveParentId" => true, "resetIndex" => true]]];
$childIds = [];
if ($document->hasChilds()) {
// get amount of childs
$list = new Document\Listing();
$list->setCondition("path LIKE '" . $document->getRealFullPath() . "/%'");
$list->setOrderKey("LENGTH(path)", false);
$list->setOrder("ASC");
$childIds = $list->loadIdList();
if (count($childIds) > 0) {
foreach ($childIds as $id) {
$pasteJobs[] = [["url" => "/admin/document/copy", "params" => ["sourceId" => $id, "targetParentId" => $this->getParam("targetId"), "sourceParentId" => $this->getParam("sourceId"), "type" => "child", "enableInheritance" => $this->getParam("enableInheritance"), "transactionId" => $transactionId]]];
}
}
}
// add id-rewrite steps
if ($this->getParam("type") == "recursive-update-references") {
for ($i = 0; $i < count($childIds) + 1; $i++) {
$pasteJobs[] = [["url" => "/admin/document/copy-rewrite-ids", "params" => ["transactionId" => $transactionId, "enableInheritance" => $this->getParam("enableInheritance"), "_dc" => uniqid()]]];
}
}
} elseif ($this->getParam("type") == "child" || $this->getParam("type") == "replace") {
// the object itself is the last one
$pasteJobs[] = [["url" => "/admin/document/copy", "params" => ["sourceId" => $this->getParam("sourceId"), "targetId" => $this->getParam("targetId"), "type" => $this->getParam("type"), "enableInheritance" => $this->getParam("enableInheritance"), "transactionId" => $transactionId, "resetIndex" => $this->getParam("type") == "child"]]];
}
$this->_helper->json(["pastejobs" => $pasteJobs]);
}