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