UserDAO.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. class FreshRSS_UserDAO extends Minz_ModelPdo {
  3. public function createUser($username) {
  4. $db = Minz_Configuration::dataBase();
  5. require_once(APP_PATH . '/SQL/install.sql.' . $db['type'] . '.php');
  6. $userPDO = new Minz_ModelPdo($username);
  7. $ok = false;
  8. if (defined('SQL_CREATE_TABLES')) { //E.g. MySQL
  9. $sql = sprintf(SQL_CREATE_TABLES, $db['prefix'] . $username . '_', _t('gen.short.default_category'));
  10. $stm = $userPDO->bd->prepare($sql);
  11. $ok = $stm && $stm->execute();
  12. } else { //E.g. SQLite
  13. global $SQL_CREATE_TABLES;
  14. if (is_array($SQL_CREATE_TABLES)) {
  15. $ok = true;
  16. foreach ($SQL_CREATE_TABLES as $instruction) {
  17. $sql = sprintf($instruction, '', _t('gen.short.default_category'));
  18. $stm = $userPDO->bd->prepare($sql);
  19. $ok &= ($stm && $stm->execute());
  20. }
  21. }
  22. }
  23. if ($ok) {
  24. return true;
  25. } else {
  26. $info = empty($stm) ? array(2 => 'syntax error') : $stm->errorInfo();
  27. Minz_Log::error('SQL error : ' . $info[2]);
  28. return false;
  29. }
  30. }
  31. public function deleteUser($username) {
  32. $db = Minz_Configuration::dataBase();
  33. require_once(APP_PATH . '/SQL/install.sql.' . $db['type'] . '.php');
  34. if ($db['type'] === 'sqlite') {
  35. return unlink(join_path(DATA_PATH, 'users', $username, 'db.sqlite'));
  36. } else {
  37. $userPDO = new Minz_ModelPdo($username);
  38. $sql = sprintf(SQL_DROP_TABLES, $db['prefix'] . $username . '_');
  39. $stm = $userPDO->bd->prepare($sql);
  40. if ($stm && $stm->execute()) {
  41. return true;
  42. } else {
  43. $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo();
  44. Minz_Log::error('SQL error : ' . $info[2]);
  45. return false;
  46. }
  47. }
  48. }
  49. public static function exist($username) {
  50. return is_dir(join_path(DATA_PATH , 'users', $username));
  51. }
  52. public static function touch($username) {
  53. return touch(join_path(DATA_PATH , 'users', $username, 'config.php'));
  54. }
  55. public static function mtime($username) {
  56. return @filemtime(join_path(DATA_PATH , 'users', $username, 'config.php'));
  57. }
  58. }