summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-08-09 19:58:39 +0200
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-08-09 19:58:39 +0200
commitd477373ef2879bdeeaa3c157287c0fab98afefdc (patch)
tree14117dc0d2a8b1fd8124be3127eaf74b1a046d3b /app
parent737b206d8cc0819efb11beb9a3ad341827a29290 (diff)
SQLite: Bug creation new users
Not tested much yet. Some MySQL parts changed a bit too to double-check. https://github.com/marienfressinaud/FreshRSS/issues/574
Diffstat (limited to 'app')
-rw-r--r--app/Models/UserDAO.php35
-rw-r--r--app/SQL/install.sql.sqlite.php1
2 files changed, 23 insertions, 13 deletions
diff --git a/app/Models/UserDAO.php b/app/Models/UserDAO.php
index 1763fac67..9f64fb4a7 100644
--- a/app/Models/UserDAO.php
+++ b/app/Models/UserDAO.php
@@ -4,18 +4,21 @@ class FreshRSS_UserDAO extends Minz_ModelPdo {
public function createUser($username) {
$db = Minz_Configuration::dataBase();
require_once(APP_PATH . '/SQL/install.sql.' . $db['type'] . '.php');
-
- if (defined('SQL_CREATE_TABLES')) {
+
+ $userPDO = new Minz_ModelPdo($username);
+
+ $ok = false;
+ if (defined('SQL_CREATE_TABLES')) { //E.g. MySQL
$sql = sprintf(SQL_CREATE_TABLES, $db['prefix'] . $username . '_', Minz_Translate::t('default_category'));
- $stm = $this->bd->prepare($sql);
+ $stm = $userPDO->bd->prepare($sql);
$ok = $stm && $stm->execute();
- } else {
+ } else { //E.g. SQLite
global $SQL_CREATE_TABLES;
if (is_array($SQL_CREATE_TABLES)) {
$ok = true;
foreach ($SQL_CREATE_TABLES as $instruction) {
$sql = sprintf($instruction, '', Minz_Translate::t('default_category'));
- $stm = $c->prepare($sql);
+ $stm = $userPDO->bd->prepare($sql);
$ok &= ($stm && $stm->execute());
}
}
@@ -24,7 +27,7 @@ class FreshRSS_UserDAO extends Minz_ModelPdo {
if ($ok) {
return true;
} else {
- $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo();
+ $info = empty($stm) ? array(2 => 'syntax error') : $stm->errorInfo();
Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
return false;
}
@@ -34,14 +37,20 @@ class FreshRSS_UserDAO extends Minz_ModelPdo {
$db = Minz_Configuration::dataBase();
require_once(APP_PATH . '/SQL/install.sql.' . $db['type'] . '.php');
- $sql = sprintf(SQL_DROP_TABLES, $db['prefix'] . $username . '_');
- $stm = $this->bd->prepare($sql);
- if ($stm && $stm->execute()) {
- return true;
+ if ($db['type'] === 'sqlite') {
+ return unlink(DATA_PATH . '/' . $username . '.sqlite');
} else {
- $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo();
- Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
- return false;
+ $userPDO = new Minz_ModelPdo($username);
+
+ $sql = sprintf(SQL_DROP_TABLES, $db['prefix'] . $username . '_');
+ $stm = $userPDO->bd->prepare($sql);
+ if ($stm && $stm->execute()) {
+ return true;
+ } else {
+ $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo();
+ Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
+ return false;
+ }
}
}
}
diff --git a/app/SQL/install.sql.sqlite.php b/app/SQL/install.sql.sqlite.php
index b90a5ef5e..7988ada04 100644
--- a/app/SQL/install.sql.sqlite.php
+++ b/app/SQL/install.sql.sqlite.php
@@ -1,4 +1,5 @@
<?php
+global $SQL_CREATE_TABLES;
$SQL_CREATE_TABLES = array(
'CREATE TABLE IF NOT EXISTS `%1$scategory` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,