Commit deae9035 authored by Jan Helke's avatar Jan Helke Committed by Frank Nägler
Browse files

[!!!][TASK] Doctrine: migrate ext:backend/Tree

Releases: master
Resolves: #75645
Change-Id: I4ee542e4c939388cfccdb896ff1e38e849965849
Reviewed-on: https://review.typo3.org/47693


Reviewed-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: default avatarDaniel Goerz <ervaude@gmail.com>
Reviewed-by: Frank Nägler's avatarFrank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Nägler's avatarFrank Naegler <frank.naegler@typo3.org>
parent bc764d2e
...@@ -18,7 +18,8 @@ use TYPO3\CMS\Backend\Routing\Router; ...@@ -18,7 +18,8 @@ use TYPO3\CMS\Backend\Routing\Router;
use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Database\DatabaseConnection; use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory; use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
...@@ -832,9 +833,16 @@ abstract class AbstractTreeView ...@@ -832,9 +833,16 @@ abstract class AbstractTreeView
$res = $this->getDataInit($uid); $res = $this->getDataInit($uid);
return $this->getDataCount($res); return $this->getDataCount($res);
} else { } else {
$db = $this->getDatabaseConnection(); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$where = $this->parentField . '=' . $db->fullQuoteStr($uid, $this->table) . BackendUtility::deleteClause($this->table) . BackendUtility::versioningPlaceholderClause($this->table) . $this->clause; $count = $queryBuilder
return $db->exec_SELECTcountRows('uid', $this->table, $where); ->count('uid')
->from($this->table)
->where($queryBuilder->expr()->eq($this->parentField, $queryBuilder->createNamedParameter($uid)))
->andWhere(QueryHelper::stripLogicalOperatorPrefix($this->clause))
->execute()
->fetchColumn();
return (int)$count;
} }
} }
...@@ -885,9 +893,19 @@ abstract class AbstractTreeView ...@@ -885,9 +893,19 @@ abstract class AbstractTreeView
} }
return $parentId; return $parentId;
} else { } else {
$db = $this->getDatabaseConnection(); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$where = $this->parentField . '=' . $db->fullQuoteStr($parentId, $this->table) . BackendUtility::deleteClause($this->table) . BackendUtility::versioningPlaceholderClause($this->table) . $this->clause; $queryBuilder
return $db->exec_SELECTquery(implode(',', $this->fieldArray), $this->table, $where, '', $this->orderByFields); ->select(...$this->fieldArray)
->from($this->table)
->where($queryBuilder->expr()->eq($this->parentField, $queryBuilder->createNamedParameter($parentId)))
->andWhere(QueryHelper::stripLogicalOperatorPrefix($this->clause));
foreach (QueryHelper::parseOrderBy($this->orderByFields) as $orderPair) {
list($fieldName, $order) = $orderPair;
$queryBuilder->addOrderBy($fieldName, $order);
}
return $queryBuilder->execute();
} }
} }
...@@ -904,7 +922,7 @@ abstract class AbstractTreeView ...@@ -904,7 +922,7 @@ abstract class AbstractTreeView
if (is_array($this->data)) { if (is_array($this->data)) {
return count($this->dataLookup[$res][$this->subLevelID]); return count($this->dataLookup[$res][$this->subLevelID]);
} else { } else {
return $this->getDatabaseConnection()->sql_num_rows($res); return count($res);
} }
} }
...@@ -927,7 +945,7 @@ abstract class AbstractTreeView ...@@ -927,7 +945,7 @@ abstract class AbstractTreeView
} }
return $row; return $row;
} else { } else {
while ($row = @$this->getDatabaseConnection()->sql_fetch_assoc($res)) { while ($row = $res->fetch()) {
BackendUtility::workspaceOL($this->table, $row, $this->BE_USER->workspace, true); BackendUtility::workspaceOL($this->table, $row, $this->BE_USER->workspace, true);
if (is_array($row)) { if (is_array($row)) {
break; break;
...@@ -947,7 +965,7 @@ abstract class AbstractTreeView ...@@ -947,7 +965,7 @@ abstract class AbstractTreeView
public function getDataFree(&$res) public function getDataFree(&$res)
{ {
if (!is_array($this->data)) { if (!is_array($this->data)) {
$this->getDatabaseConnection()->sql_free_result($res); $res->closeCursor();
} }
} }
...@@ -1010,12 +1028,4 @@ abstract class AbstractTreeView ...@@ -1010,12 +1028,4 @@ abstract class AbstractTreeView
{ {
return $GLOBALS['BE_USER']; return $GLOBALS['BE_USER'];
} }
/**
* @return DatabaseConnection
*/
protected function getDatabaseConnection()
{
return $GLOBALS['TYPO3_DB'];
}
} }
...@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Backend\Tree\View; ...@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Backend\Tree\View;
*/ */
use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
/** /**
...@@ -83,7 +84,7 @@ class BrowseTreeView extends AbstractTreeView ...@@ -83,7 +84,7 @@ class BrowseTreeView extends AbstractTreeView
// This will hide records from display - it has nothing to do with user rights!! // This will hide records from display - it has nothing to do with user rights!!
$clauseExcludePidList = ''; $clauseExcludePidList = '';
if ($pidList = $this->getBackendUser()->getTSConfigVal('options.hideRecords.pages')) { if ($pidList = $this->getBackendUser()->getTSConfigVal('options.hideRecords.pages')) {
if ($pidList = $this->getDatabaseConnection()->cleanIntList($pidList)) { if ($pidList = implode(',', GeneralUtility::intExplode(',', $pidList))) {
$clauseExcludePidList = ' AND pages.uid NOT IN (' . $pidList . ')'; $clauseExcludePidList = ' AND pages.uid NOT IN (' . $pidList . ')';
} }
} }
...@@ -148,18 +149,18 @@ class BrowseTreeView extends AbstractTreeView ...@@ -148,18 +149,18 @@ class BrowseTreeView extends AbstractTreeView
$title = parent::getTitleStr($row, $titleLen); $title = parent::getTitleStr($row, $titleLen);
} }
if (!empty($row['is_siteroot']) && $this->getBackendUser()->getTSConfigVal('options.pageTree.showDomainNameWithTitle')) { if (!empty($row['is_siteroot']) && $this->getBackendUser()->getTSConfigVal('options.pageTree.showDomainNameWithTitle')) {
$rows = $this->getDatabaseConnection()->exec_SELECTgetRows( $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_domain');
'domainName,sorting', $row = $queryBuilder
'sys_domain', ->select('domainName', 'sorting')
'pid=' . $this->getDatabaseConnection()->quoteStr( ->from('sys_domain')
$row['uid'] . BackendUtility::deleteClause('sys_domain') . BackendUtility::BEenableFields('sys_domain'), ->where($queryBuilder->expr()->eq('pid', (int)$row['uid']))
'sys_domain' ->orderBy('sorting')
), ->setMaxResults(1)
'', ->execute()
'sorting', ->fetch();
1);
if (is_array($rows) && !empty($rows)) { if ($row !== false) {
$title = sprintf('%s [%s]', $title, htmlspecialchars($rows[0]['domainName'])); $title = sprintf('%s [%s]', $title, htmlspecialchars($row['domainName']));
} }
} }
return $title; return $title;
......
...@@ -16,7 +16,8 @@ namespace TYPO3\CMS\Backend\Tree\View; ...@@ -16,7 +16,8 @@ namespace TYPO3\CMS\Backend\Tree\View;
use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Database\DatabaseConnection; use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryContextType;
use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory; use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
...@@ -339,17 +340,33 @@ class PagePositionMap ...@@ -339,17 +340,33 @@ class PagePositionMap
$colPosArray = GeneralUtility::trimExplode(',', $colPosList, true); $colPosArray = GeneralUtility::trimExplode(',', $colPosList, true);
$lines = array(); $lines = array();
foreach ($colPosArray as $kk => $vv) { foreach ($colPosArray as $kk => $vv) {
$res = $this->getDatabase()->exec_SELECTquery('*', 'tt_content', 'pid=' . (int)$pid . ($showHidden ? '' : BackendUtility::BEenableFields('tt_content')) . ' AND colPos=' . (int)$vv . ((string)$this->cur_sys_language !== '' ? ' AND sys_language_uid=' . (int)$this->cur_sys_language : '') . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content'), '', 'sorting'); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
$queryBuilder->getQueryContext()
->setContext(QueryContextType::BACKEND_NO_VERSIONING_PLACEHOLDERS)
->setIgnoreEnableFields($showHidden);
$queryBuilder
->select('*')
->from('tt_content')
->where($queryBuilder->expr()->eq('pid', (int)$pid))
->andWhere($queryBuilder->expr()->eq('colPos', (int)$vv))
->orderBy('sorting');
if ((string)$this->cur_sys_language !== '') {
$queryBuilder->andWhere($queryBuilder->expr()->eq('sys_language_uid', (int)$this->cur_sys_language));
}
$res = $queryBuilder->execute();
$lines[$vv] = array(); $lines[$vv] = array();
$lines[$vv][] = $this->insertPositionIcon('', $vv, $kk, $moveUid, $pid); $lines[$vv][] = $this->insertPositionIcon('', $vv, $kk, $moveUid, $pid);
while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
while ($row = $res->fetch()) {
BackendUtility::workspaceOL('tt_content', $row); BackendUtility::workspaceOL('tt_content', $row);
if (is_array($row)) { if (is_array($row)) {
$lines[$vv][] = $this->wrapRecordHeader($this->getRecordHeader($row), $row); $lines[$vv][] = $this->wrapRecordHeader($this->getRecordHeader($row), $row);
$lines[$vv][] = $this->insertPositionIcon($row, $vv, $kk, $moveUid, $pid); $lines[$vv][] = $this->insertPositionIcon($row, $vv, $kk, $moveUid, $pid);
} }
} }
$this->getDatabase()->sql_free_result($res);
} }
return $this->printRecordMap($lines, $colPosArray, $pid); return $this->printRecordMap($lines, $colPosArray, $pid);
} }
...@@ -579,12 +596,4 @@ class PagePositionMap ...@@ -579,12 +596,4 @@ class PagePositionMap
{ {
return $GLOBALS['LANG']; return $GLOBALS['LANG'];
} }
/**
* @return DatabaseConnection
*/
protected function getDatabase()
{
return $GLOBALS['TYPO3_DB'];
}
} }
=====================================================
Breaking: #75645 - Doctrine: migrate ext:backend/Tree
=====================================================
Description
===========
This patch changes all database related functions to use the new Doctrine database API.
The method :php:``getDatabaseConnection()`` has been removed.
Impact
======
Calls to the method :php:``AbstractTreeView::getDataInit()`` will now return :php:``Statement`` objects.
All other :php:``AbstractTreeView::getData*`` methods now expects such as ::php:``Statement`` object
instead of a SQL resource.
Affected Installations
======================
All installations using TreeViews extending the AbstractTreeView.
Migration
=========
Migrate all calls that work with the result :php:``Statement`` from TreeView to be able to
handle :php:``Statement`` objects.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment