From aa8c9f2a32ea75278d52c86c6a3a39d34bce5cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 31 May 2013 22:55:52 +0200 Subject: Installation mode --- inc/store/sqlite.class.php | 51 +++++++++++++++++++++++++++++++++++++++++++++- inc/store/store.class.php | 8 ++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) (limited to 'inc/store') 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 { parent::__construct(); $this->handle = new PDO(self::$db_path); - $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)'); $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } @@ -25,6 +24,56 @@ class Sqlite extends Store { return $this->handle; } + public function isInstalled() { + $sql = "SELECT name FROM sqlite_sequence WHERE name=?"; + $query = $this->executeQuery($sql, array('config')); + $hasConfig = $query->fetchAll(); + + if (count($hasConfig) == 0) + return FALSE; + + if (!$this->getLogin() || !$this->getPassword()) + return FALSE; + + return TRUE; + } + + public function install($login, $password) { + $this->getHandle()->exec('CREATE TABLE IF NOT EXISTS "config" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , "name" VARCHAR UNIQUE, "value" BLOB)'); + + $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)'); + + if (!$this->getLogin()) { + $sql_login = 'INSERT INTO config ( name, value ) VALUES (?, ?)'; + $params_login = array('login', $login); + $query = $this->executeQuery($sql_login, $params_login); + } + + if (!$this->getPassword()) { + $sql_pass = 'INSERT INTO config ( name, value ) VALUES (?, ?)'; + $params_pass = array('password', $password); + $query = $this->executeQuery($sql_pass, $params_pass); + } + + return TRUE; + } + + public function getLogin() { + $sql = "SELECT value FROM config WHERE name=?"; + $query = $this->executeQuery($sql, array('login')); + $login = $query->fetchAll(); + + return isset($login[0]['value']) ? $login[0]['value'] : FALSE; + } + + public function getPassword() { + $sql = "SELECT value FROM config WHERE name=?"; + $query = $this->executeQuery($sql, array('password')); + $pass = $query->fetchAll(); + + return isset($pass[0]['value']) ? $pass[0]['value'] : FALSE; + } + private function executeQuery($sql, $params) { try { 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 { } + public function getLogin() { + + } + + public function getPassword() { + + } + public function add() { } -- cgit v1.2.3