aboutsummaryrefslogtreecommitdiff
path: root/app/Models/UserDAO.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Models/UserDAO.php')
-rw-r--r--app/Models/UserDAO.php57
1 files changed, 9 insertions, 48 deletions
diff --git a/app/Models/UserDAO.php b/app/Models/UserDAO.php
index 6292cc09f..7580de06e 100644
--- a/app/Models/UserDAO.php
+++ b/app/Models/UserDAO.php
@@ -1,43 +1,22 @@
<?php
class FreshRSS_UserDAO extends Minz_ModelPdo {
- public function createUser($new_user_language = null, $insertDefaultFeeds = false) {
- require_once(APP_PATH . '/SQL/install.sql.' . $this->bd->dbType() . '.php');
-
- $currentLanguage = Minz_Translate::language();
+ public function createUser($insertDefaultFeeds = false) {
+ require_once(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php');
try {
- if ($new_user_language != null) {
- Minz_Translate::reset($new_user_language);
- }
- $ok = false;
- if (defined('SQL_CREATE_TABLES')) { //E.g. MySQL
- $sql = sprintf(SQL_CREATE_TABLES . SQL_CREATE_TABLE_ENTRYTMP . SQL_CREATE_TABLE_TAGS, $this->prefix, _t('gen.short.default_category'));
- $stm = $this->bd->prepare($sql);
- $ok = $stm && $stm->execute();
- } else { //E.g. SQLite
- global $SQL_CREATE_TABLES, $SQL_CREATE_TABLE_ENTRYTMP, $SQL_CREATE_TABLE_TAGS;
- if (is_array($SQL_CREATE_TABLES)) {
- $instructions = array_merge($SQL_CREATE_TABLES, $SQL_CREATE_TABLE_ENTRYTMP, $SQL_CREATE_TABLE_TAGS);
- $ok = !empty($instructions);
- foreach ($instructions as $instruction) {
- $sql = sprintf($instruction, $this->prefix, _t('gen.short.default_category'));
- $stm = $this->bd->prepare($sql);
- $ok &= ($stm && $stm->execute());
- }
- }
- }
+ $sql = SQL_CREATE_TABLES . SQL_CREATE_TABLE_ENTRYTMP . SQL_CREATE_TABLE_TAGS;
+ $ok = $this->pdo->exec($sql) !== false; //Note: Only exec() can take multiple statements safely.
if ($ok && $insertDefaultFeeds) {
$default_feeds = FreshRSS_Context::$system_conf->default_feeds;
+ $stm = $this->pdo->prepare(SQL_INSERT_FEED);
foreach ($default_feeds as $feed) {
- $sql = sprintf(SQL_INSERT_FEED, $this->prefix);
- $stm = $this->bd->prepare($sql);
- $parameters = array(
+ $parameters = [
':url' => $feed['url'],
':name' => $feed['name'],
':website' => $feed['website'],
':description' => $feed['description'],
- );
+ ];
$ok &= ($stm && $stm->execute($parameters));
}
}
@@ -45,8 +24,6 @@ class FreshRSS_UserDAO extends Minz_ModelPdo {
Minz_Log::error('Error while creating database for user: ' . $e->getMessage());
}
- Minz_Translate::reset($currentLanguage);
-
if ($ok) {
return true;
} else {
@@ -61,25 +38,9 @@ class FreshRSS_UserDAO extends Minz_ModelPdo {
fwrite(STDERR, 'Deleting SQL data for user “' . $this->current_user . "”…\n");
}
- require_once(APP_PATH . '/SQL/install.sql.' . $this->bd->dbType() . '.php');
+ require_once(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php');
- $ok = false;
- if (defined('SQL_DROP_TABLES')) { //E.g. MySQL
- $sql = sprintf(SQL_DROP_TABLES, $this->prefix);
- $stm = $this->bd->prepare($sql);
- $ok = $stm && $stm->execute();
- } else { //E.g. SQLite
- global $SQL_DROP_TABLES;
- if (is_array($SQL_DROP_TABLES)) {
- $instructions = $SQL_DROP_TABLES;
- $ok = !empty($instructions);
- foreach ($instructions as $instruction) {
- $sql = sprintf($instruction, $this->prefix);
- $stm = $this->bd->prepare($sql);
- $ok &= ($stm && $stm->execute());
- }
- }
- }
+ $ok = $this->pdo->exec(SQL_DROP_TABLES) !== false;
if ($ok) {
return true;