/** * makes sure, that the creation of objects with duplicate paths is not possible * @expectedException Exception * @depends testObjectFolderCreate */ public function testDuplicateObjectPath() { $id = uniqid(); $folder = Object_Folder::create(array("o_parentId" => 1, "o_creationDate" => time(), "o_key" => $id)); $folder->save(); $folder = Object_Folder::create(array("o_parentId" => 1, "o_creationDate" => time(), "o_key" => $id)); $folder->save(); }
public function getFolderAlpha($name) { $fdata["o_key"] = strtolower(substr($name, 0, 1)); $root = $this->getFolderRoot(); $data = $this->db->fetchRow(sprintf("SELECT o.* FROM objects o WHERE o.o_key ='%s' and o.o_type='folder' and o.o_parentId=%s", array($fdata['o_key'], $root->getId()))); if ($data["o_id"]) { $folder = Object_Folder::getById($data["o_id"]); return $folder; } else { $fdata["o_parentId"] = $root->getId(); $folder = Object_Folder::create($fdata); return $folder; } }
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)); }
public function createFolders() { $root = Object_Folder::create(array('o_parentId' => 1, 'o_creationDate' => time(), 'o_userOwner' => $this->_getUser()->getId(), 'o_userModification' => $this->_getUser()->getId(), 'o_key' => 'blog', 'o_published' => true)); Object_Folder::create(array('o_parentId' => $root->getId(), 'o_creationDate' => time(), 'o_userOwner' => $this->_getUser()->getId(), 'o_userModification' => $this->_getUser()->getId(), 'o_key' => 'entries', 'o_published' => true)); Object_Folder::create(array('o_parentId' => $root->getId(), 'o_creationDate' => time(), 'o_userOwner' => $this->_getUser()->getId(), 'o_userModification' => $this->_getUser()->getId(), 'o_key' => 'categories', 'o_published' => true)); return $root; }
/** * @param $folderPath * * @return mixed * @throws Exception * * Runs each level of the folder-path and checks if it is already existing in pimcore */ protected function checkFolderPath($folderPath) { $folderObject = Object_Folder::getByPath($folderPath); if (!is_object($folderObject)) { $folderPathArray = explode('/', $folderPath); $growingPath = ''; foreach ($folderPathArray as $folderName) { $folderObject = Object_Folder::getByPath($growingPath . '/' . $folderName); if (!is_object($folderObject) && !method_exists($folderObject, 'getId')) { try { $parentFolder = Object_Folder::getByPath($growingPath); if (is_object($parentFolder)) { $parentId = $parentFolder->getId(); $parentFolder = Object_Folder::create(array('type' => 'folder', 'key' => $folderName, 'parentId' => $parentId)); } } catch (Exception $e) { throw $e; } } $growingPath .= '/' . $folderName; } } if (is_object($folderObject)) { return $folderObject; } else { return $parentFolder; } }