diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-12-23 10:35:09 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-12-23 10:35:09 +0100 |
commit | 5cfafc6110985236d9f212533faee79e460bf20d (patch) | |
tree | 439b8e12a2b246702891b1cd97386d205f150a73 /inc/poche | |
parent | 1810c13b55b01043620fd81a65ce6e84cccc429c (diff) | |
download | wallabag-5cfafc6110985236d9f212533faee79e460bf20d.tar.gz wallabag-5cfafc6110985236d9f212533faee79e460bf20d.tar.zst wallabag-5cfafc6110985236d9f212533faee79e460bf20d.zip |
[add] check tags tables
Diffstat (limited to 'inc/poche')
-rw-r--r-- | inc/poche/Database.class.php | 71 | ||||
-rw-r--r-- | inc/poche/Poche.class.php | 3 |
2 files changed, 71 insertions, 3 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) { |
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 4b26574d..4f70afb7 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -49,6 +49,7 @@ class Poche | |||
49 | if (! $this->store->isInstalled()) { | 49 | if (! $this->store->isInstalled()) { |
50 | $this->install(); | 50 | $this->install(); |
51 | } | 51 | } |
52 | $this->store->checkTags(); | ||
52 | } | 53 | } |
53 | } | 54 | } |
54 | 55 | ||
@@ -659,7 +660,7 @@ class Poche | |||
659 | if(isset($_SERVER['REMOTE_USER'])) { | 660 | if(isset($_SERVER['REMOTE_USER'])) { |
660 | return array($_SERVER['REMOTE_USER'],'http_auth'); | 661 | return array($_SERVER['REMOTE_USER'],'http_auth'); |
661 | } | 662 | } |
662 | 663 | ||
663 | return array(false,false); | 664 | return array(false,false); |
664 | } | 665 | } |
665 | 666 | ||