Improve behaviour when multiple databases are disabled
This commit is contained in:
parent
56c03c16b0
commit
04d0e76d8a
@ -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,27 +26,32 @@ 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() {
|
||||||
|
|
||||||
$values = Request\values();
|
if (ENABLE_MULTIPLE_DB) {
|
||||||
list($valid, $errors) = Model\Database\validate($values);
|
|
||||||
|
|
||||||
if ($valid) {
|
$values = Request\values();
|
||||||
|
list($valid, $errors) = Model\Database\validate($values);
|
||||||
|
|
||||||
if (Model\Database\create(strtolower($values['name']).'.sqlite', $values['username'], $values['password'])) {
|
if ($valid) {
|
||||||
Session\flash(t('Database created successfully.'));
|
|
||||||
}
|
if (Model\Database\create(strtolower($values['name']).'.sqlite', $values['username'], $values['password'])) {
|
||||||
else {
|
Session\flash(t('Database created successfully.'));
|
||||||
Session\flash_error(t('Unable to create the new database.'));
|
}
|
||||||
|
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(
|
Response\redirect('?action=config');
|
||||||
'errors' => $errors,
|
|
||||||
'values' => $values,
|
|
||||||
'menu' => 'config',
|
|
||||||
'title' => t('New database')
|
|
||||||
)));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Auto-update
|
// Auto-update
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user