UserDAO.php 1.6 KB

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