public function copyInfoAction()
 {
     $transactionId = time();
     $pasteJobs = array();
     Tool\Session::useSession(function ($session) use($transactionId) {
         $session->{$transactionId} = array();
     }, "pimcore_copy");
     if ($this->getParam("type") == "recursive") {
         $asset = Asset::getById($this->getParam("sourceId"));
         // first of all the new parent
         $pasteJobs[] = array(array("url" => "/admin/asset/copy", "params" => array("sourceId" => $this->getParam("sourceId"), "targetId" => $this->getParam("targetId"), "type" => "child", "transactionId" => $transactionId, "saveParentId" => true)));
         if ($asset->hasChilds()) {
             // get amount of childs
             $list = new Asset\Listing();
             $list->setCondition("path LIKE '" . $asset->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/asset/copy", "params" => array("sourceId" => $id, "targetParentId" => $this->getParam("targetId"), "sourceParentId" => $this->getParam("sourceId"), "type" => "child", "transactionId" => $transactionId)));
                 }
             }
         }
     } else {
         if ($this->getParam("type") == "child" || $this->getParam("type") == "replace") {
             // the object itself is the last one
             $pasteJobs[] = array(array("url" => "/admin/asset/copy", "params" => array("sourceId" => $this->getParam("sourceId"), "targetId" => $this->getParam("targetId"), "type" => $this->getParam("type"), "transactionId" => $transactionId)));
         }
     }
     $this->_helper->json(array("pastejobs" => $pasteJobs));
 }
Пример #2
0
 /**
  * @param $item \Pimcore\Model\Asset
  * @param int $nr
  * @return string
  * @throws \Exception
  */
 public static function getUniqueKey($item, $nr = 0)
 {
     $list = new Listing();
     $key = \Pimcore\File::getValidFilename($item->getKey());
     if (!$key) {
         throw new \Exception("No item key set.");
     }
     if ($nr) {
         if ($item->getType() == 'folder') {
             $key = $key . '_' . $nr;
         } else {
             $keypart = substr($key, 0, strrpos($key, '.'));
             $extension = str_replace($keypart, '', $key);
             $key = $keypart . '_' . $nr . $extension;
         }
     }
     $parent = $item->getParent();
     if (!$parent) {
         throw new \Exception("You have to set a parent folder to determine a unique Key");
     }
     if (!$item->getId()) {
         $list->setCondition('parentId = ? AND `filename` = ? ', [$parent->getId(), $key]);
     } else {
         $list->setCondition('parentId = ? AND `filename` = ? AND id != ? ', [$parent->getId(), $key, $item->getId()]);
     }
     $check = $list->loadIdList();
     if (!empty($check)) {
         $nr++;
         $key = self::getUniqueKey($item, $nr);
     }
     return $key;
 }