[BUGFIX] Install Tool fatal with Oracle database
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / Action / Step / DatabaseSelect.php
index 7220b5c..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,7 +127,7 @@ class DatabaseSelect extends Action\AbstractAction implements StepInterface {
         * @return string
         */
        public function handle() {
-               $this->initialize();
+               $this->initializeHandle();
                /** @var $configurationManager \TYPO3\CMS\Core\Configuration\ConfigurationManager */
                $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
                $isInitialInstallationInProgress = $configurationManager->getConfigurationValueByPath('SYS/isInitialInstallationInProgress');
@@ -140,17 +153,18 @@ class DatabaseSelect extends Action\AbstractAction implements StepInterface {
                if ($initialInstallation === FALSE) {
                        return $allPossibleDatabases;
                } else {
-                       // In first installation we only show empty databases (no tables)
-                       $databasesWithoutTables = array();
+                       // 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();
-                               if (count($existingTables) === 0) {
-                                       $databasesWithoutTables[] = $database;
-                               }
+                               $databases[] = array(
+                                       'name' => $database,
+                                       'tables' => count($existingTables),
+                               );
                        }
-                       return $databasesWithoutTables;
+                       return $databases;
                }
        }
 
@@ -169,4 +183,3 @@ class DatabaseSelect extends Action\AbstractAction implements StepInterface {
                $this->databaseConnection->sql_pconnect();
        }
 }
-?>
\ No newline at end of file