diff --git a/app/Controller/ConfigController.php b/app/Controller/ConfigController.php index 8572316e7..222549f4f 100644 --- a/app/Controller/ConfigController.php +++ b/app/Controller/ConfigController.php @@ -200,6 +200,32 @@ class ConfigController extends BaseController $this->response->redirect($this->helper->url->to('ConfigController', 'index')); } + /** + * Display the Sqlite database upload page + * + * @access public + */ + public function uploadDb() + { + $this->response->html($this->helper->layout->config('config/upload_db', array())); + } + + /** + * Replace current Sqlite db with uploaded file + * + * @access public + */ + public function uploadDbSave() + { + $filename = $this->request->getFilePath('file'); + if (!file_exists($filename) || !$this->configModel->uploadDatabase($filename)) { + $this->flash->failure(t('Unable to read your file')); + } else { + $this->flash->success(t('Database upload done.')); + } + $this->response->redirect($this->helper->url->to('ConfigController', 'index')); + } + /** * Regenerate webhook token * diff --git a/app/Model/ConfigModel.php b/app/Model/ConfigModel.php index 945c5e6fa..b45199fd9 100644 --- a/app/Model/ConfigModel.php +++ b/app/Model/ConfigModel.php @@ -48,6 +48,20 @@ class ConfigModel extends SettingModel return gzencode(file_get_contents(DB_FILENAME)); } + /** + * Replace database file with uploaded one + * + * @access public + * @return boolean + */ + public function uploadDatabase($file) + { + + $this->db->closeConnection(); + $result = file_put_contents(DB_FILENAME, gzdecode(file_get_contents($file))); + return $result == false? false: true; + } + /** * Get the Sqlite database size in bytes * diff --git a/app/Template/config/about.php b/app/Template/config/about.php index 3f078c3dd..23a3e6c02 100644 --- a/app/Template/config/about.php +++ b/app/Template/config/about.php @@ -68,6 +68,9 @@ = $this->url->link(t('Download the database'), 'ConfigController', 'downloadDb', array(), true) ?> = t('(Gzip compressed Sqlite file)') ?> +