From e15776cdf9007c4132ae7454f2b0b18e7fe659f6 Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Fri, 29 May 2020 13:23:26 +0200
Subject: [PATCH] [!!!][TASK] Remove deprecated functionality in DataHandler

The Permission handling within DataHandler has been migrated
into PagePermissionAssembler in TYPO3 v10.

All other previously deprecated code within DataHandler is also removed.

The following previously deprecated code is now removed:
* DataHandler->assemblePermissions()
* DataHandler->setTSconfigPermissions()
* DataHandler->process_uploads()
* DataHandler->pMap
* DataHandler->defaultPermissions

Resolves: #91480
Releases: master
Change-Id: Ia52dc8c2fa042458272b49608c5b318e19e73735
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64599
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
---
 .../core/Classes/DataHandling/DataHandler.php | 135 +-----------------
 ...g-91473-DeprecatedFunctionalityRemoved.rst |   8 ++
 .../Php/MethodCallMatcher.php                 |   3 +
 .../Php/PropertyPublicMatcher.php             |   2 +
 4 files changed, 17 insertions(+), 131 deletions(-)

diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
index ae05c7bb94a1..63df75d6d29b 100644
--- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php
+++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
@@ -376,18 +376,6 @@ class DataHandler implements LoggerAwareInterface
      */
     public $admin;
 
-    /**
-     * Can be overridden from $GLOBALS['TYPO3_CONF_VARS']
-     *
-     * @var array
-     * @deprecated will be removed in TYPO3 11. use PagePermissionAssembler instead.
-     */
-    public $defaultPermissions = [
-        'user' => 'show,edit,delete,new,editcontent',
-        'group' => 'show,edit,new,editcontent',
-        'everybody' => ''
-    ];
-
     /**
      * @var PagePermissionAssembler
      */
@@ -437,23 +425,6 @@ class DataHandler implements LoggerAwareInterface
     protected $historyRecords = [];
 
     // Internal static:
-    /**
-     * Permission mapping
-     *
-     * @var array
-     * @deprecated will be removed in TYPO3 11. use PagePermissionAssembler instead.
-     */
-    public $pMap = [
-        'show' => 1,
-        // 1st bit
-        'edit' => 2,
-        // 2nd bit
-        'delete' => 4,
-        // 3rd bit
-        'new' => 8,
-        // 4th bit
-        'editcontent' => 16
-    ];
 
     /**
      * The interval between sorting numbers used with tables with a 'sorting' field defined.
@@ -702,17 +673,6 @@ class DataHandler implements LoggerAwareInterface
             $this->setDefaultsFromUserTS($tcaDefaultOverride);
         }
 
-        // Initializing default permissions for pages
-        $defaultPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPermissions'];
-        if (isset($defaultPermissions['user'])) {
-            $this->defaultPermissions['user'] = $defaultPermissions['user'];
-        }
-        if (isset($defaultPermissions['group'])) {
-            $this->defaultPermissions['group'] = $defaultPermissions['group'];
-        }
-        if (isset($defaultPermissions['everybody'])) {
-            $this->defaultPermissions['everybody'] = $defaultPermissions['everybody'];
-        }
         // generates the excludelist, based on TCA/exclude-flag and non_exclude_fields for the user:
         if (!$this->admin) {
             $this->excludedTablesAndFields = array_flip($this->getExcludeListArray());
@@ -814,16 +774,6 @@ class DataHandler implements LoggerAwareInterface
         return $cleanFieldArray;
     }
 
-    /**
-     * Dummy method formerly used for file handling.
-     *
-     * @deprecated since TYPO3 v10.0, will be removed in TYPO3 v11.0.
-     */
-    public function process_uploads()
-    {
-        trigger_error('DataHandler->process_uploads() will be removed in TYPO3 v11.0.', E_USER_DEPRECATED);
-    }
-
     /*********************************************
      *
      * HOOKS
@@ -6223,17 +6173,14 @@ class DataHandler implements LoggerAwareInterface
      *
      * @param string $table Record table name
      * @param int $id Record UID
-     * @param int|string $perms Permission restrictions to observe: Either an integer that will be bitwise AND'ed or a string, which points to a key in the ->pMap array. Only integers are supported starting with TYPO3 v11.
+     * @param int $perms Permission restrictions to observe: integer that will be bitwise AND'ed.
      * @return bool Returns TRUE if the record given by $table, $id and $perms can be selected
      *
      * @throws \RuntimeException
      * @internal should only be used from within DataHandler
      */
-    public function doesRecordExist($table, $id, $perms)
+    public function doesRecordExist($table, $id, int $perms)
     {
-        if (!MathUtility::canBeInterpretedAsInteger($perms)) {
-            trigger_error('Support for handing in permissions as string into "doesRecordExist" will be not be supported with TYPO3 v11 anymore. Use the Permission BitSet class instead.', E_USER_DEPRECATED);
-        }
         return $this->recordInfoWithPermissionCheck($table, $id, $perms, 'uid, pid') !== false;
     }
 
