Delete a page
public static delete ( integer $id, string $language = null, integer $revisionId = null ) : boolean | ||
$id | integer | The id of the page to delete. |
$language | string | The language wherein the page will be deleted, if not provided we will use the working language. |
$revisionId | integer | If specified the given revision will be deleted, used for deleting drafts. |
return | boolean |
/** * Execute the action */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendPagesModel::exists($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // init var $success = false; // cannot have children if (BackendPagesModel::getFirstChildId($this->id) !== false) { $this->redirect(BackendModel::createURLForAction('Edit') . '&error=non-existing'); } $revisionId = $this->getParameter('revision_id', 'int'); if ($revisionId == 0) { $revisionId = null; } // get page (we need the title) $page = BackendPagesModel::get($this->id, $revisionId); // valid page? if (!empty($page)) { // delete the page $success = BackendPagesModel::delete($this->id, null, $revisionId); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id)); // delete search indexes BackendSearchModel::removeIndex($this->getModule(), $this->id); // build cache BackendPagesModel::buildCache(BL::getWorkingLanguage()); } // page is deleted, so redirect to the overview if ($success) { $this->redirect(BackendModel::createURLForAction('Index') . '&id=' . $page['parent_id'] . '&report=deleted&var=' . rawurlencode($page['title'])); } else { $this->redirect(BackendModel::createURLForAction('Edit') . '&error=non-existing'); } } else { $this->redirect(BackendModel::createURLForAction('Edit') . '&error=non-existing'); } }