summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2009-09-13 17:53:15 -0700
committerBrenda Wallace <shiny@cpan.org>2009-09-14 18:06:48 +1200
commit4181c6f04ad6a2321b2957d8784abc7dfef5779f (patch)
tree22bddba2920033994253a7db6843c088b2f4a044
parentcd650b090a339673f2cc7797c8cb9b0eb0196f82 (diff)
bug 1814: installer now only offers DB types which are available.
Abstracted a couple of hardcoded lists of mysql/pgsql checks and radio button creation to use a nice little array of names, installer funcs, and modules to check. Only those DB types whose modules are present will be presented in the installer; if all are missing, we throw an error and list out all the possibilities we were looking for.
-rw-r--r--install.php52
1 files changed, 37 insertions, 15 deletions
diff --git a/install.php b/install.php
index e828fa814..092172d35 100644
--- a/install.php
+++ b/install.php
@@ -181,6 +181,18 @@ $external_libraries=array(
'check_class'=>'Validate'
)
);
+$dbModules = array(
+ 'mysql' => array(
+ 'name' => 'MySQL',
+ 'check_module' => 'mysql', // mysqli?
+ 'installer' => 'mysql_db_installer',
+ ),
+ 'pgsql' => array(
+ 'name' => 'PostgreSQL',
+ 'check_module' => 'pgsql',
+ 'installer' => 'pgsql_db_installer',
+ ),
+);
function main()
{
@@ -238,8 +250,18 @@ function checkPrereqs()
$pass = false;
}
}
- if (!checkExtension('pgsql') && !checkExtension('mysql')) {
- ?><p class="error">Cannot find mysql or pgsql extension. You need one or the other: <code><?php echo $req; ?></code></p><?php
+
+ // Make sure we have at least one database module available
+ global $dbModules;
+ $missingExtensions = array();
+ foreach ($dbModules as $type => $info) {
+ if (!checkExtension($info['check_module'])) {
+ $missingExtensions[] = $info['check_module'];
+ }
+ }
+ if (count($missingExtensions) == count($dbModules)) {
+ $req = implode(', ', $missingExtensions);
+ ?><p class="error">Cannot find database support. You need at least one of these PHP extensions installed: <code><?php echo $req; ?></code></p><?php
$pass = false;
}
@@ -340,6 +362,15 @@ E_O_T;
function showForm()
{
+ global $dbModules;
+ $dbRadios = '';
+ $checked = 'checked="checked" '; // Check the first one which exists
+ foreach ($dbModules as $type => $info) {
+ if (checkExtension($info['check_module'])) {
+ $dbRadios .= "<input type=\"radio\" name=\"dbtype\" id=\"dbtype-$type\" value=\"$type\" $checked/> $info[name]<br />\n";
+ $checked = '';
+ }
+ }
echo<<<E_O_T
</ul>
</dd>
@@ -376,8 +407,7 @@ function showForm()
<li>
<label for="dbtype">Type</label>
- <input type="radio" name="dbtype" id="fancy-mysql" value="mysql" checked='checked' /> MySQL<br />
- <input type="radio" name="dbtype" id="dbtype-pgsql" value="pgsql" /> PostgreSQL<br />
+ $dbRadios
<p class="form_guide">Database type</p>
</li>
@@ -465,17 +495,9 @@ function handlePost()
return;
}
- // FIXME: use PEAR::DB or PDO instead of our own switch
-
- switch($dbtype) {
- case 'mysql':
- $db = mysql_db_installer($host, $database, $username, $password);
- break;
- case 'pgsql':
- $db = pgsql_db_installer($host, $database, $username, $password);
- break;
- default:
- }
+ global $dbModules;
+ $db = call_user_func($dbModules[$dbtype]['installer'],
+ $host, $database, $username, $password);
if (!$db) {
// database connection failed, do not move on to create config file.