public function saveAction() { try { if ($this->getParam("id")) { $snippet = Document\Snippet::getById($this->getParam("id")); $snippet = $this->getLatestVersion($snippet); $snippet->setUserModification($this->getUser()->getId()); if ($this->getParam("task") == "unpublish") { $snippet->setPublished(false); } if ($this->getParam("task") == "publish") { $snippet->setPublished(true); } if ($this->getParam("task") == "publish" && $snippet->isAllowed("publish") or $this->getParam("task") == "unpublish" && $snippet->isAllowed("unpublish")) { $this->setValuesToDocument($snippet); try { $snippet->save(); $this->saveToSession($snippet); $this->_helper->json(["success" => true]); } catch (\Exception $e) { if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) { throw $e; } $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } else { if ($snippet->isAllowed("save")) { $this->setValuesToDocument($snippet); try { $snippet->saveVersion(); $this->saveToSession($snippet); $this->_helper->json(["success" => true]); } catch (\Exception $e) { $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } } } } 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 saveAction() { if ($this->getParam("id")) { $snippet = Document\Snippet::getById($this->getParam("id")); $snippet = $this->getLatestVersion($snippet); $snippet->setUserModification($this->getUser()->getId()); if ($this->getParam("task") == "unpublish") { $snippet->setPublished(false); } if ($this->getParam("task") == "publish") { $snippet->setPublished(true); } if ($this->getParam("task") == "publish" && $snippet->isAllowed("publish") or $this->getParam("task") == "unpublish" && $snippet->isAllowed("unpublish")) { $this->setValuesToDocument($snippet); try { $snippet->save(); $this->saveToSession($snippet); $this->_helper->json(array("success" => true)); } catch (\Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } else { if ($snippet->isAllowed("save")) { $this->setValuesToDocument($snippet); try { $snippet->saveVersion(); $this->saveToSession($snippet); $this->_helper->json(array("success" => true)); } catch (\Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } } } $this->_helper->json(false); }
/** * @param Model\Webservice\Data\Document\Element $wsElement * @param mixed $params * @param null $idMapper * @throws \Exception */ public function getFromWebserviceImport($wsElement, $document = null, $params = [], $idMapper = null) { $data = $wsElement->value; if ($data->id !== null) { $this->id = $data->id; if (is_numeric($this->id)) { $this->snippet = Document\Snippet::getById($this->id); if (!$this->snippet instanceof Document\Snippet) { throw new \Exception("cannot get values from web service import - referenced snippet with id [ " . $this->id . " ] is unknown"); } } else { throw new \Exception("cannot get values from web service import - id is not valid"); } } }
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)); } }