/** * @see Document::delete and Document_PageSnippet::delete * @return void */ public function delete() { if ($this->getId() == 1) { throw new Exception("root-node cannot be deleted"); } // check for redirects pointing to this document, and delete them too $redirects = new Redirect_List(); $redirects->setCondition("target = ?", $this->getId()); $redirects->load(); foreach ($redirects->getRedirects() as $redirect) { $redirect->delete(); } parent::delete(); }
public function redirectsAction() { if ($this->_getParam("data")) { if ($this->getUser()->isAllowed("redirects")) { if ($this->_getParam("xaction") == "destroy") { $id = Zend_Json::decode($this->_getParam("data")); $redirect = Redirect::getById($id); $redirect->delete(); $this->_helper->json(array("success" => true, "data" => array())); } else { if ($this->_getParam("xaction") == "update") { $data = Zend_Json::decode($this->_getParam("data")); // save redirect $redirect = Redirect::getById($data["id"]); if ($data["target"]) { if ($doc = Document::getByPath($data["target"])) { $data["target"] = $doc->getId(); } } $redirect->setValues($data); $redirect->save(); $redirectTarget = $redirect->getTarget(); if (is_numeric($redirectTarget)) { if ($doc = Document::getById(intval($redirectTarget))) { $redirect->setTarget($doc->getFullPath()); } } $this->_helper->json(array("data" => $redirect, "success" => true)); } else { if ($this->_getParam("xaction") == "create") { $data = Zend_Json::decode($this->_getParam("data")); unset($data["id"]); // save route $redirect = new Redirect(); if ($data["target"]) { if ($doc = Document::getByPath($data["target"])) { $data["target"] = $doc->getId(); } } $redirect->setValues($data); $redirect->save(); $redirectTarget = $redirect->getTarget(); if (is_numeric($redirectTarget)) { if ($doc = Document::getById(intval($redirectTarget))) { $redirect->setTarget($doc->getFullPath()); } } $this->_helper->json(array("data" => $redirect, "success" => true)); } } } } else { Logger::err("user [" . $this->getUser()->getId() . "] attempted to modify static routes, but has no permission to do so."); } } else { // get list of routes $list = new Redirect_List(); $list->setLimit($this->_getParam("limit")); $list->setOffset($this->_getParam("start")); if ($this->_getParam("sort")) { $list->setOrderKey($this->_getParam("sort")); $list->setOrder($this->_getParam("dir")); } if ($this->_getParam("filter")) { $list->setCondition("`source` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%") . " OR `target` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%")); } $list->load(); $redirects = array(); foreach ($list->getRedirects() as $redirect) { if ($link = $redirect->getTarget()) { if (is_numeric($link)) { if ($doc = Document::getById(intval($link))) { $redirect->setTarget($doc->getFullPath()); } } } $redirects[] = $redirect; } $this->_helper->json(array("data" => $redirects, "success" => true, "total" => $list->getTotalCount())); } $this->_helper->json(false); }
/** * */ public static function maintenanceCleanUp() { $list = new Redirect_List(); $list->setCondition("expiry < " . time() . " AND expiry IS NOT NULL AND expiry != ''"); $list->load(); foreach ($list->getRedirects() as $redirect) { echo $redirect->getSource() . "\n"; $redirect->delete(); } }