From 9301ce961038ee6835fea495d87e1415161228fd Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Sun, 27 May 2018 15:13:38 +0200
Subject: [PATCH] [TASK] Deprecate GeneralUtility::arrayToLogString()

The method arrayToLogString() within GeneralUtility is deprecated in favor of using
own implementations, based on PSR-3.

Still, the one place where this method was in use - ListSysLogCommand -
moved the logic into its own protected method.

Resolves: #85086
Releases: master
Change-Id: If6815a5ea9e459258408458b97b7ee4ad901bd40
Reviewed-on: https://review.typo3.org/57056
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
---
 .../core/Classes/Utility/GeneralUtility.php   |  2 +
 ...n-85086-GeneralUtilityArrayToLogString.rst | 37 +++++++++++++++++++
 .../Php/MethodCallStaticMatcher.php           | 15 ++++++--
 .../Classes/Command/ListSysLogCommand.php     | 24 +++++++++++-
 4 files changed, 72 insertions(+), 6 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-85086-GeneralUtilityArrayToLogString.rst

diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php
index adf099c6fa11..c57aa9fd6d8b 100644
--- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php
+++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php
@@ -4022,9 +4022,11 @@ class GeneralUtility
      * @param mixed $valueList List of keys which should be listed in the output string. Pass a comma list or an array. An empty list outputs the whole array.
      * @param int $valueLength Long string values are shortened to this length. Default: 20
      * @return string Output string with key names and their value as string
+     * @deprecated since TYPO3 v9.3, will be removed in TYPO3 v10.
      */
     public static function arrayToLogString(array $arr, $valueList = [], $valueLength = 20)
     {
+        trigger_error('Method GeneralUtility::arrayToLogString() will be removed in TYPO3 v10. Use CLI-related methods in your code directly.', E_USER_DEPRECATED);
         $str = '';
         if (!is_array($valueList)) {
             $valueList = self::trimExplode(',', $valueList, true);
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85086-GeneralUtilityArrayToLogString.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85086-GeneralUtilityArrayToLogString.rst
new file mode 100644
index 000000000000..02394d705b79
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85086-GeneralUtilityArrayToLogString.rst
@@ -0,0 +1,37 @@
+.. include:: ../../Includes.txt
+
+========================================================
+Deprecation: #85086 - GeneralUtility::arrayToLogString()
+========================================================
+
+See :issue:`85086`
+
+Description
+===========
+
+The method :php:`GeneralUtility::arrayToLogString()`, responsible for formatting an array to a string
+ready for logging or output, has been marked as deprecated.
+
+
+Impact
+======
+
+Calling the method directly will trigger a deprecation warning.
+
+
+Affected Installations
+======================
+
+Any TYPO3 installation with third-party extensions using this method.
+
+
+Migration
+=========
+
+For logging purposes, switch to PSR-3 compatible logging where a log-writer is taking care of outputting / storing
+this information properly.
+
+For other purposes, like CLI-command output, it is recommended to implement this functionality directly in the
+corresponding CLI command.
+
+.. index:: CLI, PHP-API, FullyScanned, ext:core
\ 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 70a65316b161..580413cb6f7a 100644
--- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php
+++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php
@@ -547,32 +547,39 @@ return [
             'Deprecation-83475-AggregateValidatorInformationInClassSchema-2.rst',
         ],
     ],
-    'TYPO3\CMS\backend\Utility\BackendUtility::getPidForModTSconfig' => [
+    'TYPO3\CMS\Backend\Utility\BackendUtility::getPidForModTSconfig' => [
         'numberOfMandatoryArguments' => 3,
         'maximumNumberOfArguments' => 3,
         'restFiles' => [
             'Deprecation-84994-BackendUtilitygetPidForModTSconfigDeprecated.rst',
         ],
     ],
-    'TYPO3\CMS\backend\Utility\BackendUtility::getModTSconfig' => [
+    'TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig' => [
         'numberOfMandatoryArguments' => 2,
         'maximumNumberOfArguments' => 2,
         'restFiles' => [
             'Deprecation-84993-DeprecateSomeTSconfigRelatedMethods.rst',
         ],
     ],
-    'TYPO3\CMS\backend\Utility\BackendUtility::unsetMenuItems' => [
+    'TYPO3\CMS\Backend\Utility\BackendUtility::unsetMenuItems' => [
         'numberOfMandatoryArguments' => 3,
         'maximumNumberOfArguments' => 3,
         'restFiles' => [
             'Deprecation-84993-DeprecateSomeTSconfigRelatedMethods.rst',
         ],
     ],
-    'TYPO3\CMS\saltedpasswords\Utility\SaltedPasswordsUtility::isUsageEnabled' => [
+    'TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility::isUsageEnabled' => [
         'numberOfMandatoryArguments' => 0,
         'maximumNumberOfArguments' => 1,
         'restFiles' => [
             'Deprecation-85027-SaltedPasswordsRelatedMethodsAndClasses.rst',
         ],
     ],
+    'TYPO3\CMS\Core\Utility\GeneralUtility::arrayToLogString' => [
+        'numberOfMandatoryArguments' => 1,
+        'maximumNumberOfArguments' => 3,
+        'restFiles' => [
+            'Deprecation-85086-GeneralUtilityArrayToLogString.rst',
+        ],
+    ],
 ];
diff --git a/typo3/sysext/lowlevel/Classes/Command/ListSysLogCommand.php b/typo3/sysext/lowlevel/Classes/Command/ListSysLogCommand.php
index 94708c98bd06..c9db8a3430a1 100644
--- a/typo3/sysext/lowlevel/Classes/Command/ListSysLogCommand.php
+++ b/typo3/sysext/lowlevel/Classes/Command/ListSysLogCommand.php
@@ -92,7 +92,7 @@ class ListSysLogCommand extends Command
             ];
 
             if ($showDetails) {
-                $result[] = str_replace('; ', LF, GeneralUtility::arrayToLogString($row, [
+                $result[] = $this->arrayToLogString($row, [
                     'uid',
                     'userid',
                     'action',
@@ -107,10 +107,30 @@ class ListSysLogCommand extends Command
                     'event_pid',
                     'NEWid',
                     'workspace'
-                ]));
+                ]);
             }
             $content[] = $result;
         }
         $io->table($tableHeaders, $content);
     }
+
+    /**
+     * Converts a one dimensional array to a one line string which can be used for logging or debugging output
+     * Example: "loginType: FE; refInfo: Array; HTTP_HOST: www.example.org; REMOTE_ADDR: 192.168.1.5; REMOTE_HOST:; security_level:; showHiddenRecords: 0;"
+     * Previously found in GeneralUtility::arrayToLogString()
+     *
+     * @param array $arr Data array which should be outputted
+     * @param array $valueList List of keys which should be listed in the output string.
+     * @return string Output string with key names and their value as string
+     */
+    protected function arrayToLogString(array $arr, array $valueList): string
+    {
+        $str = '';
+        foreach ($arr as $key => $value) {
+            if (in_array($key, $valueList, true)) {
+                $str .= (string)$key . trim(': ' . GeneralUtility::fixed_lgd_cs(str_replace(LF, '|', (string)$value), 20)) . LF;
+            }
+        }
+        return $str;
+    }
 }
-- 
GitLab