protected function setValuesToDocument(Document\Hardlink $link) { // data $data = \Zend_Json::decode($this->getParam("data")); $sourceId = null; if ($sourceDocument = Document::getByPath($data["sourcePath"])) { $sourceId = $sourceDocument->getId(); } $link->setSourceId($sourceId); $link->setValues($data); $this->addPropertiesToDocument($link); }
/** * @param Document\Hardlink $hardlink * @param $path * @return Document */ public static function getNearestChildByPath(Document\Hardlink $hardlink, $path) { if ($hardlink->getChildsFromSource() && $hardlink->getSourceDocument()) { $hardlinkRealPath = preg_replace("@^" . preg_quote($hardlink->getRealFullPath()) . "@", $hardlink->getSourceDocument()->getRealFullPath(), $path); $pathes = array(); $pathes[] = "/"; $pathParts = explode("/", $hardlinkRealPath); $tmpPathes = array(); foreach ($pathParts as $pathPart) { $tmpPathes[] = $pathPart; $t = implode("/", $tmpPathes); if (!empty($t)) { $pathes[] = $t; } } $pathes = array_reverse($pathes); foreach ($pathes as $p) { $hardLinkedDocument = Document::getByPath($p); if ($hardLinkedDocument instanceof Document) { $hardLinkedDocument = self::wrap($hardLinkedDocument); $hardLinkedDocument->setHardLinkSource($hardlink); $_path = $path != "/" ? $_path = dirname($p) : $p; $_path = str_replace("\\", "/", $_path); // windows patch $_path .= $_path != "/" ? "/" : ""; $_path = preg_replace("@^" . preg_quote($hardlink->getSourceDocument()->getRealPath()) . "@", $hardlink->getRealPath(), $_path); $hardLinkedDocument->setPath($_path); return $hardLinkedDocument; } } } }
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)); } }