[TASK] Show not empty databases in install tool 68/24668/3
authorNicole Cordes <typo3@cordes.co>
Sun, 13 Oct 2013 01:22:44 +0000 (03:22 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Tue, 15 Oct 2013 12:57:19 +0000 (14:57 +0200)
This patch enables the visibility of all databases the user has access
to but disables the non empty ones from being chosen.

Resolves: #52585
Releases: 6.2
Change-Id: Ic8b527c5d256e46b99f79c35d236809ce015cbef
Reviewed-on: https://review.typo3.org/24668
Reviewed-by: Nicole Cordes
Tested-by: Nicole Cordes
Reviewed-by: Thorsten Kahler
Tested-by: Thorsten Kahler
Reviewed-by: Alexander Opitz
Tested-by: Alexander Opitz
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/install/Classes/Controller/Action/Step/DatabaseSelect.php
typo3/sysext/install/Resources/Private/Templates/Action/Step/DatabaseSelect.html

index 793ec21..8a7d469 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) {
@@ -74,12 +76,17 @@ class DatabaseSelect extends Action\AbstractAction implements StepInterface {
                                $result[] = $errorStatus;
                        }
                } elseif ($postValues['type'] === 'existing') {
-                       $localConfigurationPathValuePairs['DB/database'] = $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'];
+                       }
                }
 
                if (!empty($localConfigurationPathValuePairs)) {
-                       /** @var $configurationManager \TYPO3\CMS\Core\Configuration\ConfigurationManager */
-                       $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
                        $configurationManager->setLocalConfigurationValuesByPathValuePairs($localConfigurationPathValuePairs);
                }
 
@@ -140,17 +147,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;
                }
        }
 
index 1cdf38b..c20b44a 100644 (file)
                                                                        onfocus="document.getElementById('t3-install-form-db-select-type-existing').checked=true;"
                                                                >
                                                                        <option value="">Select database</option>
-                                                                       <f:for each="{databaseList}" as="database" iteration="databaseIterator">
-                                                                               <option value="{database}"{f:if(condition: databaseIterator.isFirst ,then: ' selected="selected"')}>{database}</option>
+                                                                       <f:for each="{databaseList}" as="database">
+                                                                               <f:if condition="{database.tables}">
+                                                                                       <f:then>
+                                                                                               <option value="{database.name}" disabled="disabled">{database.name} ({database.tables} Tables)</option>
+                                                                                       </f:then>
+                                                                                       <f:else>
+                                                                                               <option value="{database.name}">{database.name}</option>
+                                                                                       </f:else>
+                                                                               </f:if>
                                                                        </f:for>
                                                                </select>
                                                        </div>