From fe8446aa08ac63e03bbefe3ad8f6726d1309cf2f Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Fri, 7 Aug 2015 12:05:34 +0200 Subject: [PATCH] Fix fatal error on deleting the homepage --- admin.php | 17 +++++++++++++---- classes/admin.php | 5 +++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/admin.php b/admin.php index 838c78f49..89786e6c2 100644 --- a/admin.php +++ b/admin.php @@ -148,7 +148,12 @@ public function onPagesInitialized() unset($this->grav['admin']->routes['/']); } - $pages->dispatch('/', true)->route($home); + $page = $pages->dispatch('/', true); + + // If page is null, the default page does not exist, and we cannot route to it + if ($page) { + $page->route($home); + } // Make local copy of POST. $post = !empty($_POST) ? $_POST : array(); @@ -216,9 +221,13 @@ public function onTwigSiteVariables() $twig->twig_vars['popularity'] = $this->popularity; break; case 'pages': - $twig->twig_vars['file'] = File::instance($this->admin->page(true)->filePath()); - $twig->twig_vars['media_types'] = str_replace('defaults,', '', - implode(',.', array_keys($this->config->get('media')))); + $page = $this->admin->page(true); + if ($page != null) { + $twig->twig_vars['file'] = File::instance($page->filePath()); + $twig->twig_vars['media_types'] = str_replace('defaults,', '', + implode(',.', array_keys($this->config->get('media')))); + + } break; } } diff --git a/classes/admin.php b/classes/admin.php index af264b057..c291ef0ba 100644 --- a/classes/admin.php +++ b/classes/admin.php @@ -486,6 +486,11 @@ protected function getPage($path) if (!$page) { $slug = basename($path); + + if ($slug == '') { + return null; + } + $ppath = dirname($path); // Find or create parent(s).