summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Arthur <paul.arthur@flowerysong.com>2013-05-28 13:04:38 -0400
committerPaul Arthur <paul.arthur@flowerysong.com>2013-05-28 13:09:58 -0400
commit94d635d37401de0c747bd34030e08c738dfe0d68 (patch)
tree176f89427b3027d3811bd0d32aa8722b78d8df70 /lib
parentdf253855f7dad20a338e221ab6aff2725df358e3 (diff)
downloadampache-94d635d37401de0c747bd34030e08c738dfe0d68.tar.gz
ampache-94d635d37401de0c747bd34030e08c738dfe0d68.tar.bz2
ampache-94d635d37401de0c747bd34030e08c738dfe0d68.zip
Clean up the logic in install_insert_db
Check the things in an order that makes sense and minimise duplication.
Diffstat (limited to 'lib')
-rw-r--r--lib/install.lib.php33
1 files changed, 15 insertions, 18 deletions
diff --git a/lib/install.lib.php b/lib/install.lib.php
index dfaba46e..8c4d2769 100644
--- a/lib/install.lib.php
+++ b/lib/install.lib.php
@@ -126,30 +126,27 @@ function install_insert_db($db_user = null, $db_pass = null, $overwrite = false)
}
$db_exists = Dba::read('SHOW TABLES');
+ $create_db = true;
- if ($db_exists && $_POST['existing_db']) {
- // Rien a faire, we've got the db just blow through
- }
- elseif ($db_exists && !$overwrite) {
- Error::add('general', T_('Error: Database Already exists and Overwrite not checked'));
- return false;
- }
- elseif (!$db_exists) {
- $sql = 'CREATE DATABASE `' . $database . '`';
- if (!Dba::write($sql)) {
- Error::add('general',sprintf(T_('Error: Unable to create database: %s'), Dba::error()));
+ if ($db_exists) {
+ if ($_POST['existing_db']) {
+ $create_db = false;
+ }
+ else if ($overwrite) {
+ Dba::write('DROP DATABASE `' . $database . '`');
+ }
+ else {
+ Error::add('general', T_('Error: Database already exists and overwrite not checked'));
return false;
}
- } // if db can't be selected
- else {
- $sql = 'DROP DATABASE `' . $database . '`';
- Dba::write($sql);
- $sql = 'CREATE DATABASE `' . $database . '`';
- if (!Dba::write($sql)) {
+ }
+
+ if ($create_db) {
+ if (!Dba::write('CREATE DATABASE `' . $database . '`')) {
Error::add('general', sprintf(T_('Error: Unable to create database: %s'), Dba::error()));
return false;
}
- } // end if selected and overwrite
+ }
Dba::disconnect();