/** * Permanently delete a page and it's fields. * * Unlike trash(), pages deleted here are not restorable. * * If you attempt to delete a page with children, and don't specifically set the $recursive param to True, then * this method will throw an exception. If a recursive delete fails for any reason, an exception will be thrown. * * @param Page $page * @param bool $recursive If set to true, then this will attempt to delete all children too. * @param array $options Optional settings to change behavior (for the future) * @return bool|int Returns true (success), or integer of quantity deleted if recursive mode requested. * @throws WireException on fatal error * */ public function ___delete(Page $page, $recursive = false, array $options = array()) { if (!$this->isDeleteable($page)) { throw new WireException("This page may not be deleted"); } $numDeleted = 0; if ($page->numChildren) { if (!$recursive) { throw new WireException("Can't delete Page {$page} because it has one or more children."); } else { foreach ($page->children("include=all") as $child) { /** @var Page $child */ if ($this->delete($child, true)) { $numDeleted++; } else { throw new WireException("Error doing recursive page delete, stopped by page {$child}"); } } } } // trigger a hook to indicate delete is ready and WILL occur $this->deleteReady($page); foreach ($page->fieldgroup as $field) { if (!$field->type->deletePageField($page, $field)) { $this->error("Unable to delete field '{$field}' from page '{$page}'"); } } try { if (PagefilesManager::hasPath($page)) { $page->filesManager->emptyAllPaths(); } } catch (Exception $e) { } // $page->getCacheFile()->remove(); $access = new PagesAccess(); $access->deletePage($page); $database = $this->wire('database'); $query = $database->prepare("DELETE FROM pages_parents WHERE pages_id=:page_id"); $query->bindValue(":page_id", $page->id, \PDO::PARAM_INT); $query->execute(); $query = $database->prepare("DELETE FROM pages WHERE id=:page_id LIMIT 1"); // QA $query->bindValue(":page_id", $page->id, \PDO::PARAM_INT); $query->execute(); $this->sortfields->delete($page); $page->setTrackChanges(false); $page->status = Page::statusDeleted; // no need for bitwise addition here, as this page is no longer relevant $this->deleted($page); $numDeleted++; $this->uncacheAll($page); $this->debugLog('delete', $page, true); return $recursive ? $numDeleted : true; }
/** * Update or insert template to database * * If the template's fieldgroup has changed, then we delete data that's no longer applicable to the new fieldgroup. * * @param Saveable|Template $item * @return bool true on success * @throws WireException * */ public function ___save(Saveable $item) { $isNew = $item->id < 1; if (!$item->fieldgroup) { throw new WireException("Template '{$item}' cannot be saved because it has no fieldgroup assigned"); } if (!$item->fieldgroup->id) { throw new WireException("You must save Fieldgroup '{$item->fieldgroup->name}' before adding to Template '{$item}'"); } $rolesChanged = $item->isChanged('useRoles'); if ($this->wire('pages')->get("/")->template->id == $item->id) { if (!$item->useRoles) { throw new WireException("Template '{$item}' is used by the homepage and thus must manage access"); } if (!$item->hasRole("guest")) { throw new WireException("Template '{$item}' is used by the homepage and thus must have the 'guest' role assigned."); } } if (!$item->isChanged('modified')) { $item->modified = time(); } $result = parent::___save($item); if ($result && !$isNew && $item->fieldgroupPrevious && $item->fieldgroupPrevious->id != $item->fieldgroup->id) { // the fieldgroup has been changed // remove data from all fields that are not part of the new fieldgroup $removeFields = new FieldsArray(); foreach ($item->fieldgroupPrevious as $field) { if (!$item->fieldgroup->has($field)) { $removeFields->add($field); } } if (count($removeFields)) { foreach ($removeFields as $field) { $field->type->deleteTemplateField($item, $field); } /* $pages = $this->fuel('pages')->find("templates_id={$item->id}, check_access=0, status<" . Page::statusMax); foreach($pages as $page) { foreach($removeFields as $field) { $field->type->deletePageField($page, $field); if($this->fuel('config')->debug) $this->message("Removed field '$field' on page '{$page->url}'"); } } */ } } if ($rolesChanged) { $access = new PagesAccess(); $access->updateTemplate($item); } $this->wire('cache')->maintenance($item); return $result; }
/** * Permanently delete a page and it's fields. * * Unlike trash(), pages deleted here are not restorable. * * If you attempt to delete a page with children, and don't specifically set the $recursive param to True, then * this method will throw an exception. If a recursive delete fails for any reason, an exception will be thrown. * * @param Page $page * @param bool $recursive If set to true, then this will attempt to delete all children too. * @return bool * */ public function ___delete(Page $page, $recursive = false) { if (!$this->isDeleteable($page)) { throw new WireException("This page may not be deleted"); } if ($page->numChildren) { if (!$recursive) { throw new WireException("Can't delete Page {$page} because it has one or more children."); } foreach ($page->children("status<" . Page::statusMax) as $child) { if (!$this->delete($child, true)) { throw new WireException("Error doing recursive page delete, stopped by page {$child}"); } } } // trigger a hook to indicate delete is ready and WILL occur $this->deleteReady($page); foreach ($page->fieldgroup as $field) { if (!$field->type->deletePageField($page, $field)) { $this->error("Unable to delete field '{$field}' from page '{$page}'"); } } try { $page->filesManager->emptyAllPaths(); } catch (Exception $e) { } // $page->getCacheFile()->remove(); $access = new PagesAccess(); $access->deletePage($page); $this->db->query("DELETE FROM pages_parents WHERE pages_id=" . (int) $page->id); $this->db->query("DELETE FROM pages WHERE id=" . (int) $page->id . " LIMIT 1"); // $this->getFuel('pagesRoles')->deleteRolesFromPage($page); // TODO convert to hook $this->sortfields->delete($page); $page->setTrackChanges(false); $page->status = Page::statusDeleted; // no need for bitwise addition here, as this page is no longer relevant $this->deleted($page); $this->uncacheAll(); $this->debugLog('delete', $page, true); return true; }