From da8841e2fa2eaafc96be7334104334ae3fae30b5 Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Sat, 25 Nov 2017 00:07:57 +0100
Subject: [PATCH] [TASK] Deprecate BackendUtility::getHash/storeHash

The methods are only wrappers for the Caching framework, and come
from the time where the caching framework wasn't available.

Resolves: #83116
Releases: master
Change-Id: I6e3293f1bde654ee6548898742daa77d044d2107
Reviewed-on: https://review.typo3.org/54758
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
---
 .../Classes/Configuration/TsConfigParser.php  | 13 +++++---
 .../Classes/Utility/BackendUtility.php        |  6 ++--
 .../BackendUserAuthentication.php             |  6 ++--
 ...rameworkWrapperMethodsInBackendUtility.rst | 33 +++++++++++++++++++
 .../Php/MethodCallStaticMatcher.php           | 14 ++++++++
 5 files changed, 63 insertions(+), 9 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-83116-CachingFrameworkWrapperMethodsInBackendUtility.rst

diff --git a/typo3/sysext/backend/Classes/Configuration/TsConfigParser.php b/typo3/sysext/backend/Classes/Configuration/TsConfigParser.php
index 3ca7f859ce19..8c1d72461b22 100644
--- a/typo3/sysext/backend/Classes/Configuration/TsConfigParser.php
+++ b/typo3/sysext/backend/Classes/Configuration/TsConfigParser.php
@@ -14,7 +14,8 @@ namespace TYPO3\CMS\Backend\Configuration;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Cache\CacheManager;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * A TS-Config parsing class which performs condition evaluation
@@ -53,7 +54,9 @@ class TsConfigParser extends \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
         $this->id = $id;
         $this->rootLine = $rootLine;
         $hash = md5($type . ':' . $TStext);
