Improve behaviour when multiple databases are disabled

This commit is contained in:
Frédéric Guillot 2014-04-15 18:31:59 -04:00
parent 56c03c16b0
commit 04d0e76d8a
2 changed files with 23 additions and 17 deletions

View File

@ -11,6 +11,7 @@ use PicoDb\Database;
Router\get_action('new-db', function() { Router\get_action('new-db', function() {
if (ENABLE_MULTIPLE_DB) { if (ENABLE_MULTIPLE_DB) {
Response\html(Template\layout('new_db', array( Response\html(Template\layout('new_db', array(
'errors' => array(), 'errors' => array(),
'values' => array(), 'values' => array(),
@ -25,6 +26,8 @@ Router\get_action('new-db', function() {
// Create a new database // Create a new database
Router\post_action('new-db', function() { Router\post_action('new-db', function() {
if (ENABLE_MULTIPLE_DB) {
$values = Request\values(); $values = Request\values();
list($valid, $errors) = Model\Database\validate($values); list($valid, $errors) = Model\Database\validate($values);
@ -46,6 +49,9 @@ Router\post_action('new-db', function() {
'menu' => 'config', 'menu' => 'config',
'title' => t('New database') 'title' => t('New database')
))); )));
}
Response\redirect('?action=config');
}); });
// Auto-update // Auto-update

View File

@ -18,7 +18,7 @@ function create($filename, $username, $password)
{ {
$filename = DATA_DIRECTORY.DIRECTORY_SEPARATOR.$filename; $filename = DATA_DIRECTORY.DIRECTORY_SEPARATOR.$filename;
if (! file_exists($filename)) { if (ENABLE_MULTIPLE_DB && ! file_exists($filename)) {
$db = new \PicoDb\Database(array( $db = new \PicoDb\Database(array(
'driver' => 'sqlite', 'driver' => 'sqlite',
@ -44,7 +44,7 @@ function select($filename = '')
{ {
static $current_filename = DB_FILENAME; static $current_filename = DB_FILENAME;
if ($filename !== '' && in_array($filename, get_all())) { if (ENABLE_MULTIPLE_DB && $filename !== '' && in_array($filename, get_all())) {
$current_filename = $filename; $current_filename = $filename;
$_SESSION['config'] = \Model\Config\get_all(); $_SESSION['config'] = \Model\Config\get_all();
} }