From d5b872449ace6af099e4a395e3faec2bfdefe78b Mon Sep 17 00:00:00 2001 From: Nathan Glasl Date: Mon, 26 Jun 2017 10:52:20 +1000 Subject: [PATCH] FIX, checking to ensure there's a current controller. --- README.md | 2 +- code/extensions/SiteTreeMisdirectionExtension.php | 2 +- code/services/MisdirectionService.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a1914eb..06a3857 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # [misdirection](https://packagist.org/packages/nglasl/silverstripe-misdirection) -_The current release is **2.2.22**_ +_The current release is **2.2.23**_ > A module for SilverStripe which will allow both simple and regular expression link redirections based on customisable mappings, either hooking into a page not found or replacing the default automated URL handling. diff --git a/code/extensions/SiteTreeMisdirectionExtension.php b/code/extensions/SiteTreeMisdirectionExtension.php index 97e06d6..71ca53d 100644 --- a/code/extensions/SiteTreeMisdirectionExtension.php +++ b/code/extensions/SiteTreeMisdirectionExtension.php @@ -52,7 +52,7 @@ public function onBeforeWrite() { // Retrieve the vanity mapping URL, where this is only possible using the POST variable. - $vanityURL = (is_null($controller = Controller::curr()) || is_null($URL = $controller->getRequest()->postVar('VanityURL'))) ? $this->owner->VanityMapping()->MappedLink : $URL; + $vanityURL = (!Controller::has_curr() || is_null($controller = Controller::curr()) || is_null($URL = $controller->getRequest()->postVar('VanityURL'))) ? $this->owner->VanityMapping()->MappedLink : $URL; $mappingExists = $this->owner->VanityMapping()->exists(); // Determine whether the vanity mapping URL has been updated. diff --git a/code/services/MisdirectionService.php b/code/services/MisdirectionService.php index 305c721..32f536c 100644 --- a/code/services/MisdirectionService.php +++ b/code/services/MisdirectionService.php @@ -82,7 +82,7 @@ public function getMapping($URL, $host = null) { // Enforce any hostname restriction that may have been defined. - if(is_null($host) && ($controller = Controller::curr())) { + if(is_null($host) && Controller::has_curr() && ($controller = Controller::curr())) { $host = $controller->getRequest()->getHeader('Host'); } $temporary = $host;