From 5e0cf1472ef0b019c9d50d61ba944e977e28b104 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Wed, 15 Feb 2017 21:06:41 -0500 Subject: Improve PR #3038 --- ChangeLog | 4 ++++ app/Controller/ConfigController.php | 8 +++++--- app/Model/ConfigModel.php | 7 +++---- app/Template/config/upload_db.php | 8 ++++---- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0a331ebd..f6daffd2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,10 @@ Version 1.0.40 (unreleased) --------------------------- +New features: + +* Upload Sqlite database from user interface + Improvements: * Use contextual menu instead of action column in users management diff --git a/app/Controller/ConfigController.php b/app/Controller/ConfigController.php index 222549f4..62ae8201 100644 --- a/app/Controller/ConfigController.php +++ b/app/Controller/ConfigController.php @@ -207,7 +207,7 @@ class ConfigController extends BaseController */ public function uploadDb() { - $this->response->html($this->helper->layout->config('config/upload_db', array())); + $this->response->html($this->template->render('config/upload_db')); } /** @@ -215,14 +215,16 @@ class ConfigController extends BaseController * * @access public */ - public function uploadDbSave() + public function saveUploadedDb() { $filename = $this->request->getFilePath('file'); + if (!file_exists($filename) || !$this->configModel->uploadDatabase($filename)) { - $this->flash->failure(t('Unable to read your file')); + $this->flash->failure(t('Unable to read uploaded file.')); } else { $this->flash->success(t('Database upload done.')); } + $this->response->redirect($this->helper->url->to('ConfigController', 'index')); } diff --git a/app/Model/ConfigModel.php b/app/Model/ConfigModel.php index b45199fd..7f48f34f 100644 --- a/app/Model/ConfigModel.php +++ b/app/Model/ConfigModel.php @@ -52,14 +52,13 @@ class ConfigModel extends SettingModel * Replace database file with uploaded one * * @access public - * @return boolean + * @param string $file + * @return bool */ public function uploadDatabase($file) { - $this->db->closeConnection(); - $result = file_put_contents(DB_FILENAME, gzdecode(file_get_contents($file))); - return $result == false? false: true; + return file_put_contents(DB_FILENAME, gzdecode(file_get_contents($file))) !== false; } /** diff --git a/app/Template/config/upload_db.php b/app/Template/config/upload_db.php index 4d02c9a8..d7aaac86 100644 --- a/app/Template/config/upload_db.php +++ b/app/Template/config/upload_db.php @@ -3,12 +3,12 @@
- +

+ +

-
+ form->csrf() ?> form->label(t('Database file'), 'file') ?> -- cgit v1.2.3