예제 #1
0
 public function correctPath()
 {
     // set path
     if ($this->getId() != 1) {
         // not for the root node
         $parent = Document::getById($this->getParentId());
         if ($parent) {
             $this->setPath(str_replace("//", "/", $parent->getFullPath() . "/"));
         } else {
             // parent document doesn't exist anymore, so delete this document
             //$this->delete();
             // parent document doesn't exist anymore, set the parent to to root
             $this->setParentId(1);
             $this->setPath("/");
         }
     }
     if (Document_Service::pathExists($this->getFullPath())) {
         $duplicate = Document::getByPath($this->getFullPath());
         if ($duplicate instanceof Document and $duplicate->getId() != $this->getId()) {
             throw new Exception("Duplicate full path [ " . $this->getFullPath() . " ] - cannot create document");
         }
     }
 }
 public function addAction()
 {
     $success = false;
     // check for permission
     $parentDocument = Document::getById(intval($this->_getParam("parentId")));
     if ($parentDocument->isAllowed("create")) {
         $intendedPath = $parentDocument->getFullPath() . "/" . $this->_getParam("key");
         if (!Document_Service::pathExists($intendedPath)) {
             $createValues = array("userOwner" => $this->getUser()->getId(), "userModification" => $this->getUser()->getId(), "published" => false);
             $createValues["key"] = $this->_getParam("key");
             // check for a docType
             if ($this->_getParam("docTypeId") && is_numeric($this->_getParam("docTypeId"))) {
                 $docType = Document_DocType::getById(intval($this->_getParam("docTypeId")));
                 $createValues["template"] = $docType->getTemplate();
                 $createValues["controller"] = $docType->getController();
                 $createValues["action"] = $docType->getAction();
                 $createValues["module"] = $docType->getModule();
             } else {
                 if ($this->_getParam("type") == "page" || $this->_getParam("type") == "snippet" || $this->_getParam("type") == "email") {
                     $createValues["controller"] = Pimcore_Config::getSystemConfig()->documents->default_controller;
                     $createValues["action"] = Pimcore_Config::getSystemConfig()->documents->default_action;
                 }
             }
             switch ($this->_getParam("type")) {
                 case "page":
                     $document = Document_Page::create($this->_getParam("parentId"), $createValues);
                     $success = true;
                     break;
                 case "snippet":
                     $document = Document_Snippet::create($this->_getParam("parentId"), $createValues);
                     $success = true;
                     break;
                 case "email":
                     //ckogler
                     $document = Document_Email::create($this->_getParam("parentId"), $createValues);
                     $success = true;
                     break;
                 case "link":
                     $document = Document_Link::create($this->_getParam("parentId"), $createValues);
                     $success = true;
                     break;
                 case "hardlink":
                     $document = Document_Hardlink::create($this->_getParam("parentId"), $createValues);
                     $success = true;
                     break;
                 case "folder":
                     $document = Document_Folder::create($this->_getParam("parentId"), $createValues);
                     $document->setPublished(true);
                     try {
                         $document->save();
                         $success = true;
                     } catch (Exception $e) {
                         $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
                     }
                     break;
                 default:
                     Logger::debug("Unknown document type, can't add [ " . $this->_getParam("type") . " ] ");
                     break;
             }
         } else {
             Logger::debug("prevented adding a document because document with same path+key [ {$intendedPath} ] already exists");
         }
     } else {
         Logger::debug("prevented adding a document because of missing permissions");
     }
     if ($success) {
         $this->_helper->json(array("success" => $success, "id" => $document->getId(), "type" => $document->getType()));
     } else {
         $this->_helper->json(array("success" => $success));
     }
 }
예제 #3
0
 /**
  * @static
  * @param $type
  * @param $path
  * @return bool
  */
 public static function pathExists($type, $path)
 {
     if ($type == "asset") {
         return Asset_Service::pathExists($path);
     } else {
         if ($type == "document") {
             return Document_Service::pathExists($path);
         } else {
             if ($type == "object") {
                 return Object_Service::pathExists($path);
             }
         }
     }
 }