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() {
if (ENABLE_MULTIPLE_DB) {
Response\html(Template\layout('new_db', array(
'errors' => array(),
'values' => array(),
@ -25,27 +26,32 @@ Router\get_action('new-db', function() {
// Create a new database
Router\post_action('new-db', function() {
$values = Request\values();
list($valid, $errors) = Model\Database\validate($values);
if (ENABLE_MULTIPLE_DB) {
if ($valid) {
$values = Request\values();
list($valid, $errors) = Model\Database\validate($values);
if (Model\Database\create(strtolower($values['name']).'.sqlite', $values['username'], $values['password'])) {
Session\flash(t('Database created successfully.'));
}
else {
Session\flash_error(t('Unable to create the new database.'));
if ($valid) {
if (Model\Database\create(strtolower($values['name']).'.sqlite', $values['username'], $values['password'])) {
Session\flash(t('Database created successfully.'));
}
else {
Session\flash_error(t('Unable to create the new database.'));
}
Response\redirect('?action=config');
}
Response\redirect('?action=config');
Response\html(Template\layout('new_db', array(
'errors' => $errors,
'values' => $values,
'menu' => 'config',
'title' => t('New database')
)));
}
Response\html(Template\layout('new_db', array(
'errors' => $errors,
'values' => $values,
'menu' => 'config',
'title' => t('New database')
)));
Response\redirect('?action=config');
});
// Auto-update

View File

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