[TASK] Deprecate PageRepository->versioningWorkspaceId 92/57592/3
authorBenni Mack <benni@typo3.org>
Fri, 13 Jul 2018 18:56:31 +0000 (20:56 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Mon, 23 Jul 2018 18:32:27 +0000 (20:32 +0200)
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>
typo3/sysext/core/Classes/Database/Query/Restriction/FrontendWorkspaceRestriction.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-85556-PageRepository-versioningWorkspaceId.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Database/Query/Restriction/FrontendWorkspaceRestrictionTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Classes/Page/PageRepository.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php

index dc724a8..0252e7e 100644 (file)
@@ -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 (file)
index 0000000..c67def9
--- /dev/null
@@ -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
index 1f2a732..671e0f0 100644 (file)
@@ -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);
index 8d54e36..9afec93 100644 (file)
@@ -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);
index 3589168..e7c9e22 100644 (file)
@@ -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'])
         );
 
index 1a94990..c667142 100644 (file)
@@ -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
index 102cd9a..37d7636 100644 (file)
@@ -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'