From ec15c713420dd2ee5d5c9792af489a74db9653f6 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Tue, 4 Apr 2017 15:07:49 +0100 Subject: [PATCH 1/4] FIX: Add __isset to VirtualPage for PHP7 support. Also rely on parent::hasField and parent::hasMethod --- code/model/VirtualPage.php | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/code/model/VirtualPage.php b/code/model/VirtualPage.php index 73fe510c..eb7b841e 100644 --- a/code/model/VirtualPage.php +++ b/code/model/VirtualPage.php @@ -420,6 +420,24 @@ class VirtualPage extends Page { } } + + /** + * Allow attributes on the master page to pass + * through to the virtual page + * + * @param string $field + * @return mixed + */ + public function __isset($field) { + if(parent::hasMethod($funcName = "get$field")) { + return true; + } else if(parent::hasField($field) || ($field === 'ID' && !$this->exists())) { + return true; + } else { + return $this->CopyContentFrom()->__isset($field); + } + } + /** * Pass unrecognized method calls on to the original data object * @@ -441,13 +459,11 @@ class VirtualPage extends Page { */ public function hasField($field) { return ( - array_key_exists($field, $this->record) - || $this->hasDatabaseField($field) - || array_key_exists($field, $this->db()) // Needed for composite fields - || parent::hasMethod("get{$field}") + parent::hasField($field) || $this->CopyContentFrom()->hasField($field) ); - } + } + /** * Overwrite to also check for method on the original data object * @@ -455,8 +471,10 @@ class VirtualPage extends Page { * @return bool */ public function hasMethod($method) { - if(parent::hasMethod($method)) return true; - return $this->copyContentFrom()->hasMethod($method); + return ( + parent::hasMethod($method) + || $this->CopyContentFrom()->hasMethod($method) + ); } /** From 322c6f578b666c2d86fe68e92ea3e1e79a6cc815 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Tue, 4 Apr 2017 15:08:25 +0100 Subject: [PATCH 2/4] DOCS Fix PHPDoc --- code/model/VirtualPage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/model/VirtualPage.php b/code/model/VirtualPage.php index eb7b841e..fd640f17 100644 --- a/code/model/VirtualPage.php +++ b/code/model/VirtualPage.php @@ -12,7 +12,7 @@ class VirtualPage extends Page { public static $virtualFields; /** - * @var Array Define fields that are not virtual - the virtual page must define these fields themselves. + * @var array Define fields that are not virtual - the virtual page must define these fields themselves. * Note that anything in {@link self::config()->initially_copied_fields} is implicitly included in this list. */ private static $non_virtual_fields = array( @@ -30,7 +30,7 @@ class VirtualPage extends Page { ); /** - * @var Array Define fields that are initially copied to virtual pages but left modifiable after that. + * @var array Define fields that are initially copied to virtual pages but left modifiable after that. */ private static $initially_copied_fields = array( 'ShowInMenus', From 80e89673082cd32dfb5937a4364c646792bef61c Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 5 Apr 2017 10:46:48 +1000 Subject: [PATCH 3/4] FIX: Fix VirtualPage::init() content-modification check. This check had never worked but PHP 5 silently ignored it and PHP 7 raised it as an error. --- code/model/VirtualPage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/model/VirtualPage.php b/code/model/VirtualPage.php index fd640f17..0baeda37 100644 --- a/code/model/VirtualPage.php +++ b/code/model/VirtualPage.php @@ -528,8 +528,8 @@ class VirtualPage_Controller extends Page_Controller { * We can't load the content without an ID or record to copy it from. */ public function init(){ - if(isset($this->record) && $this->record->ID){ - if($this->record->VersionID != $this->failover->CopyContentFrom()->Version){ + if(isset($this->record) && $this->record['ID']){ + if($this->record['VersionID'] != $this->failover->CopyContentFrom()->Version){ $this->reloadContent(); $this->VersionID = $this->failover->CopyContentFrom()->VersionID; } From 2ddb616829d497a464ca78e6e61a2ec07450530b Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Tue, 4 Apr 2017 15:08:48 +0100 Subject: [PATCH 4/4] FIX Correct case of CopyContentFrom method --- code/model/VirtualPage.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/code/model/VirtualPage.php b/code/model/VirtualPage.php index 0baeda37..8bb783e7 100644 --- a/code/model/VirtualPage.php +++ b/code/model/VirtualPage.php @@ -416,7 +416,7 @@ class VirtualPage extends Page { } else if(parent::hasField($field) || ($field === 'ID' && !$this->exists())) { return $this->getField($field); } else { - return $this->copyContentFrom()->$field; + return $this->CopyContentFrom()->$field; } } @@ -449,7 +449,7 @@ class VirtualPage extends Page { if(parent::hasMethod($method)) { return parent::__call($method, $args); } else { - return call_user_func_array(array($this->copyContentFrom(), $method), $args); + return call_user_func_array(array($this->CopyContentFrom(), $method), $args); } } @@ -485,8 +485,8 @@ class VirtualPage extends Page { * @return string */ public function castingHelper($field) { - if($this->copyContentFrom()) { - return $this->copyContentFrom()->castingHelper($field); + if($this->CopyContentFrom()) { + return $this->CopyContentFrom()->castingHelper($field); } else { return parent::castingHelper($field); } @@ -560,7 +560,7 @@ class VirtualPage_Controller extends Page_Controller { $originalClass = get_class($this->CopyContentFrom()); if ($originalClass == 'SiteTree') $name = 'ContentController'; else $name = $originalClass."_Controller"; - $controller = new $name($this->dataRecord->copyContentFrom()); + $controller = new $name($this->dataRecord->CopyContentFrom()); $haveIt = $controller->hasMethod($method); } return $haveIt; @@ -585,7 +585,7 @@ class VirtualPage_Controller extends Page_Controller { throw $e; } - $original = $this->copyContentFrom(); + $original = $this->CopyContentFrom(); $controller = ModelAsController::controller_for($original); // Ensure request/response data is available on virtual controller