From 7592db918f269db2fd5c33d9c1259df86f15e12b Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Fri, 12 Apr 2019 15:45:50 +0100 Subject: [PATCH 1/3] FIX: VirtualPage missing methods from target page (fixes #2408) --- code/Model/VirtualPage.php | 13 +++++++++++++ tests/php/Model/VirtualPageTest.php | 3 +++ 2 files changed, 16 insertions(+) diff --git a/code/Model/VirtualPage.php b/code/Model/VirtualPage.php index 1b4a9231..e7425f88 100644 --- a/code/Model/VirtualPage.php +++ b/code/Model/VirtualPage.php @@ -489,6 +489,19 @@ class VirtualPage extends Page return $copy && $copy->exists() && $copy->hasField($field); } + /** + * @param string $method + * @return bool + */ + public function hasMethod($method) + { + if (parent::hasMethod($method)) { + return true; + } + $copy = $this->CopyContentFrom(); + return $copy && $copy->exists() && $copy->hasMethod($method); + } + /** * Return the "casting helper" (a piece of PHP code that when evaluated creates a casted value object) for a field * on this object. diff --git a/tests/php/Model/VirtualPageTest.php b/tests/php/Model/VirtualPageTest.php index 7951b9de..834324b7 100644 --- a/tests/php/Model/VirtualPageTest.php +++ b/tests/php/Model/VirtualPageTest.php @@ -669,6 +669,9 @@ class VirtualPageTest extends FunctionalTest { /** @var VirtualPage $virtualPage */ $virtualPage = $this->objFromFixture(VirtualPage::class, 'vp4'); + $this->assertTrue($virtualPage->hasMethod('modelMethod')); + $this->assertEquals('hi there', $virtualPage->modelMethod()); + /** @var VirtualPageTest_ClassAController $controller */ $controller = ModelAsController::controller_for($virtualPage); $this->assertInstanceOf(VirtualPageTest_ClassAController::class, $controller); From 0872a23aa8345c7baf66791ca2f32db2a8343336 Mon Sep 17 00:00:00 2001 From: Adrian Humphreys Date: Mon, 9 Sep 2019 07:50:10 +1200 Subject: [PATCH 2/3] Keep a more shared understanding of Archived --- code/Controllers/SilverStripeNavigatorItem.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/code/Controllers/SilverStripeNavigatorItem.php b/code/Controllers/SilverStripeNavigatorItem.php index 04e619be..4c5644a4 100644 --- a/code/Controllers/SilverStripeNavigatorItem.php +++ b/code/Controllers/SilverStripeNavigatorItem.php @@ -128,14 +128,7 @@ abstract class SilverStripeNavigatorItem extends ViewableData } if (!isset($record->_cached_isArchived)) { - $baseClass = $record->baseClass(); - $currentDraft = Versioned::get_by_stage($baseClass, Versioned::DRAFT)->byID($record->ID); - $currentLive = Versioned::get_by_stage($baseClass, Versioned::LIVE)->byID($record->ID); - - $record->_cached_isArchived = ( - (!$currentDraft || ($currentDraft && $record->Version != $currentDraft->Version)) - && (!$currentLive || ($currentLive && $record->Version != $currentLive->Version)) - ); + $record->_cached_isArchived = $record->isArchived(); } return $record->_cached_isArchived; From 075c98ed8e951ea68105be1102df65c7ebf32120 Mon Sep 17 00:00:00 2001 From: Dileep Ratnayake Date: Wed, 11 Sep 2019 11:09:14 +1200 Subject: [PATCH 3/3] Change self:: to static:: for better extensibility --- code/Controllers/OldPageRedirector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Controllers/OldPageRedirector.php b/code/Controllers/OldPageRedirector.php index 38f3ce50..f4bffece 100644 --- a/code/Controllers/OldPageRedirector.php +++ b/code/Controllers/OldPageRedirector.php @@ -29,7 +29,7 @@ class OldPageRedirector extends Extension $getvars = $request->getVars(); unset($getvars['url']); - $page = self::find_old_page($params); + $page = static::find_old_page($params); $cleanPage = trim(Director::makeRelative($page), '/'); if (!$cleanPage) { $cleanPage = Director::makeRelative(RootURLController::get_homepage_link());