From 557a6df216b7335a48edd635f7816ddd3fd062a1 Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Wed, 30 May 2018 22:20:56 +0200 Subject: [PATCH] [TASK] Deprecate usages of CharsetConverter in core 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> --- .../sysext/core/Classes/Page/PageRenderer.php | 6 --- .../AbstractHierarchicalFilesystemDriver.php | 3 ++ .../Classes/Resource/Driver/LocalDriver.php | 5 ++- ...n-85125-UsagesOfCharsetConverterInCore.rst | 39 +++++++++++++++++++ .../Classes/Controller/SearchController.php | 7 ---- .../sysext/indexed_search/Classes/Indexer.php | 14 ++++++- typo3/sysext/indexed_search/Classes/Lexer.php | 23 +++++++++-- .../Php/MethodCallMatcher.php | 5 +++ .../Php/PropertyPublicMatcher.php | 10 +++++ 9 files changed, 93 insertions(+), 19 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-85125-UsagesOfCharsetConverterInCore.rst diff --git a/typo3/sysext/core/Classes/Page/PageRenderer.php b/typo3/sysext/core/Classes/Page/PageRenderer.php index 10781f7962f0..9ba97b8f77c1 100644 --- a/typo3/sysext/core/Classes/Page/PageRenderer.php +++ b/typo3/sysext/core/Classes/Page/PageRenderer.php @@ -76,11 +76,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 */ @@ -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; diff --git a/typo3/sysext/core/Classes/Resource/Driver/AbstractHierarchicalFilesystemDriver.php b/typo3/sysext/core/Classes/Resource/Driver/AbstractHierarchicalFilesystemDriver.php index 28fb94c59cc5..8c69f3bacbcd 100644 --- a/typo3/sysext/core/Classes/Resource/Driver/AbstractHierarchicalFilesystemDriver.php +++ b/typo3/sysext/core/Classes/Resource/Driver/AbstractHierarchicalFilesystemDriver.php @@ -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); } diff --git a/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php b/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php index bd6923152a3c..6e12a6e43900 100644 --- a/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php +++ b/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php @@ -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 index 000000000000..9d8d56483803 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85125-UsagesOfCharsetConverterInCore.rst @@ -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 diff --git a/typo3/sysext/indexed_search/Classes/Controller/SearchController.php b/typo3/sysext/indexed_search/Classes/Controller/SearchController.php index 9fff7e3736de..f3c24167347b 100644 --- a/typo3/sysext/indexed_search/Classes/Controller/SearchController.php +++ b/typo3/sysext/indexed_search/Classes/Controller/SearchController.php @@ -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; @@ -155,11 +154,6 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle */ protected $typoScriptService; - /** - * @var CharsetConverter - */ - protected $charsetConverter; - /** * @param \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 = []; } diff --git a/typo3/sysext/indexed_search/Classes/Indexer.php b/typo3/sysext/indexed_search/Classes/Indexer.php index c39c98202735..979197ddd750 100644 --- a/typo3/sysext/indexed_search/Classes/Indexer.php +++ b/typo3/sysext/indexed_search/Classes/Indexer.php @@ -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 diff --git a/typo3/sysext/indexed_search/Classes/Lexer.php b/typo3/sysext/indexed_search/Classes/Lexer.php index 2d2ed8e62d59..ad7c5be8571a 100644 --- a/typo3/sysext/indexed_search/Classes/Lexer.php +++ b/typo3/sysext/indexed_search/Classes/Lexer.php @@ -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; diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php index ee661970ed05..3dfd88579845 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php @@ -2312,4 +2312,9 @@ return [ 'Deprecation-85122-FunctionalityInCharsetConverter.rst' ], ], + 'TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver->getCharsetConversion' => [ + 'restFiles' => [ + 'Deprecation-85125-UsagesOfCharsetConverterInCore.rst' + ], + ], ]; diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php index b1a32f51aaa7..2b46e34f8b48 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php @@ -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' + ], + ], ]; -- GitLab