Commit 6b21391e authored by Georg Ringer's avatar Georg Ringer Committed by Jan Helke
Browse files

[TASK] Doctrine: Migrate EXT:backend I

Migrate the first part of DB calls of EXT:backend

Resolves: #76624
Releases: master
Change-Id: Iac323bed36af22e5c38eb4fb8a0e0f72bbee6d93
Reviewed-on: https://review.typo3.org/48574

Tested-by: default avatarBamboo TYPO3com <info@typo3.com>
Reviewed-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Jan Helke's avatarJan Helke <typo3@helke.de>
Tested-by: Jan Helke's avatarJan Helke <typo3@helke.de>
parent d7e86d1f
......@@ -19,6 +19,7 @@ use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Backend\Avatar\Avatar;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Resource\Folder;
......@@ -645,11 +646,18 @@ class ElementInformationController
$selectTable = $table;
$selectUid = $ref;
}
$rows = $this->getDatabaseConnection()->exec_SELECTgetRows(
'*',
'sys_refindex',
'ref_table=' . $this->getDatabaseConnection()->fullQuoteStr($selectTable, 'sys_refindex') . ' AND ref_uid=' . (int)$selectUid . ' AND deleted=0'
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_refindex');
$rows = $queryBuilder
->select('*')
->from('sys_refindex')
->where(
$queryBuilder->expr()->eq('ref_table', $queryBuilder->createNamedParameter($selectTable)),
$queryBuilder->expr()->eq('ref_uid', (int)$selectUid),
$queryBuilder->expr()->eq('deleted', 0)
)
->execute()
->fetchAll();
// Compile information for title tag:
$infoData = array();
......@@ -755,11 +763,18 @@ class ElementInformationController
protected function makeRefFrom($table, $ref)
{
$lang = $this->getLanguageService();
$rows = $this->getDatabaseConnection()->exec_SELECTgetRows(
'*',
'sys_refindex',
'tablename=' . $this->getDatabaseConnection()->fullQuoteStr($table, 'sys_refindex') . ' AND recuid=' . (int)$ref
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_refindex');
$rows = $queryBuilder
->select('*')
->from('sys_refindex')
->where(
$queryBuilder->expr()->eq('tablename', $queryBuilder->createNamedParameter($table)),
$queryBuilder->expr()->eq('recuid', (int)$ref)
)
->execute()
->fetchAll();
// Compile information for title tag:
$infoData = array();
......@@ -853,11 +868,16 @@ class ElementInformationController
*/
protected function transformFileReferenceToRecordReference(array $referenceRecord)
{
$fileReference = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
'*',
'sys_file_reference',
'uid=' . (int)$referenceRecord['recuid']
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_file_reference');
$queryBuilder->getRestrictions()->removeAll();
$fileReference = $queryBuilder
->select('*')
->from('sys_file_reference')
->where($queryBuilder->expr()->eq('uid', (int)$referenceRecord['recuid']))
->execute()
->fetch();
return array(
'recuid' => $fileReference['uid_foreign'],
'tablename' => $fileReference['tablenames'],
......@@ -887,14 +907,4 @@ class ElementInformationController
{
return $GLOBALS['BE_USER'];
}
/**
* Returns the database connection
*
* @return \TYPO3\CMS\Core\Database\DatabaseConnection
*/
protected function getDatabaseConnection()
{
return $GLOBALS['TYPO3_DB'];
}
}
......@@ -21,7 +21,8 @@ use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Tree\View\NewRecordPageTreeView;
use TYPO3\CMS\Backend\Tree\View\PagePositionMap;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -167,8 +168,13 @@ class NewRecordController extends AbstractModule
$this->perms_clause = $beUser->getPagePermsClause(1);
// This will hide records from display - it has nothing to do with user rights!!
if ($pidList = $beUser->getTSConfigVal('options.hideRecords.pages')) {
if ($pidList = $this->getDatabaseConnection()->cleanIntList($pidList)) {
$this->perms_clause .= ' AND pages.uid NOT IN (' . $pidList . ')';
if (!empty($pidList)) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('pages');
$this->perms_clause .= ' AND ' . $queryBuilder->expr()->in(
'pages.uid',
GeneralUtility::intExplode(',', $pidList)
);
}
}
// Setting GPvars:
......@@ -380,11 +386,17 @@ class NewRecordController extends AbstractModule
*/
public function pagesOnly()
{
$numberOfPages = $this->getDatabaseConnection()->exec_SELECTcountRows(
'*',
'pages',
'1=1' . BackendUtility::deleteClause('pages')
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_language');
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$numberOfPages = $queryBuilder
->count('*')
->from('pages')
->execute()
->fetchColumn(0);
if ($numberOfPages > 0) {
$this->code .= '
<h3>' . htmlspecialchars($this->getLanguageService()->getLL('selectPosition')) . ':</h3>
......@@ -716,11 +728,16 @@ class NewRecordController extends AbstractModule
*/
protected function checkIfLanguagesExist()
{
$languageCount = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'sys_language', '1=1');
if ($languageCount) {
$languageCount = true;
}
return $languageCount;
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_language');
$queryBuilder->getRestrictions()->removeAll();
$count = $queryBuilder
->count('uid')
->from('sys_language')
->execute()
->fetchColumn(0);
return (bool)$count;
}
/**
......@@ -742,14 +759,4 @@ class NewRecordController extends AbstractModule
{
return $GLOBALS['BE_USER'];
}
/**
* Returns the database connection
*
* @return DatabaseConnection
*/
protected function getDatabaseConnection()
{
return $GLOBALS['TYPO3_DB'];
}
}
......@@ -28,6 +28,9 @@ use TYPO3\CMS\Backend\Tree\View\ContentLayoutPagePositionMap;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\BackendLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
......@@ -541,17 +544,22 @@ class PageLayoutController
protected function getLocalizedPageTitle()
{
if ($this->current_sys_language > 0) {
$overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
'title',
'pages_language_overlay',
'pid = ' . (int)$this->id .
' AND sys_language_uid = ' . (int)$this->current_sys_language .
BackendUtility::deleteClause('pages_language_overlay') .
BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
'',
'',
''
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('pages_language_overlay');
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
$overlayRecord = $queryBuilder
->select('title')
->from('pages_language_overlay')
->where(
$queryBuilder->expr()->eq('pid', (int)$this->id),
$queryBuilder->expr()->eq('sys_language_uid', (int)$this->current_sys_language)
)
->setMaxResults(1)
->execute()
->fetch();
return $overlayRecord['title'];
} else {
return $this->pageinfo['title'];
......@@ -1102,17 +1110,22 @@ class PageLayoutController
if ($this->pageIsNotLockedForEditors() && $this->getBackendUser()->checkLanguageAccess(0)) {
// Edit localized page_language_overlay only when one specific language is selected
if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
$overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid',
'pages_language_overlay',
'pid = ' . (int)$this->id . ' ' .
'AND sys_language_uid = ' . (int)$this->current_sys_language .
BackendUtility::deleteClause('pages_language_overlay') .
BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
'',
'',
''
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('pages_language_overlay');
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
$overlayRecord = $queryBuilder
->select('uid')
->from('pages_language_overlay')
->where(
$queryBuilder->expr()->eq('pid', (int)$this->id),
$queryBuilder->expr()->eq('sys_language_uid', (int)$this->current_sys_language)
)
->setMaxResults(1)
->execute()
->fetch();
// Edit button
$urlParameters = [
'edit' => [
......
......@@ -23,6 +23,7 @@ use TYPO3\CMS\Backend\Form\FormResultCompiler;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -243,23 +244,26 @@ class RteController extends AbstractWizardController
&& $this->checkEditAccess($this->P['table'], $this->P['uid'])) {
$closeUrl = GeneralUtility::sanitizeLocalUrl($this->P['returnUrl']);
// Getting settings for the undo button:
$undoButton = 0;
$databaseConnection = $this->getDatabaseConnection();
$undoRes = $databaseConnection->exec_SELECTquery(
'tstamp',
'sys_history',
'tablename=' . $databaseConnection->fullQuoteStr(
$this->P['table'],
'sys_history'
) . ' AND recuid=' . (int)$this->P['uid'],
'',
'tstamp DESC',
'1'
);
if ($undoButtonR = $databaseConnection->sql_fetch_assoc($undoRes)) {
$undoButton = 1;
}
$undoButton = false;
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_history');
$undoButtonR = $queryBuilder
->select('tstamp')
->from('sys_history')
->where(
$queryBuilder->expr()->eq('tablename', $queryBuilder->createNamedParameter($this->P['table'])),
$queryBuilder->expr()->eq('recuid', (int)$this->P['uid'])
)
->orderBy('tstamp', 'desc')
->setMaxResults(1)
->execute()
->fetchColumn();
if ($undoButtonR !== false) {
$undoButton = true;
}
// Close
$closeButton = $buttonBar->makeLinkButton()
->setHref($closeUrl)
......
......@@ -20,6 +20,7 @@ use TYPO3\CMS\Backend\Form\InlineStackProcessor;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
......@@ -466,11 +467,18 @@ class InlineRecordContainer extends AbstractContainer
if (!empty($rec['sys_language_uid'])) {
$sys_language_uid = $rec['sys_language_uid'][0];
}
$recordInDatabase = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid',
'sys_file_metadata',
'file = ' . (int)substr($rec['uid_local'], 9) . ' AND sys_language_uid = ' . $sys_language_uid
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_file_metadata');
$recordInDatabase = $queryBuilder
->select('uid')
->from('sys_file_metadata')
->where(
$queryBuilder->expr()->eq('file', (int)substr($rec['uid_local'], 9)),
$queryBuilder->expr()->eq('sys_language_uid', (int)$sys_language_uid)
)
->setMaxResults(1)
->execute()
->fetch();
if ($backendUser->check('tables_modify', 'sys_file_metadata')) {
$url = BackendUtility::getModuleUrl('record_edit', array(
'edit[sys_file_metadata][' . (int)$recordInDatabase['uid'] . ']' => 'edit'
......
......@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Backend\Tree\Pagetree;
*/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -288,8 +289,18 @@ class Commands
*/
public static function getDomainName($uid)
{
$whereClause = 'pid=' . (int)$uid . BackendUtility::deleteClause('sys_domain') . BackendUtility::BEenableFields('sys_domain');
$domain = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('domainName', 'sys_domain', $whereClause, '', 'sorting');
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_domain');
$domain = $queryBuilder
->select('domainName')
->from('sys_domain')
->where(
$queryBuilder->expr()->eq('pid', (int)$uid)
)
->setMaxResults(1)
->orderBy('sorting')
->execute()
->fetch();
return is_array($domain) ? htmlspecialchars($domain['domainName']) : '';
}
......
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