From 0999cfd5fb49880b90a2cc26b731a2ef7eff242a Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Fri, 13 Jul 2018 21:43:27 +0200
Subject: [PATCH] [TASK] Deprecate PageRepository->checkWorkspaceAccess

An unused if() statement removes the last occurrence
of this method, so it can be deprecated.

Resolves: #85554
Releases: master
Change-Id: Ica80f66f7fdce4d72c8d97d0405360c307ca14dd
Reviewed-on: https://review.typo3.org/57593
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
---
 ...54-PageRepository-checkWorkspaceAccess.rst | 33 +++++++++++++++++++
 .../frontend/Classes/Page/PageRepository.php  |  5 ++-
 .../Php/MethodCallMatcher.php                 |  9 ++++-
 3 files changed, 45 insertions(+), 2 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-85554-PageRepository-checkWorkspaceAccess.rst

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85554-PageRepository-checkWorkspaceAccess.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85554-PageRepository-checkWorkspaceAccess.rst
new file mode 100644
index 000000000000..983f48f56c96
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85554-PageRepository-checkWorkspaceAccess.rst
@@ -0,0 +1,33 @@
+.. include:: ../../Includes.txt
+
+==========================================================
+Deprecation: #85554 - PageRepository->checkWorkspaceAccess
+==========================================================
+
+See :issue:`85554`
+
+Description
+===========
+
+The unused method :php:`TYPO3\CMS\Frontend\Page\PageRepository->checkWorkspaceAccess()` has been marked as
+deprecated.
+
+
+Impact
+======
+
+Calling the method directly will trigger a deprecation message.
+
+
+Affected Installations
+======================
+
+TYPO3 installations with custom extensions calling this public method directly.
+
+
+Migration
+=========
+
+Implement the check on :php:`BE_USER->checkWorkspace($workspaceId)` directly in the callers' code.
+
+.. index:: Frontend, PHP-API, FullyScanned, ext:frontend
\ No newline at end of file
diff --git a/typo3/sysext/frontend/Classes/Page/PageRepository.php b/typo3/sysext/frontend/Classes/Page/PageRepository.php
index c187a1444de6..1a94990d2d24 100644
--- a/typo3/sysext/frontend/Classes/Page/PageRepository.php
+++ b/typo3/sysext/frontend/Classes/Page/PageRepository.php
@@ -1654,7 +1654,7 @@ class PageRepository implements LoggerAwareInterface
             }
             // If workspace ids matches and ID of current online version is found, look up
             // the PID value of that:
-            if ($oid && ((int)$this->versioningWorkspaceId === 0 && $this->checkWorkspaceAccess($wsid) || (int)$wsid === (int)$this->versioningWorkspaceId)) {
+            if ($oid && (int)$wsid === (int)$this->versioningWorkspaceId) {
                 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
                 $queryBuilder->getRestrictions()
                     ->removeAll()
@@ -1970,9 +1970,11 @@ class PageRepository implements LoggerAwareInterface
      *
      * @param int $wsid Workspace ID
      * @return bool true if the backend user has access to a certain workspace
+     * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. Use $BE_USER->checkWorkspace() directly if necessary.
      */
     public function checkWorkspaceAccess($wsid)
     {
+        trigger_error('PageRepository->checkWorkspaceAccess() will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
         if (!$this->getBackendUser() || !ExtensionManagementUtility::isLoaded('workspaces')) {
             return false;
         }
@@ -2055,6 +2057,7 @@ class PageRepository implements LoggerAwareInterface
      * Returns the current BE user.
      *
      * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
+     * @deprecated will be removed in TYPO3 v10.0 as will not be used anymore then because checkWorkspaceAccess() will be removed.
      */
     protected function getBackendUser()
     {
diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
index c612d84454d5..783d651a354a 100644
--- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
+++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
@@ -2445,7 +2445,7 @@ return [
             'Deprecation-85558-ContentObjectRenderer-enableFields.rst'
         ],
     ],
-    'TYPO3\CMS\Scheduler\Classes\Controller\SchedulerModuleController->addMessage' => [
+    'TYPO3\CMS\Scheduler\Controller\SchedulerModuleController->addMessage' => [
         'numberOfMandatoryArguments' => 1,
         'maximumNumberOfArguments' => 2,
         'restFiles' => [
@@ -2473,4 +2473,11 @@ return [
             'Deprecation-65578-ConfigconcatenateJsAndCssAndConcatenateFiles.rst',
         ],
     ],
+    'TYPO3\CMS\Frontend\Page\PageRepository->checkWorkspaceAccess' => [
+        'numberOfMandatoryArguments' => 1,
+        'maximumNumberOfArguments' => 1,
+        'restFiles' => [
+            'Deprecation-85554-PageRepository-checkWorkspaceAccess.rst',
+        ],
+    ],
 ];
-- 
GitLab