pathExists() публичный статический Метод

public static pathExists ( $path, $type = null ) : boolean
$path
Результат boolean
Пример #1
0
 public function importDocuments()
 {
     $file = sprintf('%s/documents.json', $this->baseDir);
     $docs = new \Zend_Config_Json($file);
     foreach ($docs as $def) {
         $def = $def->toArray();
         $parent = Document::getByPath($def['parent']);
         unset($def['parent']);
         if (!$parent) {
             $parent = Document::getById(1);
         }
         $path = $parent->getFullPath() . '/' . $def['key'];
         if (Document\Service::pathExists($path)) {
             $doc = Document::getByPath($path);
         } else {
             $docClass = '\\Pimcore\\Model\\Document\\' . ucfirst($def['type']);
             /** @var Document $doc */
             $doc = $docClass::create($parent->getId(), $def, false);
             $doc->setUserOwner(self::getUser()->getId());
             $doc->setUserModification(self::getUser()->getId());
         }
         $doc->setValues($def);
         $doc->setPublished(true);
         $doc->save();
     }
 }
Пример #2
0
 /**
  * @static
  * @param $type
  * @param $path
  * @return bool
  */
 public static function pathExists($path, $type = null)
 {
     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);
             }
         }
     }
     return;
 }
Пример #3
0
 /**
  * @throws \Exception
  */
 public function correctPath()
 {
     // set path
     if ($this->getId() != 1) {
         // not for the root node
         if ($this->getParentId() == $this->getId()) {
             throw new \Exception("ParentID and ID is identical, an element can't be the parent of itself.");
         }
         $parent = Document::getById($this->getParentId());
         if ($parent) {
             // use the parent's path from the database here (getCurrentFullPath), to ensure the path really exists and does not rely on the path
             // that is currently in the parent object (in memory), because this might have changed but wasn't not saved
             $this->setPath(str_replace("//", "/", $parent->getCurrentFullPath() . "/"));
         } else {
             // parent document doesn't exist anymore, set the parent to to root
             $this->setParentId(1);
             $this->setPath("/");
         }
         if (strlen($this->getKey()) < 1) {
             $this->setKey("---no-valid-key---" . $this->getId());
             throw new \Exception("Document requires key, generated key automatically");
         }
     } else {
         if ($this->getId() == 1) {
             // some data in root node should always be the same
             $this->setParentId(0);
             $this->setPath("/");
             $this->setKey("");
             $this->setType("page");
         }
     }
     if (Document\Service::pathExists($this->getRealFullPath())) {
         $duplicate = Document::getByPath($this->getRealFullPath());
         if ($duplicate instanceof Document and $duplicate->getId() != $this->getId()) {
             throw new \Exception("Duplicate full path [ " . $this->getRealFullPath() . " ] - cannot save document");
         }
     }
     if (strlen($this->getRealFullPath()) > 765) {
         throw new \Exception("Full path is limited to 765 characters, reduce the length of your parent's path");
     }
 }
Пример #4
0
 public function addAction()
 {
     $success = false;
     $errorMessage = "";
     // 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
             $docType = Document\DocType::getById(intval($this->getParam("docTypeId")));
             if ($docType) {
                 $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"] = Config::getSystemConfig()->documents->default_controller;
                     $createValues["action"] = Config::getSystemConfig()->documents->default_action;
                 }
             }
             switch ($this->getParam("type")) {
                 case "page":
                     $document = Document\Page::create($this->getParam("parentId"), $createValues, false);
                     $document->setTitle($this->getParam('title', null));
                     $document->setProperty("navigation_name", "text", $this->getParam('name', null), false);
                     $document->save();
                     $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:
                     $classname = "\\Pimcore\\Model\\Document\\" . ucfirst($this->getParam("type"));
                     // this is the fallback for custom document types using prefixes
                     // so we need to check if the class exists first
                     if (!\Pimcore\Tool::classExists($classname)) {
                         $oldStyleClass = "\\Document_" . ucfirst($this->getParam("type"));
                         if (\Pimcore\Tool::classExists($oldStyleClass)) {
                             $classname = $oldStyleClass;
                         }
                     }
                     if (Tool::classExists($classname)) {
                         $document = $classname::create($this->getParam("parentId"), $createValues);
                         try {
                             $document->save();
                             $success = true;
                         } catch (\Exception $e) {
                             $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
                         }
                         break;
                     } else {
                         \Logger::debug("Unknown document type, can't add [ " . $this->getParam("type") . " ] ");
                     }
                     break;
             }
         } else {
             $errorMessage = "prevented adding a document because document with same path+key [ {$intendedPath} ] already exists";
             \Logger::debug($errorMessage);
         }
     } else {
         $errorMessage = "prevented adding a document because of missing permissions";
         \Logger::debug($errorMessage);
     }
     if ($success) {
         $this->_helper->json(array("success" => $success, "id" => $document->getId(), "type" => $document->getType()));
     } else {
         $this->_helper->json(array("success" => $success, "message" => $errorMessage));
     }
 }