From b0499f255f29fbf5cbe0fd82e44dc6d58cdcb8d8 Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Fri, 13 Jul 2018 20:56:31 +0200 Subject: [PATCH] [TASK] Deprecate PageRepository->versioningWorkspaceId The property does not need to be accessed from the outside anymore, and can be marked as protected/deprecated, as this information is all stored within the given context of the page repository. Resolves: #85556 Releases: master Change-Id: I36072c06b6ac5c5faa5ebce5b373e76530af7509 Reviewed-on: https://review.typo3.org/57592 Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de> Tested-by: TYPO3com <no-reply@typo3.com> Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Tested-by: Wouter Wolters <typo3@wouterwolters.nl> --- .../FrontendWorkspaceRestriction.php | 7 +++- ...6-PageRepository-versioningWorkspaceId.rst | 38 +++++++++++++++++++ .../FrontendWorkspaceRestrictionTest.php | 18 +++------ .../Generic/Storage/Typo3DbBackendTest.php | 9 ++--- .../ContentObject/ContentObjectRenderer.php | 3 +- .../frontend/Classes/Page/PageRepository.php | 4 +- .../Php/PropertyPublicMatcher.php | 5 +++ 7 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-85556-PageRepository-versioningWorkspaceId.rst diff --git a/typo3/sysext/core/Classes/Database/Query/Restriction/FrontendWorkspaceRestriction.php b/typo3/sysext/core/Classes/Database/Query/Restriction/FrontendWorkspaceRestriction.php index dc724a8f20fa..0252e7e249f2 100644 --- a/typo3/sysext/core/Classes/Database/Query/Restriction/FrontendWorkspaceRestriction.php +++ b/typo3/sysext/core/Classes/Database/Query/Restriction/FrontendWorkspaceRestriction.php @@ -15,8 +15,10 @@ namespace TYPO3\CMS\Core\Database\Query\Restriction; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression; use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Versioning\VersionState; /** @@ -46,8 +48,9 @@ class FrontendWorkspaceRestriction implements QueryRestrictionInterface */ public function __construct(int $workspaceId = null, bool $includeRowsForWorkspacePreview = null, bool $enforceLiveRowsOnly = true) { - $this->workspaceId = $workspaceId ?? $GLOBALS['TSFE']->sys_page->versioningWorkspaceId; - $this->includeRowsForWorkspacePreview = $includeRowsForWorkspacePreview ?? $GLOBALS['TSFE']->sys_page->versioningWorkspaceId > 0; + $globalWorkspaceId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('workspace', 'id'); + $this->workspaceId = $workspaceId ?? $globalWorkspaceId; + $this->includeRowsForWorkspacePreview = $includeRowsForWorkspacePreview ?? $globalWorkspaceId > 0; $this->enforceLiveRowsOnly = $enforceLiveRowsOnly; } diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85556-PageRepository-versioningWorkspaceId.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85556-PageRepository-versioningWorkspaceId.rst new file mode 100644 index 000000000000..c67def9aa6c9 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85556-PageRepository-versioningWorkspaceId.rst @@ -0,0 +1,38 @@ +.. include:: ../../Includes.txt + +=========================================================== +Deprecation: #85556 - PageRepository->versioningWorkspaceId +=========================================================== + +See :issue:`85556` + +Description +=========== + +The public property :php:`TYPO3\CMS\Frontend\Page\PageRepository->versioningWorkspaceId` has been marked as +deprecated. + + +Impact +====== + +Accessing or setting the property directly will trigger a deprecation message. + + +Affected Installations +====================== + +TYPO3 installations with custom extensions calling this public property directly. + + +Migration +========= + +Use the Context API and its workspace aspect + +:php:`GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('workspace', 'id', 0);` + +directly when reading the workspace ID, or instantiate a custom PageRepository with a custom context (see Context +API docs) for custom usages. + +.. index:: Frontend, PHP-API, FullyScanned, ext:frontend \ No newline at end of file diff --git a/typo3/sysext/core/Tests/Unit/Database/Query/Restriction/FrontendWorkspaceRestrictionTest.php b/typo3/sysext/core/Tests/Unit/Database/Query/Restriction/FrontendWorkspaceRestrictionTest.php index 1f2a73248b0c..671e0f0ed216 100644 --- a/typo3/sysext/core/Tests/Unit/Database/Query/Restriction/FrontendWorkspaceRestrictionTest.php +++ b/typo3/sysext/core/Tests/Unit/Database/Query/Restriction/FrontendWorkspaceRestrictionTest.php @@ -16,10 +16,14 @@ namespace TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction; */ use TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction; -use TYPO3\CMS\Frontend\Page\PageRepository; +/** + * Test case + */ class FrontendWorkspaceRestrictionTest extends AbstractRestrictionTestCase { + protected $resetSingletonInstances = true; + /** * @test */ @@ -33,12 +37,6 @@ class FrontendWorkspaceRestrictionTest extends AbstractRestrictionTestCase ] ]; - $pageRepository = $this->createMock(PageRepository::class); - $pageRepository->versioningWorkspaceId = 0; - - $GLOBALS['TSFE'] = new \stdClass(); - $GLOBALS['TSFE']->sys_page = $pageRepository; - $subject = new FrontendWorkspaceRestriction(0); $expression = $subject->buildExpression(['aTable' => 'aTable'], $this->expressionBuilder); $this->assertSame('("aTable"."t3ver_state" <= 0) AND ("aTable"."pid" <> -1)', (string)$expression); @@ -57,9 +55,6 @@ class FrontendWorkspaceRestrictionTest extends AbstractRestrictionTestCase ] ]; - $pageRepository = $this->createMock(PageRepository::class); - $pageRepository->versioningWorkspaceId = 42; - $subject = new FrontendWorkspaceRestriction(42, true); $expression = $subject->buildExpression(['aTable' => 'aTable'], $this->expressionBuilder); $this->assertSame('(("aTable"."t3ver_wsid" = 0) OR ("aTable"."t3ver_wsid" = 42)) AND ("aTable"."pid" <> -1)', (string)$expression); @@ -78,9 +73,6 @@ class FrontendWorkspaceRestrictionTest extends AbstractRestrictionTestCase ] ]; - $pageRepository = $this->createMock(PageRepository::class); - $pageRepository->versioningWorkspaceId = 42; - $subject = new FrontendWorkspaceRestriction(42, true, false); $expression = $subject->buildExpression(['aTable' => 'aTable'], $this->expressionBuilder); $this->assertSame('("aTable"."t3ver_wsid" = 0) OR ("aTable"."t3ver_wsid" = 42)', (string)$expression); diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php index 8d54e36d3f6b..9afec93e08a7 100644 --- a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php @@ -161,16 +161,15 @@ class Typo3DbBackendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase ->disableOriginalConstructor() ->getMock(); $sourceMock = new \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Selector('tx_foo', 'Tx_Foo'); + $context = new Context([ + 'workspace' => new WorkspaceAspect($workspaceUid) + ]); /** @var $pageRepositoryMock PageRepository|\PHPUnit_Framework_MockObject_MockObject */ $pageRepositoryMock = $this->getMockBuilder(PageRepository::class) ->setMethods(['movePlhOL', 'getWorkspaceVersionOfRecord']) - ->disableOriginalConstructor() + ->setConstructorArgs([$context]) ->getMock(); $pageRepositoryMock->expects($this->once())->method('getWorkspaceVersionOfRecord')->with($workspaceUid, 'tx_foo', '42')->will($this->returnValue($workspaceVersion)); - $pageRepositoryMock->versioningWorkspaceId = $workspaceUid; - $context = new Context([ - 'workspace' => new WorkspaceAspect($workspaceUid) - ]); $objectManagerMock->expects($this->at(0))->method('get')->with(Context::class)->willReturn($context); $objectManagerMock->expects($this->at(1))->method('get')->with(PageRepository::class, $context)->willReturn($pageRepositoryMock); $mockTypo3DbBackend = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend::class, ['dummy'], [], '', false); diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php index 358916812d9c..e7c9e22685e1 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php +++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php @@ -6723,8 +6723,9 @@ class ContentObjectRenderer implements LoggerAwareInterface 'orderBy' => null, ]; + $isInWorkspace = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('workspace', 'isOffline'); $considerMovePlaceholders = ( - $tsfe->sys_page->versioningWorkspaceId > 0 && $table !== 'pages' + $isInWorkspace && $table !== 'pages' && !empty($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) ); diff --git a/typo3/sysext/frontend/Classes/Page/PageRepository.php b/typo3/sysext/frontend/Classes/Page/PageRepository.php index 1a94990d2d24..c6671427db17 100644 --- a/typo3/sysext/frontend/Classes/Page/PageRepository.php +++ b/typo3/sysext/frontend/Classes/Page/PageRepository.php @@ -58,6 +58,7 @@ class PageRepository implements LoggerAwareInterface 'error_getRootLine' => 'Using $error_getRootLine of class PageRepository from the outside is deprecated as this property only exists for legacy reasons.', 'error_getRootLine_failPid' => 'Using $error_getRootLine_failPid of class PageRepository from the outside is deprecated as this property only exists for legacy reasons.', 'sys_language_uid' => 'Using $sys_language_uid of class PageRepository from the outside is deprecated as this information is now stored within the Context Language Aspect given by the constructor.', + 'versioningWorkspaceId' => 'Using $versioningWorkspaceId of class PageRepository from the outside is deprecated as this information is now stored within the Context Workspace Aspect given by the constructor.', ]; /** @@ -100,8 +101,9 @@ class PageRepository implements LoggerAwareInterface * user! * * @var int + * @deprecated This method will be kept protected from TYPO3 v10.0 on, instantiate a new pageRepository object with a custom workspace aspect to override this setting. */ - public $versioningWorkspaceId = 0; + protected $versioningWorkspaceId = 0; /** * @var array diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php index 102cd9a993d8..37d76364a286 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php @@ -461,6 +461,11 @@ return [ 'Deprecation-85543-Language-relatedPropertiesInTypoScriptFrontendControllerAndPageRepository.rst' ], ], + 'TYPO3\CMS\Frontend\Page\PageRepository->versioningWorkspaceId' => [ + 'restFiles' => [ + 'Deprecation-85556-PageRepository-versioningWorkspaceId.rst' + ], + ], 'TYPO3\CMS\Core\TypoScript\TemplateService->fileCache' => [ 'restFiles' => [ 'Deprecation-85445-TemplateService-getFileName.rst' -- GitLab