X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=inc%2Fpoche%2FDatabase.class.php;h=84916b83efe3cebd2fc6d9f42d03ed327068b71e;hb=fd99a8c02d7c625771656a5c5081560027d8e6e9;hp=034b10034bedc37b9d6b262b71cbe526eb1e5c60;hpb=68857cea8c08aab54c632d63f4526d0bb16f80d4;p=github%2Fwallabag%2Fwallabag.git diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 034b1003..84916b83 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -29,6 +29,7 @@ class Database { } $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + Tools::logm('storage type ' . STORAGE); } private function getHandle() { @@ -36,19 +37,34 @@ class Database { } public function isInstalled() { - $sql = "SELECT username FROM users WHERE id=?"; - $query = $this->executeQuery($sql, array('1')); - $hasAdmin = $query->fetchAll(); + $sql = "SELECT username FROM users"; + $query = $this->executeQuery($sql, array()); + $hasAdmin = count($query->fetchAll()); - if (count($hasAdmin) == 0) + if ($hasAdmin == 0) return FALSE; return TRUE; } public function install($login, $password) { - $sql = 'INSERT INTO users ( username, password ) VALUES (?, ?)'; - $params = array($login, $password); + $sql = 'INSERT INTO users ( username, password, name, email) VALUES (?, ?, ?, ?)'; + $params = array($login, $password, $login, ' '); + $query = $this->executeQuery($sql, $params); + + $sequence = ''; + if (STORAGE == 'postgres') { + $sequence = 'users_id_seq'; + } + + $id_user = intval($this->getLastId($sequence)); + + $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; + $params = array($id_user, 'pager', '10'); + $query = $this->executeQuery($sql, $params); + + $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; + $params = array($id_user, 'language', 'en_EN.UTF8'); $query = $this->executeQuery($sql, $params); return TRUE; @@ -168,6 +184,13 @@ class Database { return $entries; } + public function updateContent($id, $content, $user_id) { + $sql_action = 'UPDATE entries SET content = ? WHERE id=? AND user_id=?'; + $params_action = array($content, $id, $user_id); + $query = $this->executeQuery($sql_action, $params_action); + return $query; + } + public function add($url, $title, $content, $user_id) { $sql_action = 'INSERT INTO entries ( url, title, content, user_id ) VALUES (?, ?, ?, ?)'; $params_action = array($url, $title, $content, $user_id); @@ -194,7 +217,7 @@ class Database { $query = $this->executeQuery($sql_action, $params_action); } - public function getLastId() { - return $this->getHandle()->lastInsertId(); + public function getLastId($column = '') { + return $this->getHandle()->lastInsertId($column); } }