[FEATURE] Install tool database select during upgrading 29/23329/5
authorMichiel Roos <michiel@maxserv.nl>
Mon, 26 Aug 2013 14:59:13 +0000 (16:59 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 26 Aug 2013 20:05:33 +0000 (22:05 +0200)
- Detect if SYS/isInitialInstallationInProgress is set
- If set: Show form for creating or selecting empty db
- If not set: Show all databases the user has access to

Change-Id: Ifaa1678f8ab1eaacec944e6dddf7d23babb804cf
Resolves: #51357
Releases: 6.2
Reviewed-on: https://review.typo3.org/23329
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
Reviewed-by: Alexander Böhm
Tested-by: Alexander Böhm
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/install/Classes/Controller/Action/Step/DatabaseSelect.php
typo3/sysext/install/Resources/Private/Templates/Action/Step/DatabaseSelect.html

index 3a76d8b..7220b5c 100644 (file)
@@ -115,31 +115,43 @@ class DatabaseSelect extends Action\AbstractAction implements StepInterface {
         */
        public function handle() {
                $this->initialize();
-               $this->view->assign('databaseList', $this->getDatabaseList());
+               /** @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 only show empty databases (no tables)
+                       $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;
+                               }
                        }
+                       return $databasesWithoutTables;
                }
-               return $databasesWithoutTables;
        }
 
        /**
index 97ffe79..cc3a4f3 100644 (file)
@@ -5,48 +5,86 @@
 <f:section name="Content">
        <h3>Select database</h3>
 
-       You have two options:
+       <f:if condition="{isInitialInstallationInProgress}">
+               <f:then>
+                       You have two options:
+               </f:then>
+       </f:if>
 
        <form method="post" id="stepInstaller-databaseSelect">
                <f:render partial="Action/Common/HiddenFormFields" arguments="{_all}" />
                <input type="hidden" value="execute" name="install[set]" />
 
                <fieldset>
-                       <ul>
-                               <li>
-                                       <input
-                                               id="t3-install-form-db-select-type-new"
-                                               type="radio"
-                                               name="install[values][type]"
-                                               value="new"
-                                               checked="checked"
-                                               class="radio"
-                                       />
-                                       <div>
-                                               <label for="t3-install-step-database-new">Create a new database (recommended):</label>
-                                               <p>Enter a name for your TYPO3 database.</p>
-                                               <input
-                                                       id="t3-install-step-database-new"
-                                                       class="t3-install-form-input-text"
-                                                       type="text"
-                                                       name="install[values][new]"
-                                                       checked="checked"
-                                                       onfocus="document.getElementById('t3-install-form-db-select-type-new').checked=true;"
-                                               />
-                                       </div>
-                               </li>
 
-                               <li>
+                       <f:if condition="{isInitialInstallationInProgress}">
+
+                               <f:then>
+                                       <f:comment>
+                                               First installation
+                                       </f:comment>
+                                       <ul>
+                                               <li>
+                                                       <input
+                                                               id="t3-install-form-db-select-type-new"
+                                                               type="radio"
+                                                               name="install[values][type]"
+                                                               value="new"
+                                                               checked="checked"
+                                                               class="radio"
+                                                       />
+                                                       <div>
+                                                               <label for="t3-install-step-database-new">Create a new database (recommended):</label>
+                                                               <p>Enter a name for your TYPO3 database.</p>
+                                                               <input
+                                                                       id="t3-install-step-database-new"
+                                                                       class="t3-install-form-input-text"
+                                                                       type="text"
+                                                                       name="install[values][new]"
+                                                                       checked="checked"
+                                                                       onfocus="document.getElementById('t3-install-form-db-select-type-new').checked=true;"
+                                                               />
+                                                       </div>
+                                               </li>
+                                               <li>
+                                                       <input
+                                                               id="t3-install-form-db-select-type-existing"
+                                                               type="radio"
+                                                               name="install[values][type]"
+                                                               value="existing"
+                                                               class="radio"
+                                                       />
+                                                       <div>
+                                                               <label for="t3-install-step-database-existing">Select an EMPTY existing database:</label>
+                                                               <p>Any tables used by TYPO3 will be overwritten.</p>
+                                                               <select
+                                                                       id="t3-install-step-database-existing"
+                                                                       name="install[values][existing]"
+                                                                       onfocus="document.getElementById('t3-install-form-db-select-type-existing').checked=true;"
+                                                               >
+                                                                       <option value="">Select database</option>
+                                                                       <f:for each="{databaseList}" as="database">
+                                                                               <option value="{database}">{database}</option>
+                                                                       </f:for>
+                                                               </select>
+                                                       </div>
+                                               </li>
+                                       </ul>
+                               </f:then>
+
+                               <f:else>
+                                       <f:comment>
+                                               Upgrading
+                                       </f:comment>
                                        <input
                                                id="t3-install-form-db-select-type-existing"
-                                               type="radio"
+                                               type="hidden"
                                                name="install[values][type]"
                                                value="existing"
-                                               class="radio"
                                        />
                                        <div>
-                                               <label for="t3-install-step-database-existing">Select an EMPTY existing database:</label>
-                                               <p>Any tables used by TYPO3 will be overwritten.</p>
+                                               <label for="t3-install-step-database-existing">Select an existing database:</label>
+                                               <p>The database will not be altered in any way.</p>
                                                <select
                                                        id="t3-install-step-database-existing"
                                                        name="install[values][existing]"
                                                        </f:for>
                                                </select>
                                        </div>
-                               </li>
-                       </ul>
+                               </f:else>
+
+                       </f:if>
+
                </fieldset>
 
                <button type="submit">