-        $cachedContent = BackendUtility::getHash($hash);
+
+        $cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_hash');
+        $cachedContent = $cache->get($hash);
         if (is_array($cachedContent)) {
             $storedData = $cachedContent[0];
             $storedMD5 = $cachedContent[1];
@@ -68,7 +71,7 @@ class TsConfigParser extends \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
                 ];
             } else {
                 $shash = md5($checkMD5 . $hash);
-                $cachedSpec = BackendUtility::getHash($shash);
+                $cachedSpec = $cache->get($shash);
                 if (is_array($cachedSpec)) {
                     $storedData = $cachedSpec;
                     $res = [
@@ -78,18 +81,18 @@ class TsConfigParser extends \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
                     ];
                 } else {
                     $storeData = $this->parseWithConditions($TStext);
-                    BackendUtility::storeHash($shash, $storeData, $type . '_TSconfig');
                     $res = [
                         'TSconfig' => $storeData['TSconfig'],
                         'cached' => 0,
                         'hash' => $shash
                     ];
+                    $cache->set($shash, $storeData, ['ident_' . $type . '_TSconfig'], 0);
                 }
             }
         } else {
             $storeData = $this->parseWithConditions($TStext);
             $md5 = md5(serialize($storeData));
-            BackendUtility::storeHash($hash, [$storeData, $md5], $type . '_TSconfig');
+            $cache->set($hash, [$storeData, $md5], ['ident_' . $type . '_TSconfig'], 0);
             $res = [
                 'TSconfig' => $storeData['TSconfig'],
                 'cached' => 0,
diff --git a/typo3/sysext/backend/Classes/Utility/BackendUtility.php b/typo3/sysext/backend/Classes/Utility/BackendUtility.php
index c384d8a9eaac..7e417151540c 100644
--- a/typo3/sysext/backend/Classes/Utility/BackendUtility.php
+++ b/typo3/sysext/backend/Classes/Utility/BackendUtility.php
@@ -781,10 +781,11 @@ class BackendUtility
      * @param string $hash 32 bit hash string (eg. a md5 hash of a serialized array identifying the data being stored)
      * @param mixed $data The data to store
      * @param string $ident $ident is just a textual identification in order to inform about the content!
+     * @deprecated since TYPO3 v9, will be removed in TYPO3 v10, use the Caching Framework directly
      */
     public static function storeHash($hash, $data, $ident)
     {
-        /** @var CacheManager $cacheManager */
+        trigger_error('This method will be removed in TYPO3 v10.0, use the Caching Framework directly.', E_USER_DEPRECATED);
         $cacheManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
         $cacheManager->getCache('cache_hash')->set($hash, $data, ['ident_' . $ident], 0);
     }
@@ -795,10 +796,11 @@ class BackendUtility
      *
      * @param string $hash The hash-string which was used to store the data value
      * @return mixed The "data" from the cache
+     * @deprecated since TYPO3 v9, will be removed in TYPO3 v10, use the Caching Framework directly
      */
     public static function getHash($hash)
     {
-        /** @var CacheManager $cacheManager */
+        trigger_error('This method will be removed in TYPO3 v10.0, use the Caching Framework directly.', E_USER_DEPRECATED);
         $cacheManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
         $cacheEntry = $cacheManager->getCache('cache_hash')->get($hash);
         $hashContent = null;
diff --git a/typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php b/typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php
index 543dd28c4d16..ad74bda5b88c 100644
--- a/typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php
+++ b/typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Authentication;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
@@ -1370,14 +1371,15 @@ class BackendUserAuthentication extends AbstractUserAuthentication
             } else {
                 // Parsing the user TSconfig (or getting from cache)
                 $hash = md5('userTS:' . $this->userTS_text);
-                $cachedContent = BackendUtility::getHash($hash);
+                $cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_hash');
+                $cachedContent = $cache->get($hash);
                 if (is_array($cachedContent) && !$this->userTS_dontGetCached) {
                     $this->userTS = $cachedContent;
                 } else {
                     $parseObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
                     $parseObj->parse($this->userTS_text);
                     $this->userTS = $parseObj->setup;
-                    BackendUtility::storeHash($hash, $this->userTS, 'BE_USER_TSconfig');
+                    $cache->set($hash, $this->userTS, ['ident_BE_USER_TSconfig'], 0);
                     // Update UC:
                     $this->userTSUpdated = true;
                 }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83116-CachingFrameworkWrapperMethodsInBackendUtility.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83116-CachingFrameworkWrapperMethodsInBackendUtility.rst
new file mode 100644
index 000000000000..f681ffa136ec
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83116-CachingFrameworkWrapperMethodsInBackendUtility.rst
@@ -0,0 +1,33 @@
+.. include:: ../../Includes.txt
+
+=========================================================================
+Deprecation: #83116 - Caching framework wrapper methods in BackendUtility
+=========================================================================
+
+See :issue:`83116`
+
+Description
+===========
+
+The methods :php:``BackendUtility::getHash()`` and :php:``BackendUtility::storeHash()`` have been marked as
+deprecated.
+
+
+Impact
+======
+
+Calling the methods will trigger a deprecation warning.
+
+
+Affected Installations
+======================
+
+Any extension using the methods in custom PHP code.
+
+
+Migration
+=========
+
+Use the Caching Framework directly, as the methods now only act as wrapper methods.
+
+.. index:: PHP-API, FullyScanned
\ No newline at end of file
diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php
index 5324b3bd0fcd..f6e95ebba245 100644
--- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php
+++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php
@@ -512,4 +512,18 @@ return [
             'Deprecation-83083-GeneralUtilityllXmlAutoFileName.rst',
         ],
     ],
+    'TYPO3\CMS\Backend\Utility\BackendUtility::getHash' => [
+        'numberOfMandatoryArguments' => 1,
+        'maximumNumberOfArguments' => 1,
+        'restFiles' => [
+            'Deprecation-83116-CachingFrameworkWrapperMethodsInBackendUtility.rst',
+        ],
+    ],
+    'TYPO3\CMS\Backend\Utility\BackendUtility::storeHash' => [
+        'numberOfMandatoryArguments' => 3,
+        'maximumNumberOfArguments' => 3,
+        'restFiles' => [
+            'Deprecation-83116-CachingFrameworkWrapperMethodsInBackendUtility.rst',
+        ],
+    ],
 ];
-- 
GitLab