summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Vorobyev <vorobyev@coacha.com>2017-02-15 17:38:48 +0900
committerKonstantin Vorobyev <vorobyev@coacha.com>2017-02-15 17:38:48 +0900
commit6e9de547c074ad794b6d272eda9bf9b7d7bef792 (patch)
treed147bb8d8d286e9293b6ce7642906a48d7817603
parent5376bb9e0cf2aad9b12d6fde1f43f92854b55cf9 (diff)
Fix #3030: Add upload the sqlite database feature
-rw-r--r--app/Controller/ConfigController.php26
-rw-r--r--app/Model/ConfigModel.php14
-rw-r--r--app/Template/config/about.php3
-rw-r--r--app/Template/config/upload_db.php18
4 files changed, 61 insertions, 0 deletions
diff --git a/app/Controller/ConfigController.php b/app/Controller/ConfigController.php
index 8572316e..222549f4 100644
--- a/app/Controller/ConfigController.php
+++ b/app/Controller/ConfigController.php
@@ -201,6 +201,32 @@ class ConfigController extends BaseController
}
/**
+ * 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
*
* @access public
diff --git a/app/Model/ConfigModel.php b/app/Model/ConfigModel.php
index 945c5e6f..b45199fd 100644
--- a/app/Model/ConfigModel.php
+++ b/app/Model/ConfigModel.php
@@ -49,6 +49,20 @@ class ConfigModel extends SettingModel
}
/**
+ * 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
*
* @access public
diff --git a/app/Template/config/about.php b/app/Template/config/about.php
index 3f078c3d..23a3e6c0 100644
--- a/app/Template/config/about.php
+++ b/app/Template/config/about.php
@@ -69,6 +69,9 @@
<?= t('(Gzip compressed Sqlite file)') ?>
</li>
<li>
+ <?= $this->url->link(t('Upload the database'), 'ConfigController', 'uploadDb', array(), false, 'js-modal-medium') ?>
+ </li>
+ <li>
<?= $this->url->link(t('Optimize the database'), 'ConfigController', 'optimizeDb', array(), true) ?>&nbsp;
<?= t('(VACUUM command)') ?>
</li>
diff --git a/app/Template/config/upload_db.php b/app/Template/config/upload_db.php
new file mode 100644
index 00000000..4d02c9a8
--- /dev/null
+++ b/app/Template/config/upload_db.php
@@ -0,0 +1,18 @@
+<div class="page-header">
+ <h2><?= t('Upload the Sqlite database') ?></h2>
+</div>
+
+<div class="alert">
+ <ul>
+ <li><?= t('You can upload Gzip compressed Sqlite database you previously downloaded') ?></li>
+ </ul>
+</div>
+
+<form action="<?= $this->url->href('ConfigController', 'uploadDbSave') ?>" method="post" enctype="multipart/form-data">
+ <?= $this->form->csrf() ?>
+
+ <?= $this->form->label(t('Database file'), 'file') ?>
+ <?= $this->form->file('file') ?>
+
+ <?= $this->modal->submitButtons(array('submitLabel' => t('Upload'))) ?>
+</form>