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)); } }