public function saveAction() { if ($this->getParam("id")) { $folder = Document\Folder::getById($this->getParam("id")); $folder->setModificationDate(time()); $folder->setUserModification($this->getUser()->getId()); if ($folder->isAllowed("publish")) { $this->setValuesToDocument($folder); $folder->save(); $this->_helper->json(array("success" => true)); } } $this->_helper->json(false); }
public function saveAction() { try { if ($this->getParam("id")) { $folder = Document\Folder::getById($this->getParam("id")); $folder->setModificationDate(time()); $folder->setUserModification($this->getUser()->getId()); if ($folder->isAllowed("publish")) { $this->setValuesToDocument($folder); $folder->save(); $this->_helper->json(["success" => true]); } } } catch (\Exception $e) { \Logger::log($e); if (Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) { $this->_helper->json(["success" => false, "type" => "ValidationException", "message" => $e->getMessage(), "stack" => $e->getTraceAsString(), "code" => $e->getCode()]); } throw $e; } $this->_helper->json(false); }
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)); } }