EntryDAOSQLite.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {
  3. public function markRead($ids, $is_read = true) {
  4. if (is_array($ids)) { //Many IDs at once
  5. if (true) { //Not supported yet in SQLite, so always call IDs one by one
  6. $affected = 0;
  7. foreach ($ids as $id) {
  8. $affected += $this->markRead($id, $is_read);
  9. }
  10. return $affected;
  11. }
  12. } else {
  13. $this->bd->beginTransaction();
  14. $sql = 'UPDATE `' . $this->prefix . 'entry` e SET e.is_read = ? WHERE e.id=? AND e.is_read<>?';
  15. $values = array($is_read ? 1 : 0, $ids, $is_read ? 1 : 0);
  16. $stm = $this->bd->prepare($sql);
  17. if (!($stm && $stm->execute ($values))) {
  18. $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo();
  19. Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR);
  20. $this->bd->rollBack ();
  21. return false;
  22. }
  23. $affected = $stm->rowCount();
  24. if ($affected > 0) {
  25. $sql = 'UPDATE `' . $this->prefix . 'feed` f SET f.cache_nbUnreads=f.cache_nbUnreads' . ($is_read ? '-' : '+') . '1 '
  26. . 'WHERE f.id=(SELECT e.id_feed FROM `' . $this->prefix . 'entry` e WHERE e.id=?)';
  27. $values = array($ids);
  28. $stm = $this->bd->prepare($sql);
  29. if (!($stm && $stm->execute ($values))) {
  30. $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo();
  31. Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR);
  32. $this->bd->rollBack ();
  33. return false;
  34. }
  35. }
  36. $this->bd->commit();
  37. return $affected;
  38. }
  39. }
  40. }