[BUGFIX] Install Tool fatal with Oracle database
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / Action / Step / DatabaseSelect.php
index da4213c..26b6e34 100644 (file)
@@ -48,6 +48,8 @@ class DatabaseSelect extends Action\AbstractAction implements StepInterface {
                $this->initializeDatabaseConnection();
                $postValues = $this->postValues['values'];
                $localConfigurationPathValuePairs = array();
+               /** @var $configurationManager \TYPO3\CMS\Core\Configuration\ConfigurationManager */
+               $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
                if ($postValues['type'] === 'new') {
                        $newDatabaseName = $postValues['new'];
                        if (strlen($newDatabaseName) <= 50) {
@@ -61,7 +63,7 @@ class DatabaseSelect extends Action\AbstractAction implements StepInterface {
                                        $errorStatus->setMessage(
                                                'Database with name ' . $newDatabaseName . ' could not be created.' .
                                                ' Either your database name contains special chars (only alphanumeric characters are allowed)' .
-                                               ' or your database user probably has no sufficient permissions to create it.' .
+                                               ' or your database user probably does not have sufficient permissions to create it.' .
                                                ' Please choose an existing (empty) database or contact administration.'
                                        );
                                        $result[] = $errorStatus;
@@ -73,13 +75,24 @@ class DatabaseSelect extends Action\AbstractAction implements StepInterface {
                                $errorStatus->setMessage('Given database name must be shorter than fifty characters.');
                                $result[] = $errorStatus;
                        }
-               } elseif ($postValues['type'] === 'existing') {
-                       $localConfigurationPathValuePairs['DB/database'] = $postValues['existing'];
+               } elseif ($postValues['type'] === 'existing' && !empty($postValues['existing'])) {
+                       // Only store database information when it's empty
+                       $this->databaseConnection->setDatabaseName($postValues['existing']);
+                       $this->databaseConnection->sql_select_db();
+                       $existingTables = $this->databaseConnection->admin_get_tables();
+                       $isInitialInstallation = $configurationManager->getConfigurationValueByPath('SYS/isInitialInstallationInProgress');
+                       if (!$isInitialInstallation || count($existingTables) === 0) {
+                               $localConfigurationPathValuePairs['DB/database'] = $postValues['existing'];
+                       }
+               } else {
+                       /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
+                       $errorStatus = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
+                       $errorStatus->setTitle('No Database selected');
+                       $errorStatus->setMessage('You have to select a database.');
+                       $result[] = $errorStatus;
                }
 
                if (!empty($localConfigurationPathValuePairs)) {
-                       /** @var $configurationManager \TYPO3\CMS\Core\Configuration\ConfigurationManager */
-                       $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
                        $configurationManager->setLocalConfigurationValuesByPathValuePairs($localConfigurationPathValuePairs);
                }
 
@@ -114,32 +127,45 @@ class DatabaseSelect extends Action\AbstractAction implements StepInterface {
         * @return string
         */
        public function handle() {
-               $this->initialize();
-               $this->view->assign('databaseList', $this->getDatabaseList());
+               $this->initializeHandle();
+               /** @var $configurationManager \TYPO3\CMS\Core\Configuration\ConfigurationManager */
+               $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
+               $isInitialInstallationInProgress = $configurationManager->getConfigurationValueByPath('SYS/isInitialInstallationInProgress');
+               $this->view->assign('databaseList', $this->getDatabaseList($isInitialInstallationInProgress));
+               $this->view->assign('isInitialInstallationInProgress', $isInitialInstallationInProgress);
                return $this->view->render();
        }
 
        /**
         * Returns list of available databases (with access-check based on username/password)
         *
+        * @param boolean $initialInstallation TRUE if first installation is in progress, FALSE if upgrading or usual access
         * @return array List of available databases
         */
-       protected function getDatabaseList() {
+       protected function getDatabaseList($initialInstallation) {
                $this->initializeDatabaseConnection();
                $databaseArray = $this->databaseConnection->admin_get_dbs();
                // Remove mysql organizational tables from database list
                $reservedDatabaseNames = array('mysql', 'information_schema', 'performance_schema');
                $allPossibleDatabases = array_diff($databaseArray, $reservedDatabaseNames);
-               $databasesWithoutTables = array();
-               foreach ($allPossibleDatabases as $database) {
-                       $this->databaseConnection->setDatabaseName($database);
-                       $this->databaseConnection->sql_select_db();
-                       $existingTables = $this->databaseConnection->admin_get_tables();
-                       if (count($existingTables) === 0) {
-                               $databasesWithoutTables[] = $database;
+
+               // If we are upgrading we show *all* databases the user has access to
+               if ($initialInstallation === FALSE) {
+                       return $allPossibleDatabases;
+               } else {
+                       // In first installation we show all databases but disable not empty ones (with tables)
+                       $databases = array();
+                       foreach ($allPossibleDatabases as $database) {
+                               $this->databaseConnection->setDatabaseName($database);
+                               $this->databaseConnection->sql_select_db();
+                               $existingTables = $this->databaseConnection->admin_get_tables();
+                               $databases[] = array(
+                                       'name' => $database,
+                                       'tables' => count($existingTables),
+                               );
                        }
+                       return $databases;
                }
-               return $databasesWithoutTables;
        }
 
        /**
@@ -153,7 +179,7 @@ class DatabaseSelect extends Action\AbstractAction implements StepInterface {
                $this->databaseConnection->setDatabasePassword($GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
                $this->databaseConnection->setDatabaseHost($GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
                $this->databaseConnection->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['port']);
+               $this->databaseConnection->setDatabaseSocket($GLOBALS['TYPO3_CONF_VARS']['DB']['socket']);
                $this->databaseConnection->sql_pconnect();
        }
 }
-?>
\ No newline at end of file