From 0a1f7db091a74f94ced890a902b2657795a9acb8 Mon Sep 17 00:00:00 2001 From: Christian Kuhn <lolli@schwarzbu.ch> Date: Thu, 15 Feb 2018 00:01:14 +0100 Subject: [PATCH] [TASK] Deprecate array handling in AbstractTreeView The array handling in AbstractTreeView has not been used in the core for quite some while. To clean that class up a bit, the functionality is now deprecated. Deprecation is covered by the extension scanner, except the class property $this->data which is too common and would create way too many false positives. Change-Id: I7bafdab242bf3d568c733cec669e895b87498241 Resolves: #83904 Releases: master Reviewed-on: https://review.typo3.org/55722 Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Andreas Wolf <andreas.wolf@typo3.org> Tested-by: Andreas Wolf <andreas.wolf@typo3.org> --- .../Classes/Tree/View/AbstractTreeView.php | 29 ++++++++++-- ...-83904-ArrayHandlingInAbstractTreeView.rst | 44 +++++++++++++++++++ .../Php/MethodCallMatcher.php | 14 ++++++ .../Php/PropertyPublicMatcher.php | 10 +++++ 4 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-83904-ArrayHandlingInAbstractTreeView.rst diff --git a/typo3/sysext/backend/Classes/Tree/View/AbstractTreeView.php b/typo3/sysext/backend/Classes/Tree/View/AbstractTreeView.php index 2f520a1cee3c..b4ce3fd50d5a 100644 --- a/typo3/sysext/backend/Classes/Tree/View/AbstractTreeView.php +++ b/typo3/sysext/backend/Classes/Tree/View/AbstractTreeView.php @@ -197,6 +197,7 @@ abstract class AbstractTreeView * This value has formerly been "subLevel" and "--sublevel--" * * @var string + * @deprecated since TYPO3 v9, will be removed in TYPO3 v10. */ public $subLevelID = '_SUB_LEVEL'; @@ -235,16 +236,19 @@ abstract class AbstractTreeView */ public $specUIDmap = []; - // For arrays: - // Holds the input data array /** + * For arrays, holds the input data array + * * @var bool + * @deprecated since TYPO3 v9, will be removed in TYPO3 v10. */ public $data = false; - // Holds an index with references to the data array. /** + * For arrays, holds an index with references to the data array. + * * @var bool + * @deprecated since TYPO3 v9, will be removed in TYPO3 v10. */ public $dataLookup = false; @@ -325,6 +329,8 @@ abstract class AbstractTreeView } // Sets the tree name which is used to identify the tree, used for JavaScript and other things $this->treeName = str_replace('_', '', $this->treeName ?: $this->table); + + // @deprecated since TYPO3 v9, will be removed in TYPO3 v10. Remove with $this->data and friends. // Setting this to FALSE disables the use of array-trees by default $this->data = false; $this->dataLookup = false; @@ -835,6 +841,8 @@ abstract class AbstractTreeView public function getCount($uid) { if (is_array($this->data)) { + // @deprecated since TYPO3 v9, will be removed in TYPO3 v10. Remove the "if" along with $this->data and friends. + trigger_error('Handling array data in AbstractTreeView has been deprecated', E_USER_DEPRECATED); $res = $this->getDataInit($uid); return $this->getDataCount($res); } @@ -880,6 +888,7 @@ abstract class AbstractTreeView public function getRecord($uid) { if (is_array($this->data)) { + // @deprecated since TYPO3 v9, will be removed in TYPO3 v10. Remove "if" with $this->data and friends. return $this->dataLookup[$uid]; } return BackendUtility::getRecordWSOL($this->table, $uid); @@ -898,6 +907,7 @@ abstract class AbstractTreeView public function getDataInit($parentId) { if (is_array($this->data)) { + // @deprecated since TYPO3 v9, will be removed in TYPO3 v10. Remove "if" with $this->data and friends. if (!is_array($this->dataLookup[$parentId][$this->subLevelID])) { $parentId = -1; } else { @@ -940,6 +950,7 @@ abstract class AbstractTreeView public function getDataCount(&$res) { if (is_array($this->data)) { + // @deprecated since TYPO3 v9, will be removed in TYPO3 v10. Remove "if" with $this->data and friends. return count($this->dataLookup[$res][$this->subLevelID]); } return $res->rowCount(); @@ -957,6 +968,7 @@ abstract class AbstractTreeView public function getDataNext(&$res) { if (is_array($this->data)) { + // @deprecated since TYPO3 v9, will be removed in TYPO3 v10. Remove the "if" along with $this->data and friends. if ($res < 0) { $row = false; } else { @@ -983,6 +995,7 @@ abstract class AbstractTreeView */ public function getDataFree(&$res) { + // @deprecated since TYPO3 v9, will be removed in TYPO3 v10. Remove "if" with $this->data and friends. Keep $res->closeCursor(). if (!is_array($this->data)) { $res->closeCursor(); } @@ -998,10 +1011,19 @@ abstract class AbstractTreeView * @param array $dataArr The input array, see examples below in this script. * @param bool $traverse Internal, for recursion. * @param int $pid Internal, for recursion. + * @deprecated since TYPO3 v9, will be removed in TYPO3 v10. */ public function setDataFromArray(&$dataArr, $traverse = false, $pid = 0) { + static $deprecationThrown = false; + if (!$deprecationThrown) { + // Throw deprecation only once for this recursive method + $deprecationThrown = true; + trigger_error('Method setDataFromArray() of AbstractTreeView has been deprecated', E_USER_DEPRECATED); + } + if (!$traverse) { + // @deprecated since TYPO3 v9, will be removed in TYPO3 v10. $this->data = &$dataArr; $this->dataLookup = []; // Add root @@ -1026,6 +1048,7 @@ abstract class AbstractTreeView */ public function setDataFromTreeArray(&$treeArr, &$treeLookupArr) { + trigger_error('Method setDataFromTreeArray() of AbstractTreeView has been deprecated', E_USER_DEPRECATED); $this->data = &$treeArr; $this->dataLookup = &$treeLookupArr; } diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83904-ArrayHandlingInAbstractTreeView.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83904-ArrayHandlingInAbstractTreeView.rst new file mode 100644 index 000000000000..db19752751a7 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83904-ArrayHandlingInAbstractTreeView.rst @@ -0,0 +1,44 @@ +.. include:: ../../Includes.txt + +======================================================== +Deprecation: #83904 - Array handling in AbstractTreeView +======================================================== + +See :issue:`83904` + +Description +=========== + +Handling arrays instead of database relations in class +:php:`TYPO3\CMS\Backend\Tree\View\AbstractTreeView` +has been deprecated. + + +Impact +====== + +Calling the following methods will throw deprecation errors and will be removed with core version 10: + +* [scanned] :php:`AbstractTreeView->setDataFromArray` +* [scanned] :php:`AbstractTreeView->setDataFromTreeArray` + +The following class properties should not be used any longer and will be removed with core version 10: + +* [not scanned] :php:`AbstractTreeView->data` +* [scanned] :php:`AbstractTreeView->dataLookup` +* [scanned] :php:`AbstractTreeView->subLevelID` + + +Affected Installations +====================== + +This feature was rarely used, it is pretty unlikely an instance is affected by a consuming extension. +The extension scanner will report most use cases. + + +Migration +========= + +No migration available. + +.. index:: Backend, PHP-API, PartiallyScanned \ No newline at end of file diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php index d84c2104b468..03544d75b986 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php @@ -1591,4 +1591,18 @@ return [ 'Deprecation-83883-PageNotFoundAndErrorHandlingInFrontend.rst', ], ], + 'TYPO3\CMS\Backend\Tree\View\AbstractTreeView->setDataFromArray' => [ + 'numberOfMandatoryArguments' => 1, + 'maximumNumberOfArguments' => 3, + 'restFiles' => [ + 'Deprecation-83904-ArrayHandlingInAbstractTreeView.rst', + ], + ], + 'TYPO3\CMS\Backend\Tree\View\AbstractTreeView->setDataFromTreeArray' => [ + 'numberOfMandatoryArguments' => 2, + 'maximumNumberOfArguments' => 2, + 'restFiles' => [ + 'Deprecation-83904-ArrayHandlingInAbstractTreeView.rst', + ], + ], ]; diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php index af858e654ab6..5b4898d82556 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php @@ -329,6 +329,16 @@ return [ 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->page_cache_reg1' => [ 'restFiles' => [ 'Deprecation-83905-TypoScriptFrontendController-page_cache_reg1.rst', + ] + ], + 'TYPO3\CMS\Backend\Tree\View\AbstractTreeView->dataLookup' => [ + 'restFiles' => [ + 'Deprecation-83904-ArrayHandlingInAbstractTreeView.rst', + ], + ], + 'TYPO3\CMS\Backend\Tree\View\AbstractTreeView->subLevelID' => [ + 'restFiles' => [ + 'Deprecation-83904-ArrayHandlingInAbstractTreeView.rst', ], ], ]; -- GitLab