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)); }
public static function getUniqueKey($item, $nr = 0) { $list = new Listing(); $list->setUnpublished(true); $key = \Pimcore\File::getValidFilename($item->getKey()); if (!$key) { throw new \Exception("No item key set."); } if ($nr) { $key = $key . '_' . $nr; } $parent = $item->getParent(); if (!$parent) { throw new \Exception("You have to set a parent Object to determine a unique Key"); } if (!$item->getId()) { $list->setCondition('o_parentId = ? AND `o_key` = ? ', array($parent->getId(), $key)); } else { $list->setCondition('o_parentId = ? AND `o_key` = ? AND o_id != ? ', array($parent->getId(), $key, $item->getId())); } $check = $list->loadIdList(); if (!empty($check)) { $nr++; $key = self::getUniqueKey($item, $nr); } return $key; }