@@ -6532,12 +6479,12 @@ class DataHandler implements LoggerAwareInterface
      *
      * @param string $table Record table name
      * @param int $id Record UID
-     * @param int|string $perms Permission restrictions to observe: Either an integer that will be bitwise AND'ed or a string, which points to a key in the ->pMap array. With TYPO3 v11, only integers are allowed
+     * @param int $perms Permission restrictions to observe: An integer that will be bitwise AND'ed.
      * @param string $fieldList - fields - default is '*'
      * @throws \RuntimeException
      * @return array|bool Row if exists and accessible, false otherwise
      */
-    protected function recordInfoWithPermissionCheck(string $table, int $id, $perms, string $fieldList = '*')
+    protected function recordInfoWithPermissionCheck(string $table, int $id, int $perms, string $fieldList = '*')
     {
         if ($this->bypassAccessCheckForRecords) {
             $columns = GeneralUtility::trimExplode(',', $fieldList, true);
@@ -6553,27 +6500,6 @@ class DataHandler implements LoggerAwareInterface
 
             return $record ?: false;
         }
-        // Processing the incoming $perms (from possible string to integer that can be AND'ed)
-        if (!MathUtility::canBeInterpretedAsInteger($perms)) {
-            trigger_error('Support for handing in permissions as string into "recordInfoWithPermissionCheck" will be not be supported with TYPO3 v11 anymore. Use the Permission BitSet class instead.', E_USER_DEPRECATED);
-            if ($table !== 'pages') {
-                switch ($perms) {
-                    case 'edit':
-                    case 'delete':
-                    case 'new':
-                        // This holds it all in case the record is not page!!
-                        if ($table === 'sys_file_reference' && array_key_exists('pages', $this->datamap)) {
-                            $perms = 'edit';
-                        } else {
-                            $perms = 'editcontent';
-                        }
-                        break;
-                }
-            }
-            $perms = (int)(Permission::getMap()[$perms] ?? 0);
-        } else {
-            $perms = (int)$perms;
-        }
         if (!$perms) {
             throw new \RuntimeException('Internal ERROR: no permissions to check for non-admin user', 1270853920);
         }
@@ -7258,36 +7184,6 @@ class DataHandler implements LoggerAwareInterface
         return $previousLocalizedRecordUid;
     }
 
