UserDAO.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. class FreshRSS_UserDAO extends Minz_ModelPdo {
  3. public function createUser($insertDefaultFeeds = false) {
  4. require_once(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php');
  5. try {
  6. $sql = SQL_CREATE_TABLES . SQL_CREATE_TABLE_ENTRYTMP . SQL_CREATE_TABLE_TAGS;
  7. $ok = $this->pdo->exec($sql) !== false; //Note: Only exec() can take multiple statements safely.
  8. if ($ok && $insertDefaultFeeds) {
  9. $default_feeds = FreshRSS_Context::$system_conf->default_feeds;
  10. $stm = $this->pdo->prepare(SQL_INSERT_FEED);
  11. foreach ($default_feeds as $feed) {
  12. $parameters = [
  13. ':url' => $feed['url'],
  14. ':name' => $feed['name'],
  15. ':website' => $feed['website'],
  16. ':description' => $feed['description'],
  17. ];
  18. $ok &= ($stm && $stm->execute($parameters));
  19. }
  20. }
  21. } catch (Exception $e) {
  22. Minz_Log::error('Error while creating database for user: ' . $e->getMessage());
  23. }
  24. if ($ok) {
  25. return true;
  26. } else {
  27. $info = empty($stm) ? $this->pdo->errorInfo() : $stm->errorInfo();
  28. Minz_Log::error(__METHOD__ . ' error: ' . $info[2]);
  29. return false;
  30. }
  31. }
  32. public function deleteUser() {
  33. if (defined('STDERR')) {
  34. fwrite(STDERR, 'Deleting SQL data for user “' . $this->current_user . "”…\n");
  35. }
  36. require_once(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php');
  37. $ok = $this->pdo->exec(SQL_DROP_TABLES) !== false;
  38. if ($ok) {
  39. return true;
  40. } else {
  41. $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
  42. Minz_Log::error(__METHOD__ . ' error: ' . $info[2]);
  43. return false;
  44. }
  45. }
  46. public static function exists($username) {
  47. return is_dir(USERS_PATH . '/' . $username);
  48. }
  49. public static function touch($username = '') {
  50. if (!FreshRSS_user_Controller::checkUsername($username)) {
  51. $username = Minz_Session::param('currentUser', '_');
  52. }
  53. return touch(USERS_PATH . '/' . $username . '/config.php');
  54. }
  55. public static function mtime($username) {
  56. return @filemtime(USERS_PATH . '/' . $username . '/config.php');
  57. }
  58. }