Skip to content

Commit

Permalink
[TASK] Deprecate array handling in AbstractTreeView
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lolli42 authored and andreaswolf committed Feb 18, 2018
1 parent 96d3514 commit 0a1f7db
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
29 changes: 26 additions & 3 deletions typo3/sysext/backend/Classes/Tree/View/AbstractTreeView.php
Expand Up @@ -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';

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -325,6 +329,8 @@ public function init($clause = '', $orderByFields = '')
}
// 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;
Expand Down Expand Up @@ -835,6 +841,8 @@ public function getTree($uid, $depth = 999, $depthData = '')
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);
}
Expand Down Expand Up @@ -880,6 +888,7 @@ public function getRootRecord()
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);
Expand All @@ -898,6 +907,7 @@ public function getRecord($uid)
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 {
Expand Down Expand Up @@ -940,6 +950,7 @@ public function getDataInit($parentId)
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();
Expand All @@ -957,6 +968,7 @@ public function getDataCount(&$res)
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 {
Expand All @@ -983,6 +995,7 @@ public function getDataNext(&$res)
*/
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();
}
Expand All @@ -998,10 +1011,19 @@ public function getDataFree(&$res)
* @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
Expand All @@ -1026,6 +1048,7 @@ public function setDataFromArray(&$dataArr, $traverse = false, $pid = 0)
*/
public function setDataFromTreeArray(&$treeArr, &$treeLookupArr)
{
trigger_error('Method setDataFromTreeArray() of AbstractTreeView has been deprecated', E_USER_DEPRECATED);
$this->data = &$treeArr;
$this->dataLookup = &$treeLookupArr;
}
Expand Down
@@ -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
Expand Up @@ -1591,4 +1591,18 @@
'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',
],
],
];
Expand Up @@ -329,6 +329,16 @@
'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',
],
],
];

0 comments on commit 0a1f7db

Please sign in to comment.