-    /**
-     * Setting up perms_* fields in $fieldArray based on TSconfig input
-     * Used for new pages
-     *
-     * @param array $fieldArray Field Array, returned with modifications
-     * @param array $TSConfig_p TSconfig properties
-     * @return array Modified Field Array
-     * @deprecated will be removed in TYPO3 v11.0 - Use PagePermissionAssembler instead.
-     */
-    public function setTSconfigPermissions($fieldArray, $TSConfig_p)
-    {
-        trigger_error('DataHandler->setTSconfigPermissions will be removed in TYPO3 v11.0. Use the PagePermissionAssembler API instead.', E_USER_DEPRECATED);
-        if ((string)$TSConfig_p['userid'] !== '') {
-            $fieldArray['perms_userid'] = (int)$TSConfig_p['userid'];
-        }
-        if ((string)$TSConfig_p['groupid'] !== '') {
-            $fieldArray['perms_groupid'] = (int)$TSConfig_p['groupid'];
-        }
-        if ((string)$TSConfig_p['user'] !== '') {
-            $fieldArray['perms_user'] = MathUtility::canBeInterpretedAsInteger($TSConfig_p['user']) ? $TSConfig_p['user'] : $this->assemblePermissions($TSConfig_p['user']);
-        }
-        if ((string)$TSConfig_p['group'] !== '') {
-            $fieldArray['perms_group'] = MathUtility::canBeInterpretedAsInteger($TSConfig_p['group']) ? $TSConfig_p['group'] : $this->assemblePermissions($TSConfig_p['group']);
-        }
-        if ((string)$TSConfig_p['everybody'] !== '') {
-            $fieldArray['perms_everybody'] = MathUtility::canBeInterpretedAsInteger($TSConfig_p['everybody']) ? $TSConfig_p['everybody'] : $this->assemblePermissions($TSConfig_p['everybody']);
-        }
-        return $fieldArray;
-    }
-
     /**
      * Returns a fieldArray with default values. Values will be picked up from the TCA array looking at the config key "default" for each column. If values are set in ->defaultValues they will overrule though.
      * Used for new records and during copy operations for defaults
@@ -7454,29 +7350,6 @@ class DataHandler implements LoggerAwareInterface
         return $result;
     }
 
-    /**
-     * Calculates the bitvalue of the permissions given in a string, comma-separated
-     *
-     * @param string $string List of pMap strings
-     * @return int Integer mask
-     * @see setTSconfigPermissions()
-     * @see newFieldArray()
-     * @deprecated will be removed in TYPO3 v11.0 - Use PagePermissionAssembler instead.
-     */
-    public function assemblePermissions($string)
-    {
-        trigger_error('DataHandler->assemblePermissions will be removed in TYPO3 v11.0. Use the PagePermissionAssembler API instead.', E_USER_DEPRECATED);
-        $keyArr = GeneralUtility::trimExplode(',', $string, true);
-        $value = 0;
-        $permissionMap = Permission::getMap();
-        foreach ($keyArr as $key) {
-            if ($key && isset($permissionMap[$key])) {
-                $value |= $permissionMap[$key];
-            }
-        }
-        return $value;
-    }
-
     /**
      * Converts a HTML entity (like &#123;) to the character '123'
      *
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-91473-DeprecatedFunctionalityRemoved.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-91473-DeprecatedFunctionalityRemoved.rst
index bad3b1a31136..4f2d62af3d3d 100644
--- a/typo3/sysext/core/Documentation/Changelog/master/Breaking-91473-DeprecatedFunctionalityRemoved.rst
+++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-91473-DeprecatedFunctionalityRemoved.rst
@@ -22,6 +22,9 @@ The following PHP class aliases that have been previously deprecated for v10 hav
 
 The following PHP class methods that have been previously deprecated for v10 have been removed:
 
+- :php:`\TYPO3\CMS\Core\DataHandling\DataHandler->assemblePermissions`
+- :php:`\TYPO3\CMS\Core\DataHandling\DataHandler->process_uploads`
+- :php:`\TYPO3\CMS\Core\DataHandling\DataHandler->setTSconfigPermissions`
 - :php:`\TYPO3\CMS\Extbase\Mvc\Controller\ActionController->emitBeforeCallActionMethodSignal`
 - :php:`\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->isOutputting`
 - :php:`\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->processContentForOutput`
@@ -53,12 +56,17 @@ The following PHP methods have been additionally deprecated and are a no-op now:
 
 The following methods changed signature according to previous deprecations in v10 at the end of the argument list:
 
+- :php:`\TYPO3\CMS\Core\DataHandling\DataHandler->doesRecordExist` (argument 3 is now an integer)
+- :php:`\TYPO3\CMS\Core\DataHandling\DataHandler->recordInfoWithPermissionCheck` (argument 3 is now an integer)
 - :php:`\TYPO3\CMS\Core\Utility\GeneralUtility::getUrl` (arguments 2, 3 and 4 are dropped)
 - :php:`\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstanceService` (arguments 3 :php:`$excludeServiceKeys` is now an array)
 - :php:`\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->__construct`
 
 The following public class properties have been dropped:
 
+- :php:`\TYPO3\CMS\Core\DataHandling\DataHandler->defaultPermissions`
+- :php:`\TYPO3\CMS\Core\DataHandling\DataHandler->pMap`
+
 The following class methods have changed visibility:
 
 The following class properties have changed visibility:
diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
index 126df8232c78..50b55338846b 100644
--- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
+++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
@@ -4131,6 +4131,7 @@ return [
         'maximumNumberOfArguments' => 1,
         'restFiles' => [
             'Breaking-87305-UseConstructorInjectionInDataMapper.rst',
+            'Breaking-91473-DeprecatedFunctionalityRemoved.rst'
         ],
     ],
     'TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder->setUseCacheHash' => [
@@ -4389,6 +4390,7 @@ return [
         'maximumNumberOfArguments' => 2,
         'restFiles' => [
             'Deprecation-90019-PagePermissionLogicByDataHandler.rst',
+            'Breaking-91473-DeprecatedFunctionalityRemoved.rst'
         ],
     ],
     'TYPO3\CMS\Core\DataHandling\DataHandler->assemblePermissions' => [
@@ -4396,6 +4398,7 @@ return [
         'maximumNumberOfArguments' => 1,
         'restFiles' => [
             'Deprecation-90019-PagePermissionLogicByDataHandler.rst',
+            'Breaking-91473-DeprecatedFunctionalityRemoved.rst'
         ],
     ],
     'TYPO3\CMS\Core\Utility\File\BasicFileUtility->setFileExtensionPermissions' => [
diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php
index 99c4bfb2fe08..bb993cb94474 100644
--- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php
+++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php
@@ -650,11 +650,13 @@ return [
     'TYPO3\CMS\Core\DataHandling\DataHandler->defaultPermissions' => [
         'restFiles' => [
             'Deprecation-90019-PagePermissionLogicByDataHandler.rst',
+            'Breaking-91473-DeprecatedFunctionalityRemoved.rst'
         ],
     ],
     'TYPO3\CMS\Core\DataHandling\DataHandler->pMap' => [
         'restFiles' => [
             'Deprecation-90019-PagePermissionLogicByDataHandler.rst',
+            'Breaking-91473-DeprecatedFunctionalityRemoved.rst'
         ],
     ],
 ];
-- 
GitLab