/** * */ public function update() { parent::update(); $config = Pimcore_Config::getSystemConfig(); if ($this->_oldPath && $config->documents->createredirectwhenmoved) { // create redirect for old path $redirect = new Redirect(); $redirect->setTarget($this->getId()); $redirect->setSource("@" . $this->_oldPath . "/?@"); $redirect->setStatusCode(301); $redirect->setExpiry(time() + 86400 * 60); // this entry is removed automatically after 60 days $redirect->save(); } }
public function saveAction() { if ($this->_getParam("id")) { $page = Document_Page::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); } // check for redirects if ($this->getUser()->isAllowed("redirects") && $this->_getParam("settings")) { $settings = Zend_Json::decode($this->_getParam("settings")); if (is_array($settings)) { $redirectList = new Redirect_List(); $redirectList->setCondition("target = ?", $page->getId()); $existingRedirects = $redirectList->load(); $existingRedirectIds = array(); foreach ($existingRedirects as $existingRedirect) { $existingRedirectIds[$existingRedirect->getId()] = $existingRedirect->getId(); } for ($i = 1; $i < 100; $i++) { if (array_key_exists("redirect_url_" . $i, $settings)) { // check for existing if ($settings["redirect_id_" . $i]) { $redirect = Redirect::getById($settings["redirect_id_" . $i]); unset($existingRedirectIds[$redirect->getId()]); } else { // create new one $redirect = new Redirect(); } $redirect->setSource($settings["redirect_url_" . $i]); $redirect->setTarget($page->getId()); $redirect->setStatusCode(301); $redirect->save(); } } // remove existing redirects which were delete foreach ($existingRedirectIds as $existingRedirectId) { $redirect = Redirect::getById($existingRedirectId); $redirect->delete(); } } } // only save when publish or unpublish if ($this->_getParam("task") == "publish" && $page->isAllowed("publish") or $this->_getParam("task") == "unpublish" && $page->isAllowed("unpublish")) { $this->setValuesToDocument($page); try { $page->save(); $this->_helper->json(array("success" => true)); } catch (Exception $e) { Logger::err($e); $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } else { if ($page->isAllowed("save")) { $this->setValuesToDocument($page); try { $page->saveVersion(); $this->_helper->json(array("success" => true)); } catch (Exception $e) { Logger::err($e); $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } } } $this->_helper->json(false); }