UserDAO.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. class FreshRSS_UserDAO extends Minz_ModelPdo {
  3. public function createUser() {
  4. require(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. } catch (Exception $e) {
  9. Minz_Log::error('Error while creating database for user ' . $this->current_user . ': ' . $e->getMessage());
  10. }
  11. if ($ok) {
  12. return true;
  13. } else {
  14. $info = $this->pdo->errorInfo();
  15. Minz_Log::error(__METHOD__ . ' error: ' . json_encode($info));
  16. return false;
  17. }
  18. }
  19. public function deleteUser() {
  20. if (defined('STDERR')) {
  21. fwrite(STDERR, 'Deleting SQL data for user “' . $this->current_user . "”…\n");
  22. }
  23. require(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php');
  24. $ok = $this->pdo->exec($SQL_DROP_TABLES) !== false;
  25. if ($ok) {
  26. return true;
  27. } else {
  28. $info = $this->pdo->errorInfo();
  29. Minz_Log::error(__METHOD__ . ' error: ' . json_encode($info));
  30. return false;
  31. }
  32. }
  33. public static function exists($username) {
  34. return is_dir(USERS_PATH . '/' . $username);
  35. }
  36. public static function touch($username = '') {
  37. if (!FreshRSS_user_Controller::checkUsername($username)) {
  38. $username = Minz_Session::param('currentUser', '_');
  39. }
  40. return touch(USERS_PATH . '/' . $username . '/config.php');
  41. }
  42. public static function mtime($username) {
  43. return @filemtime(USERS_PATH . '/' . $username . '/config.php');
  44. }
  45. }