Added 1st implementation of the installer hook
authorXavier Perseguers <typo3@perseguers.ch>
Sun, 25 Apr 2010 17:32:19 +0000 (17:32 +0000)
committerXavier Perseguers <typo3@perseguers.ch>
Sun, 25 Apr 2010 17:32:19 +0000 (17:32 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/dbal/trunk@32566 735d13b6-9817-0410-8766-e36946ffe9aa

typo3/sysext/dbal/class.user_tx_install_hook.php [new file with mode: 0644]
typo3/sysext/dbal/ext_localconf.php
typo3/sysext/dbal/res/Templates/install.html [new file with mode: 0644]

diff --git a/typo3/sysext/dbal/class.user_tx_install_hook.php b/typo3/sysext/dbal/class.user_tx_install_hook.php
new file mode 100644 (file)
index 0000000..d79f5e5
--- /dev/null
@@ -0,0 +1,172 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2010 Xavier Perseguers <typo3@perseguers.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.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*  A copy is found in the textfile GPL.txt and important notices to the license
+*  from the author is found in LICENSE.txt distributed with these scripts.
+*
+*
+*  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.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Hook for TYPO3 installer.
+ *
+ * $Id$
+ *
+ * @author Xavier Perseguers <typo3@perseguers.ch>
+ *
+ * @package TYPO3
+ * @subpackage dbal
+ */
+class user_tx_install_hook {
+
+       protected $templateFilePath = 'res/Templates/';
+
+       /**
+        * Hooks into Installer to let a non-MySQL database to be configured.
+        * 
+        * @param array $markers
+        * @param integer $step
+        * @param tx_install $instObj
+        * @return void
+        */
+       public function execute(array &$markers, $step, tx_install $instObj) {
+               switch ($step) {
+                       case 2:
+                               $this->createConnectionForm(t3lib_div::_GET('driver'), $markers, $instObj);
+                               break;
+               }
+       }
+
+       /**
+        * Creates a specialized form to configure the DBMS connection.
+        * 
+        * @param string $driver
+        * @param array $markers
+        * @param tx_install $instObj
+        * @return void
+        */
+       protected function createConnectionForm($driver, array &$markers, tx_install $instObj) {
+                       // Get the template file
+               $templateFile = @file_get_contents(
+                       t3lib_extMgm::extPath('dbal') . $this->templateFilePath . 'install.html'
+               );
+                       // Get the template part from the file
+               $template = t3lib_parsehtml::getSubpart(
+                       $templateFile, '###TEMPLATE###'
+               );
+
+                       // Get the subpart for the connection form
+               $formSubPart = t3lib_parsehtml::getSubpart(
+                       $template, '###CONNECTION_FORM###'
+               );
+               $driverTemplate = t3lib_parsehtml::getSubpart(
+                       $formSubPart, '###DATABASE_DRIVER###'
+               );
+               $driverSubPart = $instObj->prepareDatabaseDrivers($driverTemplate);
+               $formSubPart = t3lib_parsehtml::substituteSubpart(
+                       $formSubPart,
+                       '###DATABASE_DRIVER###',
+                       $driverSubPart
+               );
+
+                       // Get the subpart related to selected database driver
+               $driverOptionsSubPart = t3lib_parsehtml::getSubpart(
+                       $template, '###DRIVER_' . t3lib_div::strtoupper($driver) . '###'
+               );
+
+                       // Define driver-specific markers
+               $driverMarkers = array();
+               switch ($driver) {
+                       case 'mssql':
+                               $driverMarkers = array(
+                                       'labelUsername' => 'Username',
+                                       'username' => TYPO3_db_username,
+                                       'labelPassword' => 'Password',
+                                       'password' => TYPO3_db_password,
+                                       'labelHost' => 'Host',
+                                       'host' => TYPO3_db_host ? TYPO3_db_host : 'windows',
+                                       'labelDatabase' => 'Database',
+                                       'database' => TYPO3_db,  
+                               );
+                               break;
+                       case 'odbc_mssql':
+                               $driverMarkers = array(
+                                       'labelUsername' => 'Username',
+                                       'username' => TYPO3_db_username,
+                                       'labelPassword' => 'Password',
+                                       'password' => TYPO3_db_password,
+                                       'labelHost' => 'Host',
+                                       'host' => TYPO3_db_host ? TYPO3_db_host : 'windows',
+                                       'database' => 'dummy_string',
+                               );
+                               break;
+                       case 'oci8':
+                               $driverMarkers = array(
+                                       'labelUsername' => 'Username',
+                                       'username' => TYPO3_db_username,
+                                       'labelPassword' => 'Password',
+                                       'password' => TYPO3_db_password,
+                                       'labelHost' => 'Host',
+                                       'host' => TYPO3_db_host ? TYPO3_db_host : 'localhost',
+                                       'labelType' => 'Type',
+                                       'labelSID' => 'SID',
+                                       'labelServiceName' => 'Service Name',
+                                       'labelDatabase' => 'Name',
+                                       'database' => TYPO3_db,  
+                               );
+                               break;
+                       case 'postgres':
+                               $driverMarkers = array(
+                                       'labelUsername' => 'Username',
+                                       'username' => TYPO3_db_username,
+                                       'labelPassword' => 'Password',
+                                       'password' => TYPO3_db_password,
+                                       'labelHost' => 'Host',
+                                       'host' => TYPO3_db_host ? TYPO3_db_host : 'localhost',
+                               );
+                               break;
+               }
+
+                       // Add header marker for main template
+               $markers['header'] = 'Connect to your database host';
+                       // Define the markers content for the subpart
+               $subPartMarkers = array(
+                       'step' => $instObj->step + 1,
+                       'action' => htmlspecialchars($instObj->action),
+                       'encryptionKey' => $instObj->createEncryptionKey(),
+                       'branch' => TYPO3_branch,
+                       'driver_options' => $driverOptionsSubPart,
+                       'continue' => 'Continue'
+               );
+               $subPartMarkers = array_merge($subPartMarkers, $driverMarkers);
+
+                       // Add step marker for main template
+               $markers['step'] = t3lib_parsehtml::substituteMarkerArray(
+                       $formSubPart,
+                       $subPartMarkers,
+                       '###|###',
+                       1,
+                       1
+               );
+       }
+}
+
+?>
\ No newline at end of file
index 8ee482c..f253dd5 100644 (file)
@@ -7,4 +7,6 @@ $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_db.php'] = t3lib_extMg
 $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_sqlparser.php'] = t3lib_extMgm::extPath('dbal') . 'class.ux_t3lib_sqlparser.php';
 $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.db_list_extra.inc'] = t3lib_extMgm::extPath('dbal') . 'class.ux_db_list_extra.php';
 
+// Register a hook for the installer
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['stepOutput'][] = 'EXT:dbal/class.user_tx_install_hook.php:user_tx_install_hook';
 ?>
diff --git a/typo3/sysext/dbal/res/Templates/install.html b/typo3/sysext/dbal/res/Templates/install.html
new file mode 100644 (file)
index 0000000..e0f95bb
--- /dev/null
@@ -0,0 +1,143 @@
+?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html
+     PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+       <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+       <title>Template: Step Output</title>
+</head>
+<body>
+<!-- ###TEMPLATE### begin -->
+
+<!-- ###CONNECTION_FORM### begin -->
+<script type="text/javascript" src="../contrib/prototype/prototype.js"></script>
+<script type="text/javascript" src="../sysext/install/Resources/Public/Javascript/install.js"></script>
+
+<form method="post" action="###ACTION###">
+       <fieldset class="t3-install-form-label-width-7">
+               <ol>
+                       <li class="t3-install-hidden">
+                               <input type="hidden" value="###STEP###" name="step" />
+                               <input type="hidden" value="###ENCRYPTIONKEY###" name="TYPO3_INSTALL[localconf.php][encryptionKey]" />
+                               <input type="hidden" value="###BRANCH###" name="TYPO3_INSTALL[localconf.php][compat_version]" />
+                       </li>
+                       <!-- ###DATABASE_DRIVER### begin -->
+                       <li>
+                               <label>###LABELDRIVER###</label>
+                               <select name="TYPO3_INSTALL[localconf.php][typo_db_driver]">
+                                       <!-- ###ABSTRACTION_LAYER### begin -->
+                                       <optgroup label="###LABELABSTRACTIONLAYER###">
+                                               <!-- ###VENDOR### begin -->
+                                               <option value="###DRIVER###"###ATTRIBUTES###>###LABELVENDOR###</option>
+                                               <!-- ###VENDOR### end -->
+                                       </optgroup>
+                                       <!-- ###ABSTRACTION_LAYER### end -->
+                               </select>
+                       </li>
+                       <!-- ###DATABASE_DRIVER### end -->
+
+                       ###DRIVER_OPTIONS###
+               </ol>
+       </fieldset>
+       <fieldset class="t3-install-form-submit">
+               <ol>
+                       <li>
+                               <button type="submit">###CONTINUE###<span class="t3-install-form-button-icon-positive">&nbsp;</span></button>
+                       </li>
+               </ol>
+       </fieldset>
+</form>
+<!-- ###CONNECTION_FORM### end -->
+
+
+
+
+<!-- ###DRIVER_MSSQL### begin -->
+<li>
+       <label for="t3-install-form-username">###LABELUSERNAME###</label>
+       <input id="t3-install-form-username" class="t3-install-form-input-text" type="text" value="###USERNAME###" name="TYPO3_INSTALL[localconf.php][typo_db_username]" />
+</li>
+<li>
+       <label for="t3-install-form-password">###LABELPASSWORD###</label>
+       <input id="t3-install-form-password" class="t3-install-form-input-text" type="password" value="###PASSWORD###" name="TYPO3_INSTALL[localconf.php][typo_db_password]" />
+</li>
+<li>
+       <label for="t3-install-form-host">###LABELHOST###</label>
+       <input id="t3-install-form-host" class="t3-install-form-input-text" type="text" value="###HOST###" name="TYPO3_INSTALL[localconf.php][typo_db_host]" />
+</li>
+<li>
+       <label for="t3-install-form-database">###LABELDATABASE###</label>
+       <input id="t3-install-form-database" class="t3-install-form-input-text" type="text" value="###DATABASE###" name="TYPO3_INSTALL[localconf.php][typo_db]" />
+</li>
+<!-- ###DRIVER_MSSQL### end -->
+
+
+
+
+<!-- ###DRIVER_ODBC_MSSQL### begin -->
+<li>
+       <label for="t3-install-form-username">###LABELUSERNAME###</label>
+       <input id="t3-install-form-username" class="t3-install-form-input-text" type="text" value="###USERNAME###" name="TYPO3_INSTALL[localconf.php][typo_db_username]" />
+</li>
+<li>
+       <label for="t3-install-form-password">###LABELPASSWORD###</label>
+       <input id="t3-install-form-password" class="t3-install-form-input-text" type="password" value="###PASSWORD###" name="TYPO3_INSTALL[localconf.php][typo_db_password]" />
+</li>
+<li>
+       <label for="t3-install-form-host">###LABELHOST###</label>
+       <input id="t3-install-form-host" class="t3-install-form-input-text" type="text" value="###HOST###" name="TYPO3_INSTALL[localconf.php][typo_db_host]" />
+</li>
+<input type="hidden" value="###DATABASE###" name="TYPO3_INSTALL[localconf.php][typo_db]" />
+<!-- ###DRIVER_ODBC_MSSQL### end -->
+
+
+
+
+<!-- ###DRIVER_OCI8### begin -->
+<li>
+       <label for="t3-install-form-username">###LABELUSERNAME###</label>
+       <input id="t3-install-form-username" class="t3-install-form-input-text" type="text" value="###USERNAME###" name="TYPO3_INSTALL[localconf.php][typo_db_username]" />
+</li>
+<li>
+       <label for="t3-install-form-password">###LABELPASSWORD###</label>
+       <input id="t3-install-form-password" class="t3-install-form-input-text" type="password" value="###PASSWORD###" name="TYPO3_INSTALL[localconf.php][typo_db_password]" />
+</li>
+<li>
+       <label for="t3-install-form-host">###LABELHOST###</label>
+       <input id="t3-install-form-host" class="t3-install-form-input-text" type="text" value="###HOST###" name="TYPO3_INSTALL[localconf.php][typo_db_host]" />
+</li>
+<li>
+       <label for="t3-install-form-type">###LABELTYPE###</label>
+       <select id="t3-install-form-type" name="TYPO3_INSTALL[localconf.php][typo_db_type]">
+               <option value="sid">###LABELSID###</option>
+               <option value="servicename">###LABELSERVICENAME###</option>
+       </select>
+</li>
+<li>
+       <label for="t3-install-form-database">###LABELDATABASE###</label>
+       <input id="t3-install-form-database" class="t3-install-form-input-text" type="text" value="###DATABASE###" name="TYPO3_INSTALL[localconf.php][typo_db]" />
+</li>
+<!-- ###DRIVER_OCI8### end -->
+
+
+
+
+<!-- ###DRIVER_POSTGRES### begin -->
+<li>
+       <label for="t3-install-form-username">###LABELUSERNAME###</label>
+       <input id="t3-install-form-username" class="t3-install-form-input-text" type="text" value="###USERNAME###" name="TYPO3_INSTALL[localconf.php][typo_db_username]" />
+</li>
+<li>
+       <label for="t3-install-form-password">###LABELPASSWORD###</label>
+       <input id="t3-install-form-password" class="t3-install-form-input-text" type="password" value="###PASSWORD###" name="TYPO3_INSTALL[localconf.php][typo_db_password]" />
+</li>
+<li>
+       <label for="t3-install-form-host">###LABELHOST###</label>
+       <input id="t3-install-form-host" class="t3-install-form-input-text" type="text" value="###HOST###" name="TYPO3_INSTALL[localconf.php][typo_db_host]" />
+</li>
+<!-- ###DRIVER_POSTGRES### end -->
+
+<!-- ###TEMPLATE### end -->
+</body>
+</html>
\ No newline at end of file