diff --git a/src/Extensions/BaseElementSubsites.php b/src/Extensions/BaseElementSubsites.php index ee2a6b37..40b3a435 100644 --- a/src/Extensions/BaseElementSubsites.php +++ b/src/Extensions/BaseElementSubsites.php @@ -20,7 +20,7 @@ class BaseElementSubsites extends DataExtension * @param string|null $action * @return string */ - public function updatePreviewLink(&$link) + protected function updatePreviewLink(&$link) { // Get subsite ID from the element or from its page. Defaults to 0 automatically. $subsiteID = $this->owner->SubsiteID; diff --git a/src/Extensions/CMSPageAddControllerExtension.php b/src/Extensions/CMSPageAddControllerExtension.php index ad7c87c2..afdcdacd 100644 --- a/src/Extensions/CMSPageAddControllerExtension.php +++ b/src/Extensions/CMSPageAddControllerExtension.php @@ -13,7 +13,7 @@ */ class CMSPageAddControllerExtension extends Extension { - public function updatePageOptions(FieldList $fields) + protected function updatePageOptions(FieldList $fields) { $fields->push(HiddenField::create('SubsiteID', 'SubsiteID', SubsiteState::singleton()->getSubsiteId())); } diff --git a/src/Extensions/ErrorPageSubsite.php b/src/Extensions/ErrorPageSubsite.php index 2dac6edd..ab16cf11 100644 --- a/src/Extensions/ErrorPageSubsite.php +++ b/src/Extensions/ErrorPageSubsite.php @@ -28,7 +28,7 @@ class ErrorPageSubsite extends DataExtension * @param string $name * @param int $statusCode */ - public function updateErrorFilename(&$name, &$statusCode) + protected function updateErrorFilename(&$name, &$statusCode) { $static_filepath = Config::inst()->get($this->owner->ClassName, 'static_filepath'); $subdomainPart = ''; diff --git a/src/Extensions/FileSubsites.php b/src/Extensions/FileSubsites.php index 454ae7bf..ccbe183b 100644 --- a/src/Extensions/FileSubsites.php +++ b/src/Extensions/FileSubsites.php @@ -49,7 +49,7 @@ public function alternateTreeTitle() * @param SQLSelect $query * @param DataQuery|null $dataQuery */ - public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) + protected function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { if (Subsite::$disable_subsite_filter) { return; @@ -85,7 +85,7 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) } } - public function onBeforeWrite() + protected function onBeforeWrite() { if (!$this->owner->ID && !$this->owner->SubsiteID) { if ($this->owner->config()->get('default_root_folders_global')) { @@ -96,7 +96,7 @@ public function onBeforeWrite() } } - public function onAfterUpload() + protected function onAfterUpload() { // If we have a parent, use it's subsite as our subsite if ($this->owner->Parent()) { @@ -132,7 +132,7 @@ public function canEdit($member = null) * * @return string */ - public function cacheKeyComponent() + protected function cacheKeyComponent() { return 'subsite-' . SubsiteState::singleton()->getSubsiteId(); } diff --git a/src/Extensions/FolderFormFactoryExtension.php b/src/Extensions/FolderFormFactoryExtension.php index b1feabd7..e4071212 100644 --- a/src/Extensions/FolderFormFactoryExtension.php +++ b/src/Extensions/FolderFormFactoryExtension.php @@ -18,7 +18,7 @@ class FolderFormFactoryExtension extends Extension * Add subsites-specific fields to the folder editor. * @param FieldList $fields */ - public function updateFormFields(FieldList $fields) + protected function updateFormFields(FieldList $fields) { $sites = Subsite::accessible_sites('CMS_ACCESS_AssetAdmin'); $values = []; diff --git a/src/Extensions/GroupSubsites.php b/src/Extensions/GroupSubsites.php index 9ebedb09..469622dc 100644 --- a/src/Extensions/GroupSubsites.php +++ b/src/Extensions/GroupSubsites.php @@ -78,7 +78,7 @@ public function requireDefaultRecords() } } - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { if ($this->owner->canEdit()) { // i18n tab @@ -132,7 +132,7 @@ public function updateCMSFields(FieldList $fields) * * @param string $title */ - public function updateTreeTitle(&$title) + protected function updateTreeTitle(&$title) { if ($this->owner->AccessAllSubsites) { $title = _t(__CLASS__ . '.GlobalGroup', 'global group'); @@ -148,7 +148,7 @@ public function updateTreeTitle(&$title) * @param SQLSelect $query * @param DataQuery|null $dataQuery */ - public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) + protected function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { if (Subsite::$disable_subsite_filter) { return; @@ -203,7 +203,7 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) } } - public function onBeforeWrite() + protected function onBeforeWrite() { // New record test approximated by checking whether the ID has changed. // Note also that the after write test is only used when we're *not* on a subsite @@ -212,7 +212,7 @@ public function onBeforeWrite() } } - public function onAfterWrite() + protected function onAfterWrite() { // New record test approximated by checking whether the ID has changed. // Note also that the after write test is only used when we're on a subsite diff --git a/src/Extensions/HintsCacheKeyExtension.php b/src/Extensions/HintsCacheKeyExtension.php index 19ece6c4..dba88efd 100644 --- a/src/Extensions/HintsCacheKeyExtension.php +++ b/src/Extensions/HintsCacheKeyExtension.php @@ -16,7 +16,7 @@ */ class HintsCacheKeyExtension extends Extension { - public function updateHintsCacheKey(&$baseKey) + protected function updateHintsCacheKey(&$baseKey) { $baseKey .= '_Subsite:' . SubsiteState::singleton()->getSubsiteId(); } diff --git a/src/Extensions/LeftAndMainSubsites.php b/src/Extensions/LeftAndMainSubsites.php index 147ef280..733b092d 100644 --- a/src/Extensions/LeftAndMainSubsites.php +++ b/src/Extensions/LeftAndMainSubsites.php @@ -56,7 +56,7 @@ public function getCMSTreeTitle() return $subsite ? Convert::raw2xml($subsite->Title) : _t(__CLASS__.'.SITECONTENTLEFT', 'Site Content'); } - public function updatePageOptions(&$fields) + protected function updatePageOptions(&$fields) { $fields->push(HiddenField::create('SubsiteID', 'SubsiteID', SubsiteState::singleton()->getSubsiteId())); } @@ -266,7 +266,7 @@ public function alternateAccessCheck(Member $member = null) * fully re-synchronised with the internal session. This is better than risking some panels * showing data from another subsite. */ - public function onBeforeInit() + protected function onBeforeInit() { $request = Controller::curr()->getRequest(); $session = $request->getSession(); @@ -381,13 +381,13 @@ public function onBeforeInit() return; } - public function augmentNewSiteTreeItem(&$item) + protected function augmentNewSiteTreeItem(&$item) { $request = Controller::curr()->getRequest(); $item->SubsiteID = $request->postVar('SubsiteID') ?: SubsiteState::singleton()->getSubsiteId(); } - public function onAfterSave($record) + protected function onAfterSave($record) { if ($record->hasMethod('NormalRelated') && ($record->NormalRelated() || $record->ReverseRelated())) { $this->owner->response->addHeader( diff --git a/src/Extensions/SiteConfigSubsites.php b/src/Extensions/SiteConfigSubsites.php index 4f768ae5..5125c820 100644 --- a/src/Extensions/SiteConfigSubsites.php +++ b/src/Extensions/SiteConfigSubsites.php @@ -29,7 +29,7 @@ class SiteConfigSubsites extends DataExtension * @param SQLSelect $query * @param DataQuery|null $dataQuery */ - public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) + protected function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { if (Subsite::$disable_subsite_filter) { return; @@ -60,7 +60,7 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) $query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)"); } - public function onBeforeWrite() + protected function onBeforeWrite() { if ((!is_numeric($this->owner->ID) || !$this->owner->ID) && !$this->owner->SubsiteID) { $this->owner->SubsiteID = SubsiteState::singleton()->getSubsiteId(); @@ -70,12 +70,12 @@ public function onBeforeWrite() /** * Return a piece of text to keep DataObject cache keys appropriately specific */ - public function cacheKeyComponent() + protected function cacheKeyComponent() { return 'subsite-' . SubsiteState::singleton()->getSubsiteId(); } - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { $fields->push(HiddenField::create('SubsiteID', 'SubsiteID', SubsiteState::singleton()->getSubsiteId())); } diff --git a/src/Extensions/SiteTreeSubsites.php b/src/Extensions/SiteTreeSubsites.php index 8db1a580..0f38a477 100644 --- a/src/Extensions/SiteTreeSubsites.php +++ b/src/Extensions/SiteTreeSubsites.php @@ -63,7 +63,7 @@ public function isMainSite() * @param SQLSelect $query * @param DataQuery $dataQuery */ - public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) + protected function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { if (Subsite::$disable_subsite_filter) { return; @@ -98,7 +98,7 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) } } - public function onBeforeWrite() + protected function onBeforeWrite() { if (!$this->owner->ID && !$this->owner->SubsiteID) { $this->owner->SubsiteID = SubsiteState::singleton()->getSubsiteId(); @@ -107,7 +107,7 @@ public function onBeforeWrite() parent::onBeforeWrite(); } - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { $subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain'); if ($subsites && $subsites->count()) { @@ -225,7 +225,7 @@ public function duplicateToSubsitePrep($subsiteID, $includeChildren) /** * When duplicating a page, assign the current subsite ID from the state */ - public function onBeforeDuplicate() + protected function onBeforeDuplicate() { $subsiteId = SubsiteState::singleton()->getSubsiteId(); if ($subsiteId !== null) { @@ -290,7 +290,7 @@ public function duplicateSubsiteRelations($originalPage) /** * @return SiteConfig */ - public function alternateSiteConfig() + protected function alternateSiteConfig() { if (!$this->owner->SubsiteID) { return false; @@ -433,7 +433,7 @@ public function alternateAbsoluteLink($action = null) * @param string|null $action * @return string */ - public function updatePreviewLink(&$link, $action = null) + protected function updatePreviewLink(&$link, $action = null) { $url = Director::absoluteURL($this->owner->Link($action)); $link = HTTP::setGetVar('SubsiteID', $this->owner->SubsiteID, $url); @@ -454,7 +454,7 @@ public function MetaTags(&$tags) return $tags; } - public function augmentSyncLinkTracking() + protected function augmentSyncLinkTracking() { // Set LinkTracking appropriately $links = HTTP::getLinksIn($this->owner->Content); @@ -502,7 +502,7 @@ public function augmentSyncLinkTracking() * * @return null|bool Either true or false, or null to not influence result */ - public function augmentValidURLSegment() + protected function augmentValidURLSegment() { // If this page is being filtered in the current subsite, then no custom validation query is required. $subsiteID = SubsiteState::singleton()->getSubsiteId(); @@ -518,7 +518,7 @@ public function augmentValidURLSegment() /** * Return a piece of text to keep DataObject cache keys appropriately specific */ - public function cacheKeyComponent() + protected function cacheKeyComponent() { return 'subsite-' . SubsiteState::singleton()->getSubsiteId(); } diff --git a/src/Model/Subsite.php b/src/Model/Subsite.php index a3333a0b..2f508897 100644 --- a/src/Model/Subsite.php +++ b/src/Model/Subsite.php @@ -819,7 +819,7 @@ public function validate() * * @return void */ - public function onAfterWrite() + protected function onAfterWrite() { Subsite::writeHostMap(); if ($this->isChanged('ID')) { diff --git a/src/Model/SubsiteDomain.php b/src/Model/SubsiteDomain.php index 755f069d..3e65be8e 100644 --- a/src/Model/SubsiteDomain.php +++ b/src/Model/SubsiteDomain.php @@ -95,7 +95,7 @@ public function getTitle() * * @return void */ - public function onAfterWrite() + protected function onAfterWrite() { Subsite::writeHostMap(); parent::onAfterWrite(); diff --git a/src/Pages/SubsitesVirtualPage.php b/src/Pages/SubsitesVirtualPage.php index c19eb407..82681fa1 100644 --- a/src/Pages/SubsitesVirtualPage.php +++ b/src/Pages/SubsitesVirtualPage.php @@ -192,7 +192,7 @@ public function syncLinkTracking() Subsite::$disable_subsite_filter = $oldState; } - public function onBeforeWrite() + protected function onBeforeWrite() { parent::onBeforeWrite(); diff --git a/tests/php/FileSubsitesTest.php b/tests/php/FileSubsitesTest.php index 60f40c23..15aa5fde 100644 --- a/tests/php/FileSubsitesTest.php +++ b/tests/php/FileSubsitesTest.php @@ -9,6 +9,7 @@ use SilverStripe\Subsites\Extensions\FileSubsites; use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Security\Member; +use ReflectionMethod; class FileSubsitesTest extends BaseSubsiteTest { @@ -25,7 +26,11 @@ public function testTrivialFeatures() $this->assertEquals('FileTitle', $file->getTreeTitle()); $this->assertInstanceOf(FieldList::class, singleton(Folder::class)->getCMSFields()); Subsite::changeSubsite(1); - $this->assertEquals('subsite-1', $file->getExtensionInstance(FileSubsites::class)->cacheKeyComponent()); + $ext = $file->getExtensionInstance(FileSubsites::class); + $method = new ReflectionMethod(FileSubsites::class, 'cacheKeyComponent'); + $method->setAccessible(true); + $result = $method->invoke($ext); + $this->assertEquals('subsite-1', $result); } public function testWritingSubsiteID() @@ -35,10 +40,13 @@ public function testWritingSubsiteID() $subsite = $this->objFromFixture(Subsite::class, 'domaintest1'); Config::modify()->set(FileSubsites::class, 'default_root_folders_global', true); + $method = new ReflectionMethod(File::class, 'onAfterUpload'); + $method->setAccessible(true); + Subsite::changeSubsite(0); $file = new File(); $file->write(); - $file->onAfterUpload(); + $method->invoke($file); $this->assertEquals((int)$file->SubsiteID, 0); Subsite::changeSubsite($subsite->ID); @@ -63,7 +71,7 @@ public function testWritingSubsiteID() Config::modify()->set(FileSubsites::class, 'default_root_folders_global', true); $file = new File(); $file->ParentID = $folder->ID; - $file->onAfterUpload(); + $method->invoke($file); $this->assertEquals($folder->SubsiteID, $file->SubsiteID); }