aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Database.class.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-12-23 10:35:09 +0100
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-12-23 10:35:09 +0100
commit5cfafc6110985236d9f212533faee79e460bf20d (patch)
tree439b8e12a2b246702891b1cd97386d205f150a73 /inc/poche/Database.class.php
parent1810c13b55b01043620fd81a65ce6e84cccc429c (diff)
downloadwallabag-5cfafc6110985236d9f212533faee79e460bf20d.tar.gz
wallabag-5cfafc6110985236d9f212533faee79e460bf20d.tar.zst
wallabag-5cfafc6110985236d9f212533faee79e460bf20d.zip
[add] check tags tables
Diffstat (limited to 'inc/poche/Database.class.php')
-rw-r--r--inc/poche/Database.class.php71
1 files changed, 69 insertions, 2 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index d95b9b81..d7e9fc11 100644
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -39,12 +39,79 @@ class Database {
39 public function isInstalled() { 39 public function isInstalled() {
40 $sql = "SELECT username FROM users"; 40 $sql = "SELECT username FROM users";
41 $query = $this->executeQuery($sql, array()); 41 $query = $this->executeQuery($sql, array());
42 if ($query == false) {
43 die(STORAGE . ' database looks empty. You have to create it (you can find database structure in install folder).');
44 }
42 $hasAdmin = count($query->fetchAll()); 45 $hasAdmin = count($query->fetchAll());
43 46
44 if ($hasAdmin == 0) 47 if ($hasAdmin == 0)
45 return FALSE; 48 return false;
46 49
47 return TRUE; 50 return true;
51 }
52
53 public function checkTags() {
54
55 if (STORAGE == 'sqlite') {
56 $sql = '
57 CREATE TABLE IF NOT EXISTS tags (
58 id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
59 value TEXT
60 )';
61 }
62 elseif(STORAGE == 'mysql') {
63 $sql = '
64 CREATE TABLE IF NOT EXISTS `tags` (
65 `id` int(11) NOT NULL AUTO_INCREMENT,
66 `value` varchar(255) NOT NULL,
67 PRIMARY KEY (`id`)
68 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
69 ';
70 }
71 else {
72 $sql = '
73 CREATE TABLE tags (
74 id bigserial primary key,
75 value varchar(255) NOT NULL
76 );
77 ';
78 }
79
80 $query = $this->executeQuery($sql, array());
81
82 if (STORAGE == 'sqlite') {
83 $sql = '
84 CREATE TABLE tags_entries (
85 id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
86 entry_id INTEGER,
87 tag_id INTEGER,
88 FOREIGN KEY(entry_id) REFERENCES entries(id) ON DELETE CASCADE,
89 FOREIGN KEY(tag_id) REFERENCES tags(id) ON DELETE CASCADE
90 )';
91 }
92 elseif(STORAGE == 'mysql') {
93 $sql = '
94 CREATE TABLE IF NOT EXISTS `tags_entries` (
95 `id` int(11) NOT NULL AUTO_INCREMENT,
96 `entry_id` int(11) NOT NULL,
97 `tag_id` int(11) NOT NULL,
98 FOREIGN KEY(entry_id) REFERENCES entries(id) ON DELETE CASCADE,
99 FOREIGN KEY(tag_id) REFERENCES tags(id) ON DELETE CASCADE,
100 PRIMARY KEY (`id`)
101 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
102 ';
103 }
104 else {
105 $sql = '
106 CREATE TABLE tags_entries (
107 id bigserial primary key,
108 entry_id integer NOT NULL,
109 tag_id integer NOT NULL
110 )
111 ';
112 }
113
114 $query = $this->executeQuery($sql, array());
48 } 115 }
49 116
50 public function install($login, $password) { 117 public function install($login, $password) {