Пример #1
0
 public function copyInfoAction()
 {
     $transactionId = time();
     $pasteJobs = array();
     Session::useSession(function ($session) use($transactionId) {
         $session->{$transactionId} = array("idMapping" => array());
     }, "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[] = array(array("url" => "/admin/document/copy", "params" => array("sourceId" => $this->getParam("sourceId"), "targetId" => $this->getParam("targetId"), "type" => "child", "enableInheritance" => $this->getParam("enableInheritance"), "transactionId" => $transactionId, "saveParentId" => true)));
         $childIds = array();
         if ($document->hasChilds()) {
             // get amount of childs
             $list = new Document\Listing();
             $list->setCondition("path LIKE '" . $document->getFullPath() . "/%'");
             $list->setOrderKey("LENGTH(path)", false);
             $list->setOrder("ASC");
             $childIds = $list->loadIdList();
             if (count($childIds) > 0) {
                 foreach ($childIds as $id) {
                     $pasteJobs[] = array(array("url" => "/admin/document/copy", "params" => array("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[] = array(array("url" => "/admin/document/copy-rewrite-ids", "params" => array("transactionId" => $transactionId, "enableInheritance" => $this->getParam("enableInheritance"), "_dc" => uniqid())));
             }
         }
     } else {
         if ($this->getParam("type") == "child" || $this->getParam("type") == "replace") {
             // the object itself is the last one
             $pasteJobs[] = array(array("url" => "/admin/document/copy", "params" => array("sourceId" => $this->getParam("sourceId"), "targetId" => $this->getParam("targetId"), "type" => $this->getParam("type"), "enableInheritance" => $this->getParam("enableInheritance"), "transactionId" => $transactionId)));
         }
     }
     $this->_helper->json(array("pastejobs" => $pasteJobs));
 }
Пример #2
0
 public static function getUniqueKey($item, $nr = 0)
 {
     $list = new Listing();
     $list->setUnpublished(true);
     $key = Element\Service::getValidKey($item->getKey(), "document");
     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 document to determine a unique Key");
     }
     if (!$item->getId()) {
         $list->setCondition('parentId = ? AND `key` = ? ', [$parent->getId(), $key]);
     } else {
         $list->setCondition('parentId = ? AND `key` = ? AND id != ? ', [$parent->getId(), $key, $item->getId()]);
     }
     $check = $list->loadIdList();
     if (!empty($check)) {
         $nr++;
         $key = self::getUniqueKey($item, $nr);
     }
     return $key;
 }