/** * @throws \Exception */ 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\Listing(); $redirects->setCondition("target = ?", $this->getId()); $redirects->load(); foreach ($redirects->getRedirects() as $redirect) { $redirect->delete(); } parent::delete(); }
/** * @see Document::delete * @return void */ public function delete() { // hardlinks cannot have direct children in "real" world, so we have to empty them before we delete it $this->childs = []; // check for redirects pointing to this document, and delete them too $redirects = new Redirect\Listing(); $redirects->setCondition("target = ?", $this->getId()); $redirects->load(); foreach ($redirects->getRedirects() as $redirect) { $redirect->delete(); } parent::delete(); // we re-enable the children functionality by setting them to NULL, if requested they'll be loaded again // -> see $this->getChilds() , doesn't make sense when deleting an item but who knows, ... ;-) $this->childs = null; }
public function redirectsAction() { if ($this->getParam("data")) { $this->checkPermission("redirects"); if ($this->getParam("xaction") == "destroy") { $data = \Zend_Json::decode($this->getParam("data")); if (\Pimcore\Tool\Admin::isExtJS6()) { $id = $data["id"]; } else { $id = $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 { // get list of routes $list = new Redirect\Listing(); $list->setLimit($this->getParam("limit")); $list->setOffset($this->getParam("start")); $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey']) { $list->setOrderKey($sortingSettings['orderKey']); $list->setOrder($sortingSettings['order']); } 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\Listing(); $list->setCondition("expiry < " . time() . " AND expiry IS NOT NULL AND expiry != ''"); $list->load(); foreach ($list->getRedirects() as $redirect) { $redirect->setActive(false); $redirect->save(); } }