FIX Update API changes in ErrorPage and typo in extension config class name

This commit is contained in:
Robbie Averill 2017-08-30 12:14:11 +12:00
parent c620ff02f4
commit c155855100
4 changed files with 21 additions and 16 deletions

View File

@ -28,7 +28,7 @@ SilverStripe\Assets\File:
extensions: extensions:
- SilverStripe\Subsites\Extensions\FileSubsites - SilverStripe\Subsites\Extensions\FileSubsites
SilverStripe\CMS\Model\ErrorPage: SilverStripe\ErrorPage\ErrorPage:
extensions: extensions:
- SilverStripe\Subsites\Extensions\ErrorPageSubsite - SilverStripe\Subsites\Extensions\ErrorPageSubsite

View File

@ -11,17 +11,19 @@ use SilverStripe\Subsites\Model\Subsite;
class ErrorPageSubsite extends DataExtension 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 * FIXME since {@link Subsite::currentSubsite()} partly relies on Session, viewing other sub-site (including
* opening ErrorPage in the CMS and publish ErrorPage causes static error page to get generated incorrectly. * main site) between opening ErrorPage in the CMS and publish ErrorPage causes static error page to get
* @param $statusCode * generated incorrectly.
* @param null $locale *
* @return string * @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'); $static_filepath = Config::inst()->get($this->owner->ClassName, 'static_filepath');
$subdomainPart = ''; $subdomainPart = '';
@ -29,7 +31,8 @@ class ErrorPageSubsite extends DataExtension
// Try to get current subsite from session // Try to get current subsite from session
$subsite = Subsite::currentSubsite(); $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) { if (!$subsite) {
$subsiteID = Subsite::getSubsiteIDForDomain(); $subsiteID = Subsite::getSubsiteIDForDomain();
if ($subsiteID != 0) { if ($subsiteID != 0) {
@ -44,12 +47,16 @@ class ErrorPageSubsite extends DataExtension
$subdomainPart = "-{$subdomain}"; $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"; $filepath = $static_filepath . "/error-{$statusCode}-{$locale}{$subdomainPart}.html";
} else { } else {
$filepath = $static_filepath . "/error-{$statusCode}{$subdomainPart}.html"; $filepath = $static_filepath . "/error-{$statusCode}{$subdomainPart}.html";
} }
return $filepath; $name = $filepath;
} }
} }

View File

@ -469,7 +469,7 @@ class SiteTreeSubsites extends DataExtension
if ($subsite && $subsite->exists() && $subsite->PageTypeBlacklist) { if ($subsite && $subsite->exists() && $subsite->PageTypeBlacklist) {
$blacklisted = explode(',', $subsite->PageTypeBlacklist); $blacklisted = explode(',', $subsite->PageTypeBlacklist);
// All subclasses need to be listed explicitly // All subclasses need to be listed explicitly
if (in_array($this->owner->class, $blacklisted)) { if (in_array(get_class($this->owner), $blacklisted)) {
return false; return false;
} }
} }

View File

@ -82,12 +82,10 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
public function testErrorPageLocations() public function testErrorPageLocations()
{ {
$this->markTestSkipped('needs refactoring');
$subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1'); $subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1');
Subsite::changeSubsite($subsite1->ID); 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'); $static_path = Config::inst()->get(ErrorPage::class, 'static_filepath');
$expected_path = $static_path . '/error-500-' . $subsite1->domain() . '.html'; $expected_path = $static_path . '/error-500-' . $subsite1->domain() . '.html';