From 4f4a2294ce4b4f90cbad923d5d40c30e81139c74 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Mon, 20 May 2024 15:20:49 +1200 Subject: [PATCH] API Set extension hook implementation visibility to protected --- src/Dev/VersionedTestSessionExtension.php | 4 ++-- src/RecursivePublishable.php | 2 +- src/RecursivePublishableHandler.php | 2 +- src/Versioned.php | 24 +++++++++++----------- src/VersionedGridFieldArchiveExtension.php | 2 +- src/VersionedGridFieldDetailForm.php | 2 +- src/VersionedGridFieldStateExtension.php | 2 +- src/VersionedTableDataQueryExtension.php | 2 +- tests/php/VersionedNumberCacheTest.php | 8 +++++++- tests/php/VersionedTest/TestObject.php | 2 +- 10 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/Dev/VersionedTestSessionExtension.php b/src/Dev/VersionedTestSessionExtension.php index ad054e7d..b3f45f0e 100644 --- a/src/Dev/VersionedTestSessionExtension.php +++ b/src/Dev/VersionedTestSessionExtension.php @@ -54,7 +54,7 @@ protected function getReadingmode() * * @param string $link */ - public function updateGetURL(&$link) + protected function updateGetURL(&$link) { $this->updateLink($link); } @@ -64,7 +64,7 @@ public function updateGetURL(&$link) * * @param string $link */ - public function updatePostURL(&$link) + protected function updatePostURL(&$link) { // Default to same as http get $this->updateLink($link); diff --git a/src/RecursivePublishable.php b/src/RecursivePublishable.php index 25df24f4..6ddecc9f 100644 --- a/src/RecursivePublishable.php +++ b/src/RecursivePublishable.php @@ -432,7 +432,7 @@ public function unlinkDisownedRelationship($source, $targetStage, $relationship) * @param bool $doWrite * @param array|null|false $relations */ - public function onBeforeDuplicate($original, &$doWrite, &$relations) + protected function onBeforeDuplicate($original, &$doWrite, &$relations) { // If relations to duplicate are declared (or forced off) don't rewrite if ($relations || $relations === false) { diff --git a/src/RecursivePublishableHandler.php b/src/RecursivePublishableHandler.php index 7d4d9b82..6432fc49 100644 --- a/src/RecursivePublishableHandler.php +++ b/src/RecursivePublishableHandler.php @@ -17,7 +17,7 @@ class RecursivePublishableHandler extends Extension * Ensure that non-versioned records are published on save. * @param DataObject $record */ - public function onAfterSave(DataObject $record) + protected function onAfterSave(DataObject $record) { // Assume that any versioned record has an explicit publish already if (!$record->hasExtension(Versioned::class)) { diff --git a/src/Versioned.php b/src/Versioned.php index e1f18060..d0f610f4 100644 --- a/src/Versioned.php +++ b/src/Versioned.php @@ -313,7 +313,7 @@ public static function reset() * @param SQLSelect $query * @param DataQuery $dataQuery */ - public function augmentDataQueryCreation(SQLSelect &$query, DataQuery &$dataQuery) + protected function augmentDataQueryCreation(SQLSelect &$query, DataQuery &$dataQuery) { // Convert reading mode to dataquery params and assign $args = ReadingMode::toDataQueryParams(Versioned::get_reading_mode()); @@ -405,7 +405,7 @@ protected function getLastEditedAndStageForVersion($version) * * @param array $params */ - public function updateInheritableQueryParams(&$params) + protected function updateInheritableQueryParams(&$params) { // Skip if versioned isn't set if (!isset($params['Versioned.mode'])) { @@ -455,7 +455,7 @@ public function updateInheritableQueryParams(&$params) * @param DataQuery|null $dataQuery * @throws InvalidArgumentException */ - public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) + protected function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { if (!$dataQuery) { return; @@ -896,7 +896,7 @@ protected function isTableVersioned($table) * @param DataQuery $dataQuery * @param DataObject $dataObject */ - public function augmentLoadLazyFields(SQLSelect &$query, DataQuery &$dataQuery = null, $dataObject) + protected function augmentLoadLazyFields(SQLSelect &$query, DataQuery &$dataQuery = null, $dataObject) { // The VersionedMode local variable ensures that this decorator only applies to // queries that have originated from the Versioned object, and have the Versioned @@ -917,7 +917,7 @@ public function augmentLoadLazyFields(SQLSelect &$query, DataQuery &$dataQuery = } } - public function augmentDatabase() + protected function augmentDatabase() { $owner = $this->owner; $class = get_class($owner); @@ -1257,7 +1257,7 @@ protected function createDeletedVersion($stages = []) $this->owner->extend('onAfterVersionDelete'); } - public function augmentWrite(&$manipulation) + protected function augmentWrite(&$manipulation) { // get Version number from base data table on write $version = null; @@ -1416,7 +1416,7 @@ protected function suppressDeletedVersion($callback) * If a write was skipped, then we need to ensure that we don't leave a * migrateVersion() value lying around for the next write. */ - public function onAfterSkippedWrite() + protected function onAfterSkippedWrite() { $this->setMigratingVersion(null); } @@ -2452,7 +2452,7 @@ private static function determineVersionNumberByStage($class, $stage, $id, $cach * @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 = []) { $idList = is_array($recordList) ? $recordList : ($recordList instanceof DataList ? $recordList->column('ID') : null); @@ -2888,7 +2888,7 @@ public static function get_all_versions($class, $id) /** * @param array $labels */ - public function updateFieldLabels(&$labels) + protected function updateFieldLabels(&$labels) { $labels['Versions'] = _t(__CLASS__ . '.has_many_Versions', 'Versions', 'Past Versions of this record'); } @@ -2896,7 +2896,7 @@ public function updateFieldLabels(&$labels) /** * @param FieldList $fields */ - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { // remove the version field from the CMS as this should be left // entirely up to the extension (not the cms user). @@ -2909,7 +2909,7 @@ public function updateCMSFields(FieldList $fields) * @param DataObject $source Record this was duplicated from * @param bool $doWrite */ - public function onBeforeDuplicate($source, $doWrite) + protected function onBeforeDuplicate($source, $doWrite) { $this->owner->Version = 0; } @@ -2925,7 +2925,7 @@ public function flushCache() * * @return string */ - public function cacheKeyComponent() + protected function cacheKeyComponent() { return 'versionedmode-' . static::get_reading_mode(); } diff --git a/src/VersionedGridFieldArchiveExtension.php b/src/VersionedGridFieldArchiveExtension.php index ede29a1e..f600b3b6 100644 --- a/src/VersionedGridFieldArchiveExtension.php +++ b/src/VersionedGridFieldArchiveExtension.php @@ -13,7 +13,7 @@ */ class VersionedGridFieldArchiveExtension extends Extension { - public function updateConfig() + protected function updateConfig() { $owner = $this->getOwner(); $owner->addComponent(new GridFieldArchiveAction(), GridFieldDeleteAction::class); diff --git a/src/VersionedGridFieldDetailForm.php b/src/VersionedGridFieldDetailForm.php index 8ecf0237..1a6c1feb 100644 --- a/src/VersionedGridFieldDetailForm.php +++ b/src/VersionedGridFieldDetailForm.php @@ -20,7 +20,7 @@ class VersionedGridFieldDetailForm extends Extension * @param RequestHandler $requestHandler * @param string $assignedClass Name of class explicitly assigned to this component */ - public function updateItemRequestClass(&$class, $gridField, $record, $requestHandler, $assignedClass = null) + protected function updateItemRequestClass(&$class, $gridField, $record, $requestHandler, $assignedClass = null) { // Avoid overriding explicitly assigned class name if set using setItemRequestClass() if ($assignedClass) { diff --git a/src/VersionedGridFieldStateExtension.php b/src/VersionedGridFieldStateExtension.php index dd2039ac..c5130cbc 100644 --- a/src/VersionedGridFieldStateExtension.php +++ b/src/VersionedGridFieldStateExtension.php @@ -13,7 +13,7 @@ */ class VersionedGridFieldStateExtension extends Extension { - public function updateConfig() + protected function updateConfig() { $owner = $this->getOwner(); if (!$owner->getComponentByType(VersionedGridFieldState::class)) { diff --git a/src/VersionedTableDataQueryExtension.php b/src/VersionedTableDataQueryExtension.php index 42944986..3557dc83 100644 --- a/src/VersionedTableDataQueryExtension.php +++ b/src/VersionedTableDataQueryExtension.php @@ -21,7 +21,7 @@ class VersionedTableDataQueryExtension extends Extension * @param string $table * @param string $updated */ - public function updateJoinTableName($class, $table, &$updated) + protected function updateJoinTableName($class, $table, &$updated) { $inst = Injector::inst()->get($class); if (!$inst->hasExtension(Versioned::class) || !$inst->hasStages()) { diff --git a/tests/php/VersionedNumberCacheTest.php b/tests/php/VersionedNumberCacheTest.php index cf4bde41..eafd31ad 100644 --- a/tests/php/VersionedNumberCacheTest.php +++ b/tests/php/VersionedNumberCacheTest.php @@ -5,6 +5,7 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Tests\VersionedTest\TestObject; +use ReflectionMethod; /** * @internal Only test the right values are returned, not that the cache is actually used. @@ -100,7 +101,12 @@ public function testVersionNumberCache($stage, $ID, $cache, $expected) */ public function testPrepopulatedVersionNumberCache($stage, $ID, $cache, $expected) { - TestObject::singleton()->onPrepopulateTreeDataCache(); + $owner = TestObject::singleton(); + $ext = new Versioned(); + $ext->setOwner($owner); + $method = new ReflectionMethod(Versioned::class, 'onPrepopulateTreeDataCache'); + $method->setAccessible(true); + $method->invoke($ext); $actual = Versioned::get_versionnumber_by_stage(TestObject::class, $stage, self::${$ID}, $cache); $this->assertEquals(self::$expectedVersions[$expected], $actual); } diff --git a/tests/php/VersionedTest/TestObject.php b/tests/php/VersionedTest/TestObject.php index 14ab57c5..28ae717b 100644 --- a/tests/php/VersionedTest/TestObject.php +++ b/tests/php/VersionedTest/TestObject.php @@ -72,7 +72,7 @@ public function canView($member = null) return true; } - public function onAfterPublish($original) + protected function onAfterPublish($original) { if (self::$setNameWithoutVersionAfterPublish !== null) { $this->Name = self::$setNameWithoutVersionAfterPublish;