[TASK] Use fully qualified name resolution in PHP 5.5
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / Action / Step / DatabaseConnect.php
index b43d60d..9037eae 100644 (file)
@@ -1,30 +1,20 @@
 <?php
 namespace TYPO3\CMS\Install\Controller\Action\Step;
 
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
+/**
+ * This file is part of the TYPO3 CMS project.
  *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
+ * 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.
  *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
  *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
+ * The TYPO3 project - inspiring people to share!
+ */
 
-use TYPO3\CMS\Install\Controller\Action;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 
 /**
  * Database connect step:
@@ -33,7 +23,7 @@ use TYPO3\CMS\Install\Controller\Action;
  * - Sets database credentials in LocalConfiguration
  * - Loads / unloads ext:dbal and ext:adodb if requested
  */
-class DatabaseConnect extends Action\AbstractAction implements StepInterface {
+class DatabaseConnect extends AbstractStepAction {
 
        /**
         * Execute database step:
@@ -46,7 +36,7 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
                $result = array();
 
                /** @var $configurationManager \TYPO3\CMS\Core\Configuration\ConfigurationManager */
-               $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
+               $configurationManager = $this->objectManager->get(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
 
                $postValues = $this->postValues['values'];
                if (isset($postValues['loadDbal'])) {
@@ -90,8 +80,8 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
                                $config = $configurationManager->getConfigurationValueByPath('EXTCONF/dbal/handlerCfg');
                                $driver = $config['_DEFAULT']['config']['driver'];
                                if ($driver === 'oci8') {
-                                       $configurationManager['_DEFAULT']['config']['driverOptions']['connectSID']
-                                               = $postValues['type'] === 'sid' ? TRUE : FALSE;
+                                       $config['_DEFAULT']['config']['driverOptions']['connectSID'] = ($postValues['type'] === 'sid');
+                                       $localConfigurationPathValuePairs['EXTCONF/dbal/handlerCfg'] = $config;
                                }
                        }
 
@@ -101,7 +91,7 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
                                        $localConfigurationPathValuePairs['DB/username'] = $value;
                                } else {
                                        /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
-                                       $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
+                                       $errorStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
                                        $errorStatus->setTitle('Database username not valid');
                                        $errorStatus->setMessage('Given username must be shorter than fifty characters.');
                                        $result[] = $errorStatus;
@@ -114,7 +104,7 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
                                        $localConfigurationPathValuePairs['DB/password'] = $value;
                                } else {
                                        /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
-                                       $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
+                                       $errorStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
                                        $errorStatus->setTitle('Database password not valid');
                                        $errorStatus->setMessage('Given password must be shorter than fifty characters.');
                                        $result[] = $errorStatus;
@@ -127,22 +117,34 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
                                        $localConfigurationPathValuePairs['DB/host'] = $value;
                                } else {
                                        /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
-                                       $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
+                                       $errorStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
                                        $errorStatus->setTitle('Database host not valid');
                                        $errorStatus->setMessage('Given host is not alphanumeric (a-z, A-Z, 0-9 or _-.:) or longer than fifty characters.');
                                        $result[] = $errorStatus;
                                }
                        }
 
-                       if (isset($postValues['port'])) {
+                       if (isset($postValues['port']) && $postValues['host'] !== 'localhost') {
                                $value = $postValues['port'];
                                if (preg_match('/^[0-9]+(:.+)?$/', $value) && $value > 0 && $value <= 65535) {
                                        $localConfigurationPathValuePairs['DB/port'] = (int)$value;
                                } else {
                                        /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
-                                       $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
+                                       $errorStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
                                        $errorStatus->setTitle('Database port not valid');
-                                       $errorStatus->setMessage('Given port is not numeric or within range 1 to 65535');
+                                       $errorStatus->setMessage('Given port is not numeric or within range 1 to 65535.');
+                                       $result[] = $errorStatus;
+                               }
+                       }
+
+                       if (isset($postValues['socket']) && $postValues['socket'] !== '') {
+                               if (@file_exists($postValues['socket'])) {
+                                       $localConfigurationPathValuePairs['DB/socket'] = $postValues['socket'];
+                               } else {
+                                       /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
+                                       $errorStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
+                                       $errorStatus->setTitle('Socket does not exist');
+                                       $errorStatus->setMessage('Given socket location does not exist on server.');
                                        $result[] = $errorStatus;
                                }
                        }
@@ -153,7 +155,7 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
                                        $localConfigurationPathValuePairs['DB/database'] = $value;
                                } else {
                                        /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
-                                       $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
+                                       $errorStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
                                        $errorStatus->setTitle('Database name not valid');
                                        $errorStatus->setMessage('Given database name must be shorter than fifty characters.');
                                        $result[] = $errorStatus;
@@ -165,19 +167,19 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
 
                                // After setting new credentials, test again and create an error message if connect is not successful
                                // @TODO: This could be simplified, if isConnectSuccessful could be released from TYPO3_CONF_VARS
-                               // and feeded with connect values directly in order to obsolete the bootstrap reload.
+                               // and fed with connect values directly in order to obsolete the bootstrap reload.
                                \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
                                        ->populateLocalConfiguration()
-                                       ->setCoreCacheToNullBackend();
+                                       ->disableCoreAndClassesCache();
                                if ($this->isDbalEnabled()) {
-                                       require(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('dbal') . 'ext_localconf.php');
-                                       $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
+                                       require(ExtensionManagementUtility::extPath('dbal') . 'ext_localconf.php');
+                                       \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
                                }
                                if (!$this->isConnectSuccessful()) {
                                        /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
-                                       $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
+                                       $errorStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
                                        $errorStatus->setTitle('Database connect not successful');
-                                       $errorStatus->setMessage('Connecting the database with given settings failed. Please check.');
+                                       $errorStatus->setMessage('Connecting to the database with given settings failed. Please check.');
                                        $result[] = $errorStatus;
                                }
                        }
@@ -189,36 +191,38 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
        /**
         * Step needs to be executed if database connection is not successful.
         *
-        * @return boolean
+        * @throws \TYPO3\CMS\Install\Controller\Exception\RedirectException
+        * @return bool
         */
        public function needsExecution() {
-               if (!$this->isConnectSuccessful()) {
-                       return TRUE;
+               if ($this->isConnectSuccessful() && $this->isConfigurationComplete()) {
+                       return FALSE;
                }
-               if (!isset($GLOBALS['TYPO3_CONF_VARS']['DB']['host'])
-                       || !isset($GLOBALS['TYPO3_CONF_VARS']['DB']['port'])
-               ) {
-                       return TRUE;
+               if (!$this->isHostConfigured() && !$this->isDbalEnabled()) {
+                       $this->useDefaultValuesForNotConfiguredOptions();
+                       throw new \TYPO3\CMS\Install\Controller\Exception\RedirectException(
+                               'Wrote default settings to LocalConfiguration.php, redirect needed',
+                               1377611168
+                       );
                }
-               return FALSE;
+               return TRUE;
        }
 
        /**
-        * Render this step
+        * Executes the step
         *
-        * @return string
+        * @return string Rendered content
         */
-       public function handle() {
-               $this->initialize();
-
+       protected function executeAction() {
                $isDbalEnabled = $this->isDbalEnabled();
                $this->view
                        ->assign('isDbalEnabled', $isDbalEnabled)
-                       ->assign('username', $GLOBALS['TYPO3_CONF_VARS']['DB']['username'] ?: '')
-                       ->assign('password', $GLOBALS['TYPO3_CONF_VARS']['DB']['password'] ?: '')
-                       ->assign('host', $this->getConfiguredHost() ?: '127.0.0.1')
+                       ->assign('username', $this->getConfiguredUsername())
+                       ->assign('password', $this->getConfiguredPassword())
+                       ->assign('host', $this->getConfiguredHost())
                        ->assign('port', $this->getConfiguredOrDefaultPort())
-                       ->assign('database', $GLOBALS['TYPO3_CONF_VARS']['DB']['database'] ?: '');
+                       ->assign('database', $GLOBALS['TYPO3_CONF_VARS']['DB']['database'] ?: '')
+                       ->assign('socket', $GLOBALS['TYPO3_CONF_VARS']['DB']['socket'] ?: '');
 
                if ($isDbalEnabled) {
                        $this->view->assign('selectedDbalDriver', $this->getSelectedDbalDriver());
@@ -229,54 +233,18 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
                                ->assign('renderConnectDetailsUsername', TRUE)
                                ->assign('renderConnectDetailsPassword', TRUE)
                                ->assign('renderConnectDetailsHost', TRUE)
-                               ->assign('renderConnectDetailsPort', TRUE);
+                               ->assign('renderConnectDetailsPort', TRUE)
+                               ->assign('renderConnectDetailsSocket', TRUE);
                }
+               $this->assignSteps();
 
                return $this->view->render();
        }
 
        /**
-        * Render fields required for successful connect based on dbal driver selection.
-        * Hint: There is a code duplication in handle() and this method. This
-        * is done by intention to keep this code area easy to maintain and understand.
-        *
-        * @return void
-        */
-       protected function setDbalInputFieldsToRender() {
-               $driver = $this->getSelectedDbalDriver();
-               switch($driver) {
-                       case 'mssql':
-                       case 'odbc_mssql':
-                       case 'postgres':
-                               $this->view
-                                       ->assign('renderConnectDetailsUsername', TRUE)
-                                       ->assign('renderConnectDetailsPassword', TRUE)
-                                       ->assign('renderConnectDetailsHost', TRUE)
-                                       ->assign('renderConnectDetailsPort', TRUE)
-                                       ->assign('renderConnectDetailsDatabase', TRUE);
-                               break;
-                       case 'oci8':
-                               $this->view
-                                       ->assign('renderConnectDetailsUsername', TRUE)
-                                       ->assign('renderConnectDetailsPassword', TRUE)
-                                       ->assign('renderConnectDetailsHost', TRUE)
-                                       ->assign('renderConnectDetailsPort', TRUE)
-                                       ->assign('renderConnectDetailsDatabase', TRUE)
-                                       ->assign('renderConnectDetailsOracleSidConnect', TRUE);
-                               $type = isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg']['_DEFAULT']['config']['driverOptions']['connectSID'])
-                                       ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg']['_DEFAULT']['config']['driverOptions']['connectSID']
-                                       : '';
-                               if ($type === TRUE) {
-                                       $this->view->assign('oracleSidSelected', TRUE);
-                               }
-                               break;
-               }
-       }
-
-       /**
         * Render connect port and label
         *
-        * @return integer Configured or default port
+        * @return int Configured or default port
         */
        protected function getConfiguredOrDefaultPort() {
                $configuredPort = (int)$this->getConfiguredPort();
@@ -309,11 +277,12 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
        /**
         * Test connection with given credentials
         *
-        * @return boolean TRUE if connect was successful
+        * @return bool TRUE if connect was successful
         */
        protected function isConnectSuccessful() {
                /** @var $databaseConnection \TYPO3\CMS\Core\Database\DatabaseConnection */
-               $databaseConnection = $this->objectManager->get('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
+               $databaseConnection = $this->objectManager->get(\TYPO3\CMS\Core\Database\DatabaseConnection::class);
+               $databaseConnection->initialize();
 
                if ($this->isDbalEnabled()) {
                        // Set additional connect information based on dbal driver. postgres for example needs
@@ -323,12 +292,11 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
                        }
                }
 
-               $username = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['username']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['username'] : '';
-               $databaseConnection->setDatabaseUsername($username);
-               $password = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['password']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['password'] : '';
-               $databaseConnection->setDatabasePassword($password);
+               $databaseConnection->setDatabaseUsername($this->getConfiguredUsername());
+               $databaseConnection->setDatabasePassword($this->getConfiguredPassword());
                $databaseConnection->setDatabaseHost($this->getConfiguredHost());
                $databaseConnection->setDatabasePort($this->getConfiguredPort());
+               $databaseConnection->setDatabaseSocket($this->getConfiguredSocket());
 
                $result = FALSE;
                if (@$databaseConnection->sql_pconnect()) {
@@ -338,6 +306,164 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
        }
 
        /**
+        * Check LocalConfiguration.php for required database settings:
+        * - 'host' is mandatory and must not be empty
+        * - 'port' OR 'socket' is mandatory, but may be empty
+        *
+        * @return bool TRUE if host is set
+        */
+       protected function isHostConfigured() {
+               $hostConfigured = TRUE;
+               if (empty($GLOBALS['TYPO3_CONF_VARS']['DB']['host'])) {
+                       $hostConfigured = FALSE;
+               }
+               if (
+                       !isset($GLOBALS['TYPO3_CONF_VARS']['DB']['port'])
+                       && !isset($GLOBALS['TYPO3_CONF_VARS']['DB']['socket'])
+               ) {
+                       $hostConfigured = FALSE;
+               }
+               return $hostConfigured;
+       }
+
+       /**
+        * Check LocalConfiguration.php for required database settings:
+        * - 'host' is mandatory and must not be empty
+        * - 'port' OR 'socket' is mandatory, but may be empty
+        * - 'username' and 'password' are mandatory, but may be empty
+        *
+        * @return bool TRUE if required settings are present
+        */
+       protected function isConfigurationComplete() {
+               $configurationComplete = $this->isHostConfigured();
+               if (!isset($GLOBALS['TYPO3_CONF_VARS']['DB']['username'])) {
+                       $configurationComplete = FALSE;
+               }
+               if (!isset($GLOBALS['TYPO3_CONF_VARS']['DB']['password'])) {
+                       $configurationComplete = FALSE;
+               }
+               return $configurationComplete;
+       }
+
+       /**
+        * Write DB settings to LocalConfiguration.php, using default values.
+        * With the switch from mysql to mysqli in 6.1, some mandatory settings were
+        * added. This method tries to add those settings in case of an upgrade, and
+        * pre-configures settings in case of a "new" install process.
+        *
+        * There are two different connection types:
+        * - Unix domain socket. This may be available if mysql is running on localhost
+        * - TCP/IP connection to some mysql system somewhere.
+        *
+        * Unix domain socket connections are quicker than TCP/IP, so it is
+        * tested if a unix domain socket connection to localhost is successful. If not,
+        * a default configuration for TCP/IP is used.
+        *
+        * @return void
+        */
+       protected function useDefaultValuesForNotConfiguredOptions() {
+               $localConfigurationPathValuePairs = array();
+
+               $localConfigurationPathValuePairs['DB/host'] = $this->getConfiguredHost();
+
+               // If host is "local" either by upgrading or by first install, we try a socket
+               // connection first and use TCP/IP as fallback
+               if ($localConfigurationPathValuePairs['DB/host'] === 'localhost'
+                       || \TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP($localConfigurationPathValuePairs['DB/host'], '127.*.*.*')
+                       || strlen($localConfigurationPathValuePairs['DB/host']) === 0
+               ) {
+                       if ($this->isConnectionWithUnixDomainSocketPossible()) {
+                               $localConfigurationPathValuePairs['DB/host'] = 'localhost';
+                               $localConfigurationPathValuePairs['DB/socket'] = $this->getConfiguredSocket();
+                       } else {
+                               if (!\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($localConfigurationPathValuePairs['DB/host'], '127.')) {
+                                       $localConfigurationPathValuePairs['DB/host'] = '127.0.0.1';
+                               }
+                       }
+               }
+
+               if (!isset($localConfigurationPathValuePairs['DB/socket'])) {
+                       // Make sure a default port is set if not configured yet
+                       // This is independent from any host configuration
+                       $port = $this->getConfiguredPort();
+                       if ($port > 0) {
+                               $localConfigurationPathValuePairs['DB/port'] = $port;
+                       } else {
+                               $localConfigurationPathValuePairs['DB/port'] = $this->getConfiguredOrDefaultPort();
+                       }
+               }
+
+               /** @var \TYPO3\CMS\Core\Configuration\ConfigurationManager $configurationManager */
+               $configurationManager = $this->objectManager->get(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
+               $configurationManager->setLocalConfigurationValuesByPathValuePairs($localConfigurationPathValuePairs);
+       }
+
+       /**
+        * Test if a unix domain socket can be opened. This does not
+        * authenticate but only tests if a connect is successful.
+        *
+        * @return bool TRUE on success
+        */
+       protected function isConnectionWithUnixDomainSocketPossible() {
+               $result = FALSE;
+               // Use configured socket
+               $socket = $this->getConfiguredSocket();
+               if (!strlen($socket) > 0) {
+                       // If no configured socket, use default php socket
+                       $defaultSocket = ini_get('mysqli.default_socket');
+                       if (strlen($defaultSocket) > 0) {
+                               $socket = $defaultSocket;
+                       }
+               }
+               if (strlen($socket) > 0) {
+                       $socketOpenResult = @fsockopen('unix://' . $socket);
+                       if ($socketOpenResult) {
+                               fclose($socketOpenResult);
+                               $result = TRUE;
+                       }
+               }
+               return $result;
+       }
+
+       /**
+        * Render fields required for successful connect based on dbal driver selection.
+        * Hint: There is a code duplication in handle() and this method. This
+        * is done by intention to keep this code area easy to maintain and understand.
+        *
+        * @return void
+        */
+       protected function setDbalInputFieldsToRender() {
+               $driver = $this->getSelectedDbalDriver();
+               switch($driver) {
+                       case 'mssql':
+                       case 'odbc_mssql':
+                       case 'postgres':
+                               $this->view
+                                       ->assign('renderConnectDetailsUsername', TRUE)
+                                       ->assign('renderConnectDetailsPassword', TRUE)
+                                       ->assign('renderConnectDetailsHost', TRUE)
+                                       ->assign('renderConnectDetailsPort', TRUE)
+                                       ->assign('renderConnectDetailsDatabase', TRUE);
+                               break;
+                       case 'oci8':
+                               $this->view
+                                       ->assign('renderConnectDetailsUsername', TRUE)
+                                       ->assign('renderConnectDetailsPassword', TRUE)
+                                       ->assign('renderConnectDetailsHost', TRUE)
+                                       ->assign('renderConnectDetailsPort', TRUE)
+                                       ->assign('renderConnectDetailsDatabase', TRUE)
+                                       ->assign('renderConnectDetailsOracleSidConnect', TRUE);
+                               $type = isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg']['_DEFAULT']['config']['driverOptions']['connectSID'])
+                                       ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg']['_DEFAULT']['config']['driverOptions']['connectSID']
+                                       : '';
+                               if ($type === TRUE) {
+                                       $this->view->assign('oracleSidSelected', TRUE);
+                               }
+                               break;
+               }
+       }
+
+       /**
         * Returns a list of database drivers that are available on current server.
         *
         * @return array
@@ -428,14 +554,14 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
         * @return \TYPO3\CMS\Install\Status\StatusInterface
         */
        protected function executeLoadDbalExtension() {
-               if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('adodb')) {
-                       \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadExtension('adodb');
+               if (!ExtensionManagementUtility::isLoaded('adodb')) {
+                       ExtensionManagementUtility::loadExtension('adodb');
                }
-               if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('dbal')) {
-                       \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadExtension('dbal');
+               if (!ExtensionManagementUtility::isLoaded('dbal')) {
+                       ExtensionManagementUtility::loadExtension('dbal');
                }
                /** @var $errorStatus \TYPO3\CMS\Install\Status\WarningStatus */
-               $warningStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\WarningStatus');
+               $warningStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\WarningStatus::class);
                $warningStatus->setTitle('Loaded database abstraction layer');
                return $warningStatus;
        }
@@ -446,20 +572,40 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
         * @return \TYPO3\CMS\Install\Status\StatusInterface
         */
        protected function executeUnloadDbalExtension() {
-               if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('adodb')) {
-                       \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::unloadExtension('adodb');
+               if (ExtensionManagementUtility::isLoaded('adodb')) {
+                       ExtensionManagementUtility::unloadExtension('adodb');
                }
-               if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('dbal')) {
-                       \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::unloadExtension('dbal');
+               if (ExtensionManagementUtility::isLoaded('dbal')) {
+                       ExtensionManagementUtility::unloadExtension('dbal');
                }
                // @TODO: Remove configuration from TYPO3_CONF_VARS['EXTCONF']['dbal']
                /** @var $errorStatus \TYPO3\CMS\Install\Status\WarningStatus */
-               $warningStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\WarningStatus');
+               $warningStatus = $this->objectManager->get(\TYPO3\CMS\Install\Status\WarningStatus::class);
                $warningStatus->setTitle('Removed database abstraction layer');
                return $warningStatus;
        }
 
        /**
+        * Returns configured username, if set
+        *
+        * @return string
+        */
+       protected function getConfiguredUsername() {
+               $username = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['username']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['username'] : '';
+               return $username;
+       }
+
+       /**
+        * Returns configured password, if set
+        *
+        * @return string
+        */
+       protected function getConfiguredPassword() {
+               $password = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['password']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['password'] : '';
+               return $password;
+       }
+
+       /**
         * Returns configured host with port split off if given
         *
         * @return string
@@ -467,7 +613,7 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
        protected function getConfiguredHost() {
                $host = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['host']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['host'] : '';
                $port = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['port']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['port'] : '';
-               if (strlen($port) < 1 && strpos($host, ':') > 0) {
+               if (strlen($port) < 1 && substr_count($host, ':') === 1) {
                        list($host) = explode(':', $host);
                }
                return $host;
@@ -476,16 +622,25 @@ class DatabaseConnect extends Action\AbstractAction implements StepInterface {
        /**
         * Returns configured port. Gets port from host value if port is not yet set.
         *
-        * @return integer
+        * @return int
         */
        protected function getConfiguredPort() {
                $host = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['host']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['host'] : '';
                $port = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['port']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['port'] : '';
-               if (!strlen($port) > 0 && strpos($host, ':') > 0) {
+               if (strlen($port) === 0 && substr_count($host, ':') === 1) {
                        $hostPortArray = explode(':', $host);
                        $port = $hostPortArray[1];
                }
                return (int)$port;
        }
+
+       /**
+        * Returns configured socket, if set
+        *
+        * @return string|NULL
+        */
+       protected function getConfiguredSocket() {
+               $socket = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['socket']) ? $GLOBALS['TYPO3_CONF_VARS']['DB']['socket'] : '';
+               return $socket;
+       }
 }
-?>