public function correctPath() { // set path if ($this->getId() != 1) { // not for the root node $parent = Object_Abstract::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->setO_parentId(1); $this->setO_path("/"); } } if (Object_Service::pathExists($this->getFullPath())) { $duplicate = Object_Abstract::getByPath($this->getFullPath()); if ($duplicate instanceof Object_Abstract and $duplicate->getId() != $this->getId()) { throw new Exception("Duplicate full path [ " . $this->getFullPath() . " ] - cannot create object"); } } }
public function addFolderAction() { $success = false; $parent = Object_Abstract::getById($this->_getParam("parentId")); if ($parent->isAllowed("create")) { if (!Object_Service::pathExists($parent->getFullPath() . "/" . $this->_getParam("key"))) { $folder = Object_Folder::create(array("o_parentId" => $this->_getParam("parentId"), "o_creationDate" => time(), "o_userOwner" => $this->user->getId(), "o_userModification" => $this->user->getId(), "o_key" => $this->_getParam("key"), "o_published" => true)); $folder->setCreationDate(time()); $folder->setUserOwner($this->getUser()->getId()); $folder->setUserModification($this->getUser()->getId()); try { $folder->save(); $success = true; } catch (Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } } else { Logger::debug("prevented creating object id because of missing permissions"); } $this->_helper->json(array("success" => $success)); }
/** * @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); } } } }