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
This commit is contained in:
Alexandre Alapetite
2014-08-09 19:58:39 +02:00
parent 737b206d8c
commit d477373ef2
3 changed files with 35 additions and 21 deletions

View File

@@ -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;
}
}
}
}