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.
This commit is contained in:
Brion Vibber 2009-09-13 17:53:15 -07:00 committed by Brenda Wallace
parent cd650b090a
commit 4181c6f04a

View File

@ -181,6 +181,18 @@ $external_libraries=array(
'check_class'=>'Validate' '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() function main()
{ {
@ -238,8 +250,18 @@ function checkPrereqs()
$pass = false; $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; $pass = false;
} }
@ -340,6 +362,15 @@ E_O_T;
function showForm() 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 echo<<<E_O_T
</ul> </ul>
</dd> </dd>
@ -376,8 +407,7 @@ function showForm()
<li> <li>
<label for="dbtype">Type</label> <label for="dbtype">Type</label>
<input type="radio" name="dbtype" id="fancy-mysql" value="mysql" checked='checked' /> MySQL<br /> $dbRadios
<input type="radio" name="dbtype" id="dbtype-pgsql" value="pgsql" /> PostgreSQL<br />
<p class="form_guide">Database type</p> <p class="form_guide">Database type</p>
</li> </li>
@ -465,17 +495,9 @@ function handlePost()
return; return;
} }
// FIXME: use PEAR::DB or PDO instead of our own switch global $dbModules;
$db = call_user_func($dbModules[$dbtype]['installer'],
switch($dbtype) { $host, $database, $username, $password);
case 'mysql':
$db = mysql_db_installer($host, $database, $username, $password);
break;
case 'pgsql':
$db = pgsql_db_installer($host, $database, $username, $password);
break;
default:
}
if (!$db) { if (!$db) {
// database connection failed, do not move on to create config file. // database connection failed, do not move on to create config file.