[TASK] Deprecate usages of CharsetConverter in core 97/57097/4
authorBenni Mack <benni@typo3.org>
Wed, 30 May 2018 20:20:56 +0000 (22:20 +0200)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Wed, 30 May 2018 22:11:05 +0000 (00:11 +0200)
CharsetConverter is still instantiated in some places and not needed at all times.

The following places have CharsetConverter completely removed (as internal property):
- PageRenderer
- SearchController
- Indexer

The AbstractHierarchicalFilesystemDriver's shorthand method getCharsetConversion()
has been deprecated, as drivers should instantiate the CharsetConversion themself.

Indexed Search's Lexer has a public property "csObj" which has been switched to
protected, where a deprecation message will be thrown.

Resolves: #85125
Releases: master
Change-Id: I48fd110ecd25bb6a4225a3d2141edc5fc3b92673
Reviewed-on: https://review.typo3.org/57097
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
typo3/sysext/core/Classes/Page/PageRenderer.php
typo3/sysext/core/Classes/Resource/Driver/AbstractHierarchicalFilesystemDriver.php
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-85125-UsagesOfCharsetConverterInCore.rst [new file with mode: 0644]
typo3/sysext/indexed_search/Classes/Controller/SearchController.php
typo3/sysext/indexed_search/Classes/Indexer.php
typo3/sysext/indexed_search/Classes/Lexer.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php

index 10781f7..9ba97b8 100644 (file)
@@ -77,11 +77,6 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
     protected $moveJsFromHeaderToFooter = false;
 
     /**
-     * @var \TYPO3\CMS\Core\Charset\CharsetConverter
-     */
-    protected $csConvObj;
-
-    /**
      * @var \TYPO3\CMS\Core\Localization\Locales
      */
     protected $locales;
