From c155855100a5c6b3ab98e18b0df6632dd470d1a3 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 30 Aug 2017 12:14:11 +1200 Subject: [PATCH] FIX Update API changes in ErrorPage and typo in extension config class name --- _config/extensions.yml | 2 +- code/extensions/ErrorPageSubsite.php | 29 +++++++++++++++++----------- code/extensions/SiteTreeSubsites.php | 2 +- tests/php/SiteTreeSubsitesTest.php | 4 +--- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/_config/extensions.yml b/_config/extensions.yml index 71b48f62..506b59e3 100644 --- a/_config/extensions.yml +++ b/_config/extensions.yml @@ -28,7 +28,7 @@ SilverStripe\Assets\File: extensions: - SilverStripe\Subsites\Extensions\FileSubsites -SilverStripe\CMS\Model\ErrorPage: +SilverStripe\ErrorPage\ErrorPage: extensions: - SilverStripe\Subsites\Extensions\ErrorPageSubsite diff --git a/code/extensions/ErrorPageSubsite.php b/code/extensions/ErrorPageSubsite.php index 854dced3..199f2bcc 100644 --- a/code/extensions/ErrorPageSubsite.php +++ b/code/extensions/ErrorPageSubsite.php @@ -11,17 +11,19 @@ class ErrorPageSubsite extends DataExtension { /** - * Alter file path to generated a static (static) error page file to handle error page template on different sub-sites + * Alter file path to generated a static (static) error page file to handle error page template + * on different sub-sites * - * @see Error::get_filepath_for_errorcode() + * @see ErrorPage::get_error_filename() * - * FIXME since {@link Subsite::currentSubsite()} partly relies on Session, viewing other sub-site (including main site) between - * opening ErrorPage in the CMS and publish ErrorPage causes static error page to get generated incorrectly. - * @param $statusCode - * @param null $locale - * @return string + * FIXME since {@link Subsite::currentSubsite()} partly relies on Session, viewing other sub-site (including + * main site) between opening ErrorPage in the CMS and publish ErrorPage causes static error page to get + * generated incorrectly. + * + * @param string $name + * @param int $statusCode */ - public function alternateFilepathForErrorcode($statusCode, $locale = null) + public function updateErrorFilename(&$name, &$statusCode) { $static_filepath = Config::inst()->get($this->owner->ClassName, 'static_filepath'); $subdomainPart = ''; @@ -29,7 +31,8 @@ public function alternateFilepathForErrorcode($statusCode, $locale = null) // Try to get current subsite from session $subsite = Subsite::currentSubsite(); - // since this function is called from Page class before the controller is created, we have to get subsite from domain instead + // since this function is called from Page class before the controller is created, we have + // to get subsite from domain instead if (!$subsite) { $subsiteID = Subsite::getSubsiteIDForDomain(); if ($subsiteID != 0) { @@ -44,12 +47,16 @@ public function alternateFilepathForErrorcode($statusCode, $locale = null) $subdomainPart = "-{$subdomain}"; } - if (singleton(SiteTree::class)->hasExtension('Translatable') && $locale && $locale != Translatable::default_locale()) { + // @todo implement Translatable namespace + if (singleton(SiteTree::class)->hasExtension('Translatable') + && $locale + && $locale != Translatable::default_locale() + ) { $filepath = $static_filepath . "/error-{$statusCode}-{$locale}{$subdomainPart}.html"; } else { $filepath = $static_filepath . "/error-{$statusCode}{$subdomainPart}.html"; } - return $filepath; + $name = $filepath; } } diff --git a/code/extensions/SiteTreeSubsites.php b/code/extensions/SiteTreeSubsites.php index fa9086f6..55a9de07 100644 --- a/code/extensions/SiteTreeSubsites.php +++ b/code/extensions/SiteTreeSubsites.php @@ -469,7 +469,7 @@ public function canCreate($member = null) if ($subsite && $subsite->exists() && $subsite->PageTypeBlacklist) { $blacklisted = explode(',', $subsite->PageTypeBlacklist); // All subclasses need to be listed explicitly - if (in_array($this->owner->class, $blacklisted)) { + if (in_array(get_class($this->owner), $blacklisted)) { return false; } } diff --git a/tests/php/SiteTreeSubsitesTest.php b/tests/php/SiteTreeSubsitesTest.php index 5b794ddc..3fce8a9d 100644 --- a/tests/php/SiteTreeSubsitesTest.php +++ b/tests/php/SiteTreeSubsitesTest.php @@ -82,12 +82,10 @@ public function testBasicSanity() public function testErrorPageLocations() { - $this->markTestSkipped('needs refactoring'); - $subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1'); Subsite::changeSubsite($subsite1->ID); - $path = ErrorPage::get_filepath_for_errorcode(500); + $path = TestErrorPage::get_error_filename_spy(500); $static_path = Config::inst()->get(ErrorPage::class, 'static_filepath'); $expected_path = $static_path . '/error-500-' . $subsite1->domain() . '.html';