From 3845f70b883f3aa4246f0a5fcc6fc7fedb8c10d2 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 21 May 2024 15:00:16 +1200 Subject: [PATCH] API Set extension hook implementation visibility to protected --- src/Extension/FluentChangesExtension.php | 2 +- src/Extension/FluentDirectorExtension.php | 2 +- src/Extension/FluentExtension.php | 18 ++++++++--------- src/Extension/FluentFilteredExtension.php | 10 +++++----- src/Extension/FluentGridFieldExtension.php | 4 ++-- src/Extension/FluentIsolatedExtension.php | 8 ++++---- src/Extension/FluentLeftAndMainExtension.php | 2 +- src/Extension/FluentMemberExtension.php | 2 +- src/Extension/FluentSiteTreeExtension.php | 8 ++++---- src/Extension/FluentVersionedExtension.php | 20 +++++++++---------- src/Extension/Traits/FluentObjectTrait.php | 6 +++--- src/Model/Delete/UsesDeletePolicy.php | 2 +- src/Model/Domain.php | 2 +- src/Model/Locale.php | 4 ++-- .../FluentReadVersionsExtensionTest.php | 7 ++++++- 15 files changed, 51 insertions(+), 46 deletions(-) diff --git a/src/Extension/FluentChangesExtension.php b/src/Extension/FluentChangesExtension.php index 07fc8d61..8198ff37 100644 --- a/src/Extension/FluentChangesExtension.php +++ b/src/Extension/FluentChangesExtension.php @@ -19,7 +19,7 @@ class FluentChangesExtension extends DataExtension * @param int $draftVersion * @param int $liveVersion */ - public function updateChangeType(&$type, $draftVersion, $liveVersion) + protected function updateChangeType(&$type, $draftVersion, $liveVersion) { if ($type !== ChangeSetItem::CHANGE_NONE) { return; diff --git a/src/Extension/FluentDirectorExtension.php b/src/Extension/FluentDirectorExtension.php index 9fb27b78..ca6f8217 100644 --- a/src/Extension/FluentDirectorExtension.php +++ b/src/Extension/FluentDirectorExtension.php @@ -74,7 +74,7 @@ class FluentDirectorExtension extends Extension * @param array &$rules * @throws Exception */ - public function updateRules(&$rules) + protected function updateRules(&$rules) { $request = Injector::inst()->get(HTTPRequest::class); if (!$request) { diff --git a/src/Extension/FluentExtension.php b/src/Extension/FluentExtension.php index ff4f6820..260fb781 100644 --- a/src/Extension/FluentExtension.php +++ b/src/Extension/FluentExtension.php @@ -360,7 +360,7 @@ protected function anyMatch($value, $patterns) return false; } - public function augmentDatabase() + protected function augmentDatabase() { // Build _Localisation table $class = get_class($this->owner); @@ -462,7 +462,7 @@ protected function augmentDatabaseRequireTable($localisedTable, $fields, $indexe DB::require_table($localisedTable, $fields, $indexes, false); } - public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) + protected function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { $locale = $this->getDataQueryLocale($dataQuery); if (!$locale) { @@ -599,7 +599,7 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) * loading a page in a different locale and pressing "save" won't actually make the record available in * this locale. */ - public function onBeforeWrite(): void + protected function onBeforeWrite(): void { $owner = $this->owner; $currentLocale = FluentState::singleton()->getLocale(); @@ -625,7 +625,7 @@ public function onBeforeWrite(): void /** * @throws ValidationException */ - public function onAfterWrite(): void + protected function onAfterWrite(): void { $this->handleClassChanged(); } @@ -728,7 +728,7 @@ static function (FluentState $state) use ($recordLocale, $localisedRecord): void * * @throws LogicException if the manipulation table's ID is missing */ - public function augmentWrite(&$manipulation) + protected function augmentWrite(&$manipulation) { $locale = Locale::getCurrentLocale(); if (!$locale) { @@ -1068,7 +1068,7 @@ public function BaseURLForLocale($locale) * * @return string */ - public function cacheKeyComponent() + protected function cacheKeyComponent() { return 'fluentlocale-' . FluentState::singleton()->getLocale(); } @@ -1076,7 +1076,7 @@ public function cacheKeyComponent() /** * @param FieldList $fields */ - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { // If there is no current FluentState, then we shouldn't update. if (!FluentState::singleton()->getLocale()) { @@ -1245,7 +1245,7 @@ protected function findRecordInLocale($locale, $table, $id) * @param $summaryColumns * @see FluentObjectTrait::updateFluentCMSFields() */ - public function updateLocalisationTabColumns(&$summaryColumns) + protected function updateLocalisationTabColumns(&$summaryColumns) { $summaryColumns['Status'] = [ 'title' => 'Status', @@ -1286,7 +1286,7 @@ public function updateLocalisationTabColumns(&$summaryColumns) * * @param GridFieldConfig $config */ - public function updateLocalisationTabConfig(GridFieldConfig $config) + protected function updateLocalisationTabConfig(GridFieldConfig $config) { // Add locale copy actions $config->addComponents([ diff --git a/src/Extension/FluentFilteredExtension.php b/src/Extension/FluentFilteredExtension.php index b7dac66c..79836aa0 100644 --- a/src/Extension/FluentFilteredExtension.php +++ b/src/Extension/FluentFilteredExtension.php @@ -38,7 +38,7 @@ class FluentFilteredExtension extends DataExtension 'FilteredLocales' => Locale::class, ]; - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { $locales = Locale::getCached(); @@ -58,7 +58,7 @@ public function updateCMSFields(FieldList $fields) * * @param array $flags */ - public function updateStatusFlags(&$flags) + protected function updateStatusFlags(&$flags) { // If there is no current FluentState, then we shouldn't update. if (!FluentState::singleton()->getLocale()) { @@ -101,7 +101,7 @@ public function isAvailableInLocale($locale = null) * @param SQLSelect $query * @param DataQuery|null $dataQuery */ - public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) + protected function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { // We don't want this logic applied in the CMS. if (!FluentState::singleton()->getIsFrontend()) { @@ -170,13 +170,13 @@ protected function getModeIsStage() return substr_compare($readingMode, $draft, strlen($readingMode) - strlen($draft), strlen($draft)) === 0; } - public function updateLocalisationTabConfig(GridFieldConfig $config) + protected function updateLocalisationTabConfig(GridFieldConfig $config) { // Add inline toggle on/off to gridfield $config->addComponent(LocaleToggleColumn::create()); } - public function updateLocalisationTabColumns(&$summaryColumns) + protected function updateLocalisationTabColumns(&$summaryColumns) { // no-op } diff --git a/src/Extension/FluentGridFieldExtension.php b/src/Extension/FluentGridFieldExtension.php index 2a2ca326..41fd528a 100644 --- a/src/Extension/FluentGridFieldExtension.php +++ b/src/Extension/FluentGridFieldExtension.php @@ -31,13 +31,13 @@ class FluentGridFieldExtension extends Extension * @param DBField|null $badgeField * @see VersionedGridFieldItemRequest::Breadcrumbs() */ - public function updateBadge(&$badgeField) + protected function updateBadge(&$badgeField) { $record = $this->owner->getRecord(); $badgeField = $this->addFluentBadge($badgeField, $record); } - public function updateFormActions(FieldList $actions) + protected function updateFormActions(FieldList $actions) { $this->updateFluentActions($actions, $this->owner->getRecord()); } diff --git a/src/Extension/FluentIsolatedExtension.php b/src/Extension/FluentIsolatedExtension.php index b2e83dd0..d3d68439 100644 --- a/src/Extension/FluentIsolatedExtension.php +++ b/src/Extension/FluentIsolatedExtension.php @@ -27,7 +27,7 @@ class FluentIsolatedExtension extends DataExtension 'Locale' => Locale::class, ]; - public function onBeforeWrite() + protected function onBeforeWrite() { if (empty($this->owner->LocaleID)) { $locale = Locale::getCurrentLocale(); @@ -43,7 +43,7 @@ public function onBeforeWrite() * @param SQLSelect $query * @param DataQuery $dataQuery */ - public function augmentDataQueryCreation(SQLSelect $query, DataQuery $dataQuery) + protected function augmentDataQueryCreation(SQLSelect $query, DataQuery $dataQuery) { $state = FluentState::singleton(); $dataQuery @@ -56,7 +56,7 @@ public function augmentDataQueryCreation(SQLSelect $query, DataQuery $dataQuery) * * @throws LogicException */ - public function augmentDatabase() + protected function augmentDatabase() { // Safety check: This extension cannot be added with fluent or filtered extensions if ($this->owner->hasExtension(FluentFilteredExtension::class) @@ -79,7 +79,7 @@ public function requireDefaultRecords() * @param SQLSelect $query * @param DataQuery|null $dataQuery */ - public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) + protected function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { $locale = $this->getDataQueryLocale($dataQuery); if (!$locale) { diff --git a/src/Extension/FluentLeftAndMainExtension.php b/src/Extension/FluentLeftAndMainExtension.php index 8135059d..f274df67 100644 --- a/src/Extension/FluentLeftAndMainExtension.php +++ b/src/Extension/FluentLeftAndMainExtension.php @@ -31,7 +31,7 @@ public function init() * @param ArrayList $breadcrumbs * @see CMSMain::Breadcrumbs() */ - public function updateBreadcrumbs(ArrayList $breadcrumbs) + protected function updateBreadcrumbs(ArrayList $breadcrumbs) { $record = $this->owner->currentPage(); if (!$record) { diff --git a/src/Extension/FluentMemberExtension.php b/src/Extension/FluentMemberExtension.php index 276b87b9..45a7b283 100644 --- a/src/Extension/FluentMemberExtension.php +++ b/src/Extension/FluentMemberExtension.php @@ -21,7 +21,7 @@ class FluentMemberExtension extends DataExtension * * @param Member_GroupSet $groups */ - public function updateGroups(Member_GroupSet &$groups) + protected function updateGroups(Member_GroupSet &$groups) { // Filter groups by those that either have no locales selected (same as selected for all), // or groups that have the current locale selected. diff --git a/src/Extension/FluentSiteTreeExtension.php b/src/Extension/FluentSiteTreeExtension.php index 0eedf5dc..355981ba 100644 --- a/src/Extension/FluentSiteTreeExtension.php +++ b/src/Extension/FluentSiteTreeExtension.php @@ -164,7 +164,7 @@ public function updateLink(&$link, &$action, &$relativeLink) * * @param array $flags */ - public function updateStatusFlags(&$flags) + protected function updateStatusFlags(&$flags) { // If there is no current FluentState, then we shouldn't update. if (!FluentState::singleton()->getLocale()) { @@ -187,7 +187,7 @@ public function updateStatusFlags(&$flags) /** * @param FieldList $fields */ - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { // If there is no current FluentState, then we shouldn't update. if (!FluentState::singleton()->getLocale()) { @@ -202,7 +202,7 @@ public function updateCMSFields(FieldList $fields) /** * @param FieldList $actions */ - public function updateCMSActions(FieldList $actions) + protected function updateCMSActions(FieldList $actions) { // If there is no current FluentState, then we shouldn't update. if (!FluentState::singleton()->getLocale()) { @@ -535,7 +535,7 @@ public function actionComplete($form, $message) * @param $summaryColumns * @see FluentExtension::updateFluentCMSFields() */ - public function updateLocalisationTabColumns(&$summaryColumns) + protected function updateLocalisationTabColumns(&$summaryColumns) { parent::updateLocalisationTabColumns($summaryColumns); diff --git a/src/Extension/FluentVersionedExtension.php b/src/Extension/FluentVersionedExtension.php index 83ddc7df..64c7c366 100644 --- a/src/Extension/FluentVersionedExtension.php +++ b/src/Extension/FluentVersionedExtension.php @@ -108,7 +108,7 @@ class FluentVersionedExtension extends FluentExtension implements Resettable */ private static $prepopulate_localecontent_cache = true; - public function augmentDatabase() + protected function augmentDatabase() { // Safety check: This extension is added AFTER versioned $seenVersioned = false; @@ -155,7 +155,7 @@ protected function augmentDatabaseRequireTable($localisedTable, $fields, $indexe * * @throws InvalidArgumentException if an invalid versioned mode is provided */ - public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) + protected function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { $locale = $this->getDataQueryLocale($dataQuery); if (!$locale) { @@ -281,7 +281,7 @@ protected function localiseVersionsLookup(SQLSelect $query, Locale $locale) * * @param array $manipulation */ - public function augmentWrite(&$manipulation) + protected function augmentWrite(&$manipulation) { parent::augmentWrite($manipulation); @@ -527,7 +527,7 @@ public static function reset() * @param array $options A map of hints about what should be cached. "numChildrenMethod" and * "childrenMethod" are allowed keys. */ - public function onPrepopulateTreeDataCache($recordList = null, array $options = []) + protected function onPrepopulateTreeDataCache($recordList = null, array $options = []) { if (!Config::inst()->get(self::class, 'prepopulate_localecontent_cache')) { return; @@ -586,7 +586,7 @@ public static function prepoulateIdsInLocale($locale, $dataObjectClass, $populat } } - public function updateLocalisationTabColumns(&$summaryColumns) + protected function updateLocalisationTabColumns(&$summaryColumns) { $summaryColumns['Status'] = [ 'title' => 'Status', @@ -649,7 +649,7 @@ public function updateLocalisationTabColumns(&$summaryColumns) * * @param GridFieldConfig $config */ - public function updateLocalisationTabConfig(GridFieldConfig $config) + protected function updateLocalisationTabConfig(GridFieldConfig $config) { parent::updateLocalisationTabConfig($config); @@ -665,7 +665,7 @@ public function updateLocalisationTabConfig(GridFieldConfig $config) * * @param bool $stagesDiffer */ - public function updateStagesDiffer(bool &$stagesDiffer): void + protected function updateStagesDiffer(bool &$stagesDiffer): void { $locale = FluentState::singleton()->getLocale(); @@ -682,7 +682,7 @@ public function updateStagesDiffer(bool &$stagesDiffer): void * * @param bool $isArchived */ - public function updateIsArchived(bool &$isArchived): void + protected function updateIsArchived(bool &$isArchived): void { $locale = FluentState::singleton()->getLocale(); @@ -816,7 +816,7 @@ public function augmentMaxVersionSubSelect( * @param string $stage * @param array|null $idList */ - public function updatePrePopulateVersionNumberCache(array $versions, $class, string $stage, ?array $idList): void + protected function updatePrePopulateVersionNumberCache(array $versions, $class, string $stage, ?array $idList): void { $locale = FluentState::singleton()->getLocale(); @@ -850,7 +850,7 @@ public function updatePrePopulateVersionNumberCache(array $versions, $class, str * @param int $id * @param bool $cache */ - public function updateGetVersionNumberByStage(?int &$version, $class, string $stage, int $id, bool $cache): void + protected function updateGetVersionNumberByStage(?int &$version, $class, string $stage, int $id, bool $cache): void { $locale = FluentState::singleton()->getLocale(); diff --git a/src/Extension/Traits/FluentObjectTrait.php b/src/Extension/Traits/FluentObjectTrait.php index 54076df5..45be8779 100644 --- a/src/Extension/Traits/FluentObjectTrait.php +++ b/src/Extension/Traits/FluentObjectTrait.php @@ -25,14 +25,14 @@ trait FluentObjectTrait * @param $summaryColumns * @see FluentObjectTrait::updateFluentCMSFields() */ - abstract public function updateLocalisationTabColumns(&$summaryColumns); + abstract protected function updateLocalisationTabColumns(&$summaryColumns); /** * Add additional configs to localisation table * * @param GridFieldConfig $config */ - abstract public function updateLocalisationTabConfig( + abstract protected function updateLocalisationTabConfig( GridFieldConfig $config ); @@ -70,7 +70,7 @@ public function LinkedLocales() * @param SQLSelect $query * @param DataQuery $dataQuery */ - public function augmentDataQueryCreation( + protected function augmentDataQueryCreation( SQLSelect $query, DataQuery $dataQuery ) { diff --git a/src/Model/Delete/UsesDeletePolicy.php b/src/Model/Delete/UsesDeletePolicy.php index f403cac8..cd94f400 100644 --- a/src/Model/Delete/UsesDeletePolicy.php +++ b/src/Model/Delete/UsesDeletePolicy.php @@ -16,7 +16,7 @@ trait UsesDeletePolicy * * @param array $queriedTables */ - public function updateDeleteTables(&$queriedTables) + protected function updateDeleteTables(&$queriedTables) { // Ensure a locale exists $locale = Locale::getCurrentLocale(); diff --git a/src/Model/Domain.php b/src/Model/Domain.php index 1888a401..0ec2fcdf 100644 --- a/src/Model/Domain.php +++ b/src/Model/Domain.php @@ -200,7 +200,7 @@ public function getLocaleNames() return implode(', ', $this->getLocales()->column('Locale')); } - public function onBeforeWrite() + protected function onBeforeWrite() { parent::onBeforeWrite(); diff --git a/src/Model/Locale.php b/src/Model/Locale.php index e97715db..ff6e1247 100644 --- a/src/Model/Locale.php +++ b/src/Model/Locale.php @@ -230,7 +230,7 @@ public function getLocaleSuffix() * * For example, you may want to display the full locale badge: * - * public function updateBadgeLabel(&$badgeLabel) + * protected function updateBadgeLabel(&$badgeLabel) * { * $badgeLabel = $this->owner->Locale; * } @@ -499,7 +499,7 @@ public static function getLocales($domain = null) return Locale::getCached(); } - public function onAfterWrite() + protected function onAfterWrite() { parent::onAfterWrite(); diff --git a/tests/php/Extension/FluentReadVersionsExtensionTest.php b/tests/php/Extension/FluentReadVersionsExtensionTest.php index 7b41834d..2ced60b9 100644 --- a/tests/php/Extension/FluentReadVersionsExtensionTest.php +++ b/tests/php/Extension/FluentReadVersionsExtensionTest.php @@ -7,6 +7,7 @@ use TractorCow\Fluent\Extension\FluentReadVersionsExtension; use TractorCow\Fluent\Extension\FluentSiteTreeExtension; use TractorCow\Fluent\State\FluentState; +use ReflectionMethod; class FluentReadVersionsExtensionTest extends SapphireTest { @@ -25,7 +26,11 @@ public function testUpdateListSetsCurrentLocaleIntoHavingInQuery() $list = SiteTree::get(); $extension = new FluentReadVersionsExtension(); - $extension->updateList($list); + $method = new ReflectionMethod(FluentReadVersionsExtension::class, 'updateList'); + $method->setAccessible(true); + // Note this MUST be passed by reference, it cannot be changed not be passed by reference + // in the extension method as the reference to the list is updated in the method + $method->invokeArgs($extension, [&$list]); $this->assertContains( ['"SourceLocale" = ?' => ['en_NZ']],