Commit dac33968 authored by Tobias Adolph's avatar Tobias Adolph Committed by Morton Jonuschat
Browse files

[TASK] Doctrine: API call to retrieve all connections

Add a new method to the ConnectionPool class to retrieve a list
of all currently configured database connections.

Enhance the system information tooltip to show information about
all database connections instead of only the default connection.

Resolves: #77371
Releases: master
Change-Id: I82948d45c29e8edd47209fde30850f26681404c4
Reviewed-on: https://review.typo3.org/49340

Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
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>
parent ab0955d3
......@@ -167,13 +167,17 @@ class SystemInformationToolbarItem implements ToolbarItemInterface
*/
protected function getDatabase()
{
$this->systemInformation[] = array(
'title' => htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.sysinfo.database')),
'value' => GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME)
->getServerVersion(),
'icon' => $this->iconFactory->getIcon('sysinfo-database', Icon::SIZE_SMALL)->render()
);
foreach (GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionNames() as $connectionName) {
$this->systemInformation[] = [
'title' => $this->getLanguageService()
->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.sysinfo.database')
. ' (' . htmlspecialchars($connectionName) . ')',
'value' => GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionByName($connectionName)
->getServerVersion(),
'icon' => $this->iconFactory->getIcon('sysinfo-database', Icon::SIZE_SMALL)->render()
];
}
}
/**
......
......@@ -156,4 +156,18 @@ class ConnectionPool
return $this->getConnectionForTable($tableName)->createQueryBuilder();
}
/**
* Returns an array containing the names of all currently configured connections.
*
* This method should only be used in edge cases. Use getConnectionForTable() so
* that the tablename<>databaseConnection mapping will be taken into account.
*
* @internal
* @return array
*/
public function getConnectionNames(): array
{
return array_keys($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']);
}
}
<?php
declare (strict_types = 1);
namespace TYPO3\CMS\Core\Tests\Unit\Database;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Tests\UnitTestCase;
/**
* Test case
*/
class ConnectionPoolTest extends UnitTestCase
{
/**
* @test
*/
public function getConnectionNamesReturnsConfiguredConnectionNames()
{
$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'] = [
'Default' => [
'aConfigDetail' => '',
],
'klaus' => [
'anotherConfigDetail' => '',
],
];
$this->assertSame(['Default', 'klaus'], (new ConnectionPool())->getConnectionNames());
}
}
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