Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Set extension hook implementation visibility to protected #571

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Extensions/BaseElementSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/CMSPageAddControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/ErrorPageSubsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
8 changes: 4 additions & 4 deletions src/Extensions/FileSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')) {
Expand All @@ -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()) {
Expand Down Expand Up @@ -132,7 +132,7 @@ public function canEdit($member = null)
*
* @return string
*/
public function cacheKeyComponent()
protected function cacheKeyComponent()
{
return 'subsite-' . SubsiteState::singleton()->getSubsiteId();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/FolderFormFactoryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
10 changes: 5 additions & 5 deletions src/Extensions/GroupSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function requireDefaultRecords()
}
}

public function updateCMSFields(FieldList $fields)
protected function updateCMSFields(FieldList $fields)
{
if ($this->owner->canEdit()) {
// i18n tab
Expand Down Expand Up @@ -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');
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/HintsCacheKeyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class HintsCacheKeyExtension extends Extension
{
public function updateHintsCacheKey(&$baseKey)
protected function updateHintsCacheKey(&$baseKey)
{
$baseKey .= '_Subsite:' . SubsiteState::singleton()->getSubsiteId();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Extensions/LeftAndMainSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions src/Extensions/SiteConfigSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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()));
}
Expand Down
18 changes: 9 additions & 9 deletions src/Extensions/SiteTreeSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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()) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -290,7 +290,7 @@ public function duplicateSubsiteRelations($originalPage)
/**
* @return SiteConfig
*/
public function alternateSiteConfig()
protected function alternateSiteConfig()
{
if (!$this->owner->SubsiteID) {
return false;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Subsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ public function validate()
*
* @return void
*/
public function onAfterWrite()
protected function onAfterWrite()
{
Subsite::writeHostMap();
if ($this->isChanged('ID')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Model/SubsiteDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function getTitle()
*
* @return void
*/
public function onAfterWrite()
protected function onAfterWrite()
{
Subsite::writeHostMap();
parent::onAfterWrite();
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/SubsitesVirtualPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function syncLinkTracking()
Subsite::$disable_subsite_filter = $oldState;
}

public function onBeforeWrite()
protected function onBeforeWrite()
{
parent::onBeforeWrite();

Expand Down
14 changes: 11 additions & 3 deletions tests/php/FileSubsitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use SilverStripe\Subsites\Extensions\FileSubsites;
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Security\Member;
use ReflectionMethod;

class FileSubsitesTest extends BaseSubsiteTest
{
Expand All @@ -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()
Expand All @@ -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);
Expand All @@ -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);
}

Expand Down
Loading