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