diff options
| author | 2014-07-03 22:11:25 +0200 | |
|---|---|---|
| committer | 2014-07-03 22:11:25 +0200 | |
| commit | 2501bb337e75c41f97570f25775e20131faf2f2a (patch) | |
| tree | b87abb05d74925dd442febea67b14f213f61afec /app/Models/EntryDAOSQLite.php | |
| parent | d6f414108667f32fe2b480adeb7ec9c218db2f4a (diff) | |
Preparation #2 for SQLite
https://github.com/marienfressinaud/FreshRSS/issues/100
Diffstat (limited to 'app/Models/EntryDAOSQLite.php')
| -rw-r--r-- | app/Models/EntryDAOSQLite.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php new file mode 100644 index 000000000..45d3a3ea9 --- /dev/null +++ b/app/Models/EntryDAOSQLite.php @@ -0,0 +1,42 @@ +<?php + +class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO { + + public function markRead($ids, $is_read = true) { + if (is_array($ids)) { //Many IDs at once + if (true) { //Not supported yet in SQLite, so always call IDs one by one + $affected = 0; + foreach ($ids as $id) { + $affected += $this->markRead($id, $is_read); + } + return $affected; + } + } else { + $this->bd->beginTransaction(); + $sql = 'UPDATE `' . $this->prefix . 'entry` e SET e.is_read = ? WHERE e.id=? AND e.is_read<>?'; + $values = array($is_read ? 1 : 0, $ids, $is_read ? 1 : 0); + $stm = $this->bd->prepare($sql); + if (!($stm && $stm->execute ($values))) { + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR); + $this->bd->rollBack (); + return false; + } + $affected = $stm->rowCount(); + if ($affected > 0) { + $sql = 'UPDATE `' . $this->prefix . 'feed` f SET f.cache_nbUnreads=f.cache_nbUnreads' . ($is_read ? '-' : '+') . '1 ' + . 'WHERE f.id=(SELECT e.id_feed FROM `' . $this->prefix . 'entry` e WHERE e.id=?)'; + $values = array($ids); + $stm = $this->bd->prepare($sql); + if (!($stm && $stm->execute ($values))) { + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR); + $this->bd->rollBack (); + return false; + } + } + $this->bd->commit(); + return $affected; + } + } +} |
