Beispiel #1
0
 /**
  * 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;
 }