aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/store
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2013-05-31 22:55:52 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2013-05-31 22:55:52 +0200
commitaa8c9f2a32ea75278d52c86c6a3a39d34bce5cc7 (patch)
tree0f87b4812a968e85383eedb6803170e913cb6275 /inc/store
parentbaa8617364c3888fd28c3ffe83cfeb5345914356 (diff)
downloadwallabag-aa8c9f2a32ea75278d52c86c6a3a39d34bce5cc7.tar.gz
wallabag-aa8c9f2a32ea75278d52c86c6a3a39d34bce5cc7.tar.zst
wallabag-aa8c9f2a32ea75278d52c86c6a3a39d34bce5cc7.zip
Installation mode
Diffstat (limited to 'inc/store')
-rw-r--r--inc/store/sqlite.class.php51
-rw-r--r--inc/store/store.class.php8
2 files changed, 58 insertions, 1 deletions
diff --git a/inc/store/sqlite.class.php b/inc/store/sqlite.class.php
index cda412e6..4bfbb29e 100644
--- a/inc/store/sqlite.class.php
+++ b/inc/store/sqlite.class.php
@@ -17,7 +17,6 @@ class Sqlite extends Store {
17 parent::__construct(); 17 parent::__construct();
18 18
19 $this->handle = new PDO(self::$db_path); 19 $this->handle = new PDO(self::$db_path);
20 $this->handle->exec('CREATE TABLE IF NOT EXISTS "entries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , "title" VARCHAR, "url" VARCHAR UNIQUE , "is_read" INTEGER DEFAULT 0, "is_fav" INTEGER DEFAULT 0, "content" BLOB)');
21 $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 20 $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
22 } 21 }
23 22
@@ -25,6 +24,56 @@ class Sqlite extends Store {
25 return $this->handle; 24 return $this->handle;
26 } 25 }
27 26
27 public function isInstalled() {
28 $sql = "SELECT name FROM sqlite_sequence WHERE name=?";
29 $query = $this->executeQuery($sql, array('config'));
30 $hasConfig = $query->fetchAll();
31
32 if (count($hasConfig) == 0)
33 return FALSE;
34
35 if (!$this->getLogin() || !$this->getPassword())
36 return FALSE;
37
38 return TRUE;
39 }
40
41 public function install($login, $password) {
42 $this->getHandle()->exec('CREATE TABLE IF NOT EXISTS "config" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , "name" VARCHAR UNIQUE, "value" BLOB)');
43
44 $this->handle->exec('CREATE TABLE IF NOT EXISTS "entries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , "title" VARCHAR, "url" VARCHAR UNIQUE , "is_read" INTEGER DEFAULT 0, "is_fav" INTEGER DEFAULT 0, "content" BLOB)');
45
46 if (!$this->getLogin()) {
47 $sql_login = 'INSERT INTO config ( name, value ) VALUES (?, ?)';
48 $params_login = array('login', $login);
49 $query = $this->executeQuery($sql_login, $params_login);
50 }
51
52 if (!$this->getPassword()) {
53 $sql_pass = 'INSERT INTO config ( name, value ) VALUES (?, ?)';
54 $params_pass = array('password', $password);
55 $query = $this->executeQuery($sql_pass, $params_pass);
56 }
57
58 return TRUE;
59 }
60
61 public function getLogin() {
62 $sql = "SELECT value FROM config WHERE name=?";
63 $query = $this->executeQuery($sql, array('login'));
64 $login = $query->fetchAll();
65
66 return isset($login[0]['value']) ? $login[0]['value'] : FALSE;
67 }
68
69 public function getPassword() {
70 $sql = "SELECT value FROM config WHERE name=?";
71 $query = $this->executeQuery($sql, array('password'));
72 $pass = $query->fetchAll();
73
74 return isset($pass[0]['value']) ? $pass[0]['value'] : FALSE;
75 }
76
28 private function executeQuery($sql, $params) { 77 private function executeQuery($sql, $params) {
29 try 78 try
30 { 79 {
diff --git a/inc/store/store.class.php b/inc/store/store.class.php
index 360ff7c2..dd7d4cfe 100644
--- a/inc/store/store.class.php
+++ b/inc/store/store.class.php
@@ -13,6 +13,14 @@ class Store {
13 13
14 } 14 }
15 15
16 public function getLogin() {
17
18 }
19
20 public function getPassword() {
21
22 }
23
16 public function add() { 24 public function add() {
17 25
18 } 26 }