writeClose() public static method

public static writeClose ( )
 public function copyAction()
 {
     $success = false;
     $message = "";
     $sourceId = intval($this->getParam("sourceId"));
     $source = Object::getById($sourceId);
     $session = Tool\Session::get("pimcore_copy");
     $targetId = intval($this->getParam("targetId"));
     if ($this->getParam("targetParentId")) {
         $sourceParent = Object::getById($this->getParam("sourceParentId"));
         // this is because the key can get the prefix "_copy" if the target does already exists
         if ($session->{$this->getParam("transactionId")}["parentId"]) {
             $targetParent = Object::getById($session->{$this->getParam("transactionId")}["parentId"]);
         } else {
             $targetParent = Object::getById($this->getParam("targetParentId"));
         }
         $targetPath = preg_replace("@^" . $sourceParent->getFullPath() . "@", $targetParent . "/", $source->getPath());
         $target = Object::getByPath($targetPath);
     } else {
         $target = Object::getById($targetId);
     }
     if ($target->isAllowed("create")) {
         $source = Object::getById($sourceId);
         if ($source != null) {
             try {
                 if ($this->getParam("type") == "child") {
                     $newObject = $this->_objectService->copyAsChild($target, $source);
                     $session->{$this->getParam("transactionId")}["idMapping"][(int) $source->getId()] = (int) $newObject->getId();
                     // this is because the key can get the prefix "_copy" if the target does already exists
                     if ($this->getParam("saveParentId")) {
                         $session->{$this->getParam("transactionId")}["parentId"] = $newObject->getId();
                         Tool\Session::writeClose();
                     }
                 } elseif ($this->getParam("type") == "replace") {
                     $this->_objectService->copyContents($target, $source);
                 }
                 $success = true;
             } catch (\Exception $e) {
                 \Logger::err($e);
                 $success = false;
                 $message = $e->getMessage() . " in object " . $source->getFullPath() . " [id: " . $source->getId() . "]";
             }
         } else {
             \Logger::error("could not execute copy/paste, source object with id [ {$sourceId} ] not found");
             $this->_helper->json(array("success" => false, "message" => "source object not found"));
         }
     } else {
         \Logger::error("could not execute copy/paste because of missing permissions on target [ " . $targetId . " ]");
         $this->_helper->json(array("error" => false, "message" => "missing_permission"));
     }
     $this->_helper->json(array("success" => $success, "message" => $message));
 }
 public function copyAction()
 {
     $success = false;
     $sourceId = intval($this->getParam("sourceId"));
     $source = Asset::getById($sourceId);
     $session = Tool\Session::get("pimcore_copy");
     $targetId = intval($this->getParam("targetId"));
     if ($this->getParam("targetParentId")) {
         $sourceParent = Asset::getById($this->getParam("sourceParentId"));
         // this is because the key can get the prefix "_copy" if the target does already exists
         if ($session->{$this->getParam("transactionId")}["parentId"]) {
             $targetParent = Asset::getById($session->{$this->getParam("transactionId")}["parentId"]);
         } else {
             $targetParent = Asset::getById($this->getParam("targetParentId"));
         }
         $targetPath = preg_replace("@^" . $sourceParent->getFullPath() . "@", $targetParent . "/", $source->getPath());
         $target = Asset::getByPath($targetPath);
     } else {
         $target = Asset::getById($targetId);
     }
     if ($target->isAllowed("create")) {
         $source = Asset::getById($sourceId);
         if ($source != null) {
             if ($this->getParam("type") == "child") {
                 $newAsset = $this->_assetService->copyAsChild($target, $source);
                 // this is because the key can get the prefix "_copy" if the target does already exists
                 if ($this->getParam("saveParentId")) {
                     $session->{$this->getParam("transactionId")}["parentId"] = $newAsset->getId();
                 }
             } else {
                 if ($this->getParam("type") == "replace") {
                     $this->_assetService->copyContents($target, $source);
                 }
             }
             $success = true;
         } else {
             \Logger::debug("prevended copy/paste because asset with same path+key already exists in this location");
         }
     } else {
         \Logger::error("could not execute copy/paste because of missing permissions on target [ " . $targetId . " ]");
         $this->_helper->json(array("error" => false, "message" => "missing_permission"));
     }
     Tool\Session::writeClose();
     $this->_helper->json(array("success" => $success));
 }
示例#3
0
 /**
  *
  */
 public function saveToSessionAction()
 {
     if ($this->getParam("id")) {
         $key = "document_" . $this->getParam("id");
         $session = Session::get("pimcore_documents");
         if (!($document = $session->{$key})) {
             $document = Model\Document::getById($this->getParam("id"));
             $document = $this->getLatestVersion($document);
         }
         // set _fulldump otherwise the properties will be removed because of the session-serialize
         $document->_fulldump = true;
         $this->setValuesToDocument($document);
         $session->{$key} = $document;
         Session::writeClose();
     }
     $this->_helper->json(array("success" => true));
 }
 public function copyAction()
 {
     $success = false;
     $sourceId = intval($this->getParam("sourceId"));
     $source = Document::getById($sourceId);
     $session = Session::get("pimcore_copy");
     $targetId = intval($this->getParam("targetId"));
     if ($this->getParam("targetParentId")) {
         $sourceParent = Document::getById($this->getParam("sourceParentId"));
         // this is because the key can get the prefix "_copy" if the target does already exists
         if ($session->{$this->getParam("transactionId")}["parentId"]) {
             $targetParent = Document::getById($session->{$this->getParam("transactionId")}["parentId"]);
         } else {
             $targetParent = Document::getById($this->getParam("targetParentId"));
         }
         $targetPath = preg_replace("@^" . $sourceParent->getFullPath() . "@", $targetParent . "/", $source->getPath());
         $target = Document::getByPath($targetPath);
     } else {
         $target = Document::getById($targetId);
     }
     if ($target instanceof Document) {
         if ($target->isAllowed("create")) {
             if ($source != null) {
                 if ($this->getParam("type") == "child") {
                     $enableInheritance = $this->getParam("enableInheritance") == "true" ? true : false;
                     $resetIndex = $this->getParam("resetIndex") == "true" ? true : false;
                     $newDocument = $this->_documentService->copyAsChild($target, $source, $enableInheritance, $resetIndex);
                     $session->{$this->getParam("transactionId")}["idMapping"][(int) $source->getId()] = (int) $newDocument->getId();
                     // this is because the key can get the prefix "_copy" if the target does already exists
                     if ($this->getParam("saveParentId")) {
                         $session->{$this->getParam("transactionId")}["parentId"] = $newDocument->getId();
                     }
                     Session::writeClose();
                 } elseif ($this->getParam("type") == "replace") {
                     $this->_documentService->copyContents($target, $source);
                 }
                 $success = true;
             } else {
                 \Logger::error("prevended copy/paste because document with same path+key already exists in this location");
             }
         } else {
             \Logger::error("could not execute copy/paste because of missing permissions on target [ " . $targetId . " ]");
             $this->_helper->json(array("success" => false, "message" => "missing_permission"));
         }
     }
     $this->_helper->json(array("success" => $success));
 }