@@ -384,7 +379,6 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
     public function __construct($templateFile = '')
     {
         $this->reset();
-        $this->csConvObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
         $this->locales = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\Locales::class);
         if ($templateFile !== '') {
             $this->templateFile = $templateFile;
index 28fb94c..8c69f3b 100644 (file)
@@ -26,6 +26,7 @@ abstract class AbstractHierarchicalFilesystemDriver extends AbstractDriver
 {
     /**
      * @var CharsetConverter
+     * @deprecated instantiate CharsetConverter yourself in your driver implementation.
      */
     protected $charsetConversion;
 
@@ -33,9 +34,11 @@ abstract class AbstractHierarchicalFilesystemDriver extends AbstractDriver
      * Gets the charset conversion object.
      *
      * @return CharsetConverter
+     * @deprecated since TYPO3 v9.3, will be removed in TYPO3 v10.ß. Instantiate the CharsetConverter object yourself in your driver class.
      */
     protected function getCharsetConversion()
     {
+        trigger_error('Shorthand method "getCharsetConversion()" within the FAL driver method will be removed in TYPO3 v10.0, instantiate CharsetConverter yourself.', E_USER_DEPRECATED);
         if (!isset($this->charsetConversion)) {
             $this->charsetConversion = GeneralUtility::makeInstance(CharsetConverter::class);
         }
index bd69231..6e12a6e 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Resource\Driver;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Resource\Exception;
 use TYPO3\CMS\Core\Resource\FolderInterface;
 use TYPO3\CMS\Core\Resource\ResourceStorage;
@@ -304,8 +305,8 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
             // Allow ".", "-", 0-9, a-z, A-Z and everything beyond U+C0 (latin capital letter a with grave)
             $cleanFileName = preg_replace('/[' . self::UNSAFE_FILENAME_CHARACTER_EXPRESSION . ']/u', '_', trim($fileName));
         } else {
-            $fileName = $this->getCharsetConversion()->specCharsToASCII($charset, $fileName);
-            // Replace unwanted characters by underscores
+            $fileName = GeneralUtility::makeInstance(CharsetConverter::class)->specCharsToASCII($charset, $fileName);
+            // Replace unwanted characters with underscores
             $cleanFileName = preg_replace('/[' . self::UNSAFE_FILENAME_CHARACTER_EXPRESSION . '\\xC0-\\xFF]/', '_', trim($fileName));
         }
         // Strip trailing dots and return
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85125-UsagesOfCharsetConverterInCore.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85125-UsagesOfCharsetConverterInCore.rst
new file mode 100644 (file)
index 0000000..9d8d564
--- /dev/null
@@ -0,0 +1,39 @@
+.. include:: ../../Includes.txt
+
+==================================================================
+Deprecation: #85125 - Deprecate usages of CharsetConverter in core
+==================================================================
+
+See :issue:`85125`
+
+Description
+===========
+
+The following method has been deprecated:
+- :php:`TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver->getCharsetConversion()`
+
+The following public properties have been deprecated:
+- :php:`TYPO3\CMS\IndexedSearch\Lexer->csObj`
+- :php:`TYPO3\CMS\IndexedSearch\Indexer->csObj`
+
+
+Impact
+======
+
+Calling the method or accessing the property will trigger a deprecation warning.
+
+
+Affected Installations
+======================
+
+TYPO3 Installations with custom FAL drivers or special handling for indexed search extending the
+Lexer functionality.
+
+
+Migration
+=========
+
+Check the extension scanner if the site is affected and instantiate CharsetConverter directly in the
+callers' code.
+
+.. index:: PHP-API, FullyScanned
\ No newline at end of file
index 9fff7e3..f3c2416 100644 (file)
@@ -14,7 +14,6 @@ namespace TYPO3\CMS\IndexedSearch\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
@@ -156,11 +155,6 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
     protected $typoScriptService;
 
     /**
-     * @var CharsetConverter
-     */
-    protected $charsetConverter;
-
-    /**
      * @param \TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService
      */
     public function injectTypoScriptService(\TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService)
@@ -176,7 +170,6 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
      */
     public function initialize($searchData = [])
     {
-        $this->charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
         if (!is_array($searchData)) {
             $searchData = [];
         }
index c39c982..979197d 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\IndexedSearch;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
 use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
@@ -29,6 +30,16 @@ use TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility;
  */
 class Indexer
 {
+    use PublicPropertyDeprecationTrait;
+
+    /**
+     * List of all deprecated public properties
+     * @var array
+     */
+    protected $deprecatedPublicProperties = [
+        'csObj' => 'Using $csObj within Indexing is discouraged, the property will be removed in TYPO3 v10.0 - if needed instantiate CharsetConverter yourself.',
+    ];
+
     /**
      * @var array
      */
@@ -210,8 +221,9 @@ class Indexer
      * Charset class object
      *
      * @var \TYPO3\CMS\Core\Charset\CharsetConverter
+     * @deprecated since TYPO3 v9.3, will be removed in TYPO3 v10 (also the instantiation in the init() method).
      */
-    public $csObj;
+    protected $csObj;
 
     /**
      * Metaphone object, if any
index 2d2ed8e..ad7c5be 100644 (file)
@@ -14,12 +14,26 @@ namespace TYPO3\CMS\IndexedSearch;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Charset\CharsetConverter;
+use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * Lexer class for indexed_search
  * A lexer splits the text into words
  */
 class Lexer
 {
+    use PublicPropertyDeprecationTrait;
+
+    /**
+     * List of all deprecated public properties
+     * @var array
+     */
+    protected $deprecatedPublicProperties = [
+        'csObj' => 'Using $csObj within Indexing is discouraged, the property will be removed in TYPO3 v10.0 - if needed instantiate CharsetConverter yourself.',
+    ];
+
     /**
      * Debugging options:
      *
@@ -37,7 +51,8 @@ class Lexer
     /**
      * Charset class object
      *
-     * @var \TYPO3\CMS\Core\Charset\CharsetConverter
+     * @var CharsetConverter
+     * @deprecated since TYPO3 v9.3, will be removed in TYPO3 v10 (also the instantiation in the init() method).
      */
     public $csObj;
 
@@ -59,7 +74,8 @@ class Lexer
      */
     public function __construct()
     {
-        $this->csObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
+        // @deprecated, can be removed in TYPO3 v10.0.
+        $this->csObj = GeneralUtility::makeInstance(CharsetConverter::class);
     }
 
     /**
@@ -148,8 +164,9 @@ class Lexer
         } else {
             // Normal "single-byte" chars:
             // Remove chars:
+            $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
             foreach ($this->lexerConf['removeChars'] as $skipJoin) {
-                $theWord = str_replace($this->csObj->UnumberToChar($skipJoin), '', $theWord);
+                $theWord = str_replace($charsetConverter->UnumberToChar($skipJoin), '', $theWord);
             }
             // Add word:
             $words[] = $theWord;
index ee66197..3dfd885 100644 (file)
@@ -2312,4 +2312,9 @@ return [
             'Deprecation-85122-FunctionalityInCharsetConverter.rst'
         ],
     ],
+    'TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver->getCharsetConversion' => [
+        'restFiles' => [
+            'Deprecation-85125-UsagesOfCharsetConverterInCore.rst'
+        ],
+    ],
 ];
index b1a32f5..2b46e34 100644 (file)
@@ -401,4 +401,14 @@ return [
             'Deprecation-85078-PageRepositoryVersioningPreview.rst',
         ],
     ],
+    'TYPO3\CMS\IndexedSearch\Lexer->csObj' => [
+        'restFiles' => [
+            'Deprecation-85125-UsagesOfCharsetConverterInCore.rst'
+        ],
+    ],
+    'TYPO3\CMS\IndexedSearch\Indexer->csObj' => [
+        'restFiles' => [
+            'Deprecation-85125-UsagesOfCharsetConverterInCore.rst'
+        ],
+    ],
 ];