EntryDAOPGSQL.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. class FreshRSS_EntryDAOPGSQL extends FreshRSS_EntryDAO {
  3. protected function addColumn($name) {
  4. return false;
  5. }
  6. protected function updateCacheUnreads($catId = false, $feedId = false) {
  7. return true; //done via triggers
  8. }
  9. /**
  10. * Mark all the articles in a feed as read.
  11. * There is a fail safe to prevent to mark as read articles that are
  12. * loaded during the mark as read action. Then the cache is updated.
  13. *
  14. * If $idMax equals 0, a deprecated debug message is logged
  15. *
  16. * @param integer $id_feed feed ID
  17. * @param integer $idMax fail safe article ID
  18. * @return integer affected rows
  19. */
  20. public function markReadFeed($id_feed, $idMax = 0) {
  21. if ($idMax == 0) {
  22. $idMax = time() . '000000';
  23. Minz_Log::debug('Calling markReadFeed(0) is deprecated!');
  24. }
  25. $this->bd->beginTransaction();
  26. $sql = 'UPDATE "' . $this->prefix . 'entry" '
  27. . 'SET is_read=:is_read '
  28. . 'WHERE id_feed=:id_feed AND NOT is_read AND id <= :idmax';
  29. $values = array($id_feed, $idMax);
  30. $stm = $this->bd->prepare($sql);
  31. $stm->bindValue(':is_read', true, PDO::PARAM_BOOL);
  32. $stm->bindValue(':id_feed', $id_feed);
  33. $stm->bindValue(':idmax', $idMax);
  34. if (!($stm && $stm->execute())) {
  35. $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo();
  36. Minz_Log::error('SQL error markReadFeed: ' . $info[2]);
  37. $this->bd->rollBack();
  38. return false;
  39. }
  40. $affected = $stm->rowCount();
  41. $this->bd->commit();
  42. return $affected;
  43. }
  44. public function listHashForFeedGuids($id_feed, $guids) {
  45. if (count($guids) < 1) {
  46. return array();
  47. }
  48. $sql = 'SELECT guid, hash AS hexHash FROM "' . $this->prefix . 'entry" WHERE id_feed=? AND guid IN (' . str_repeat('?,', count($guids) - 1). '?)';
  49. $stm = $this->bd->prepare($sql);
  50. $values = array($id_feed);
  51. $values = array_merge($values, $guids);
  52. if ($stm && $stm->execute($values)) {
  53. $result = array();
  54. $rows = $stm->fetchAll(PDO::FETCH_ASSOC);
  55. foreach ($rows as $row) {
  56. $result[$row['guid']] = $row['hexHash'];
  57. }
  58. return $result;
  59. } else {
  60. $info = $stm == null ? array(0 => '', 1 => '', 2 => 'syntax error') : $stm->errorInfo();
  61. if ($this->autoAddColumn($info)) {
  62. return $this->listHashForFeedGuids($id_feed, $guids);
  63. }
  64. Minz_Log::error('SQL error listHashForFeedGuids: ' . $info[0] . ': ' . $info[1] . ' ' . $info[2]
  65. . ' while querying feed ' . $id_feed);
  66. return false;
  67. }
  68. }
  69. public function optimizeTable() {
  70. return null;
  71. }
  72. public function size($all = true) {
  73. $db = FreshRSS_Context::$system_conf->db;
  74. $sql = 'SELECT pg_size_pretty(pg_database_size(?))';
  75. $values = array($db['base']);
  76. $stm = $this->bd->prepare($sql);
  77. $stm->execute($values);
  78. $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
  79. return $res[0];
  80. }
  81. }