public function saveAction()
{
if ($this->getParam("id")) {
$page = Document\Printpage::getById($this->getParam("id"));
$page = $this->getLatestVersion($page);
$page->setUserModification($this->getUser()->getId());
// save to session
$key = "document_" . $this->getParam("id");
$session = new \Zend_Session_Namespace("pimcore_documents");
$session->{$key} = $page;
if ($this->getParam("task") == "unpublish") {
$page->setPublished(false);
}
if ($this->getParam("task") == "publish") {
$page->setPublished(true);
}
// only save when publish or unpublish
if ($this->getParam("task") == "publish" && $page->isAllowed("publish") or $this->getParam("task") == "unpublish" && $page->isAllowed("unpublish")) {
//check, if to cleanup existing elements of document
$config = Config::getWeb2PrintConfig();
if ($config->generalDocumentSaveMode == "cleanup") {
$page->setElements([]);
}
$this->setValuesToDocument($page);
try {
$page->save();
$this->_helper->json(["success" => true]);
} catch (\Exception $e) {
Logger::err($e);
$this->_helper->json(["success" => false, "message" => $e->getMessage()]);
}
} else {
if ($page->isAllowed("save")) {
$this->setValuesToDocument($page);
try {
$page->saveVersion();
$this->_helper->json(["success" => true]);
} catch (\Exception $e) {
Logger::err($e);
$this->_helper->json(["success" => false, "message" => $e->getMessage()]);
}
}
}
}
$this->_helper->json(false);
}