aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-07-03 22:48:29 +0200
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-07-03 22:48:29 +0200
commitb34f59e85aa851b82210fdc50074918034f960db (patch)
treeab7dcdb13d84454c8a6848a8ea91f293f4d3a1d7 /app/Models
parent2501bb337e75c41f97570f25775e20131faf2f2a (diff)
Preparation #3 for SQLite
https://github.com/marienfressinaud/FreshRSS/issues/100
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/Category.php2
-rw-r--r--app/Models/Entry.php2
-rw-r--r--app/Models/EntryDAOSQLite.php10
-rw-r--r--app/Models/Factory.php9
-rw-r--r--app/Models/Feed.php4
-rw-r--r--app/Models/FeedDAO.php16
-rw-r--r--app/Models/FeedDAOSQLite.php5
7 files changed, 31 insertions, 17 deletions
diff --git a/app/Models/Category.php b/app/Models/Category.php
index 328bae799..0a0dbd3ca 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -44,7 +44,7 @@ class FreshRSS_Category extends Minz_Model {
}
public function feeds () {
if ($this->feeds === null) {
- $feedDAO = new FreshRSS_FeedDAO ();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
$this->feeds = $feedDAO->listByCategory ($this->id ());
$this->nbFeed = 0;
$this->nbNotRead = 0;
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index a24a902d5..0bf1f2616 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -74,7 +74,7 @@ class FreshRSS_Entry extends Minz_Model {
}
public function feed ($object = false) {
if ($object) {
- $feedDAO = new FreshRSS_FeedDAO ();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
return $feedDAO->searchById ($this->feed);
} else {
return $this->feed;
diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php
index 45d3a3ea9..0a837b3aa 100644
--- a/app/Models/EntryDAOSQLite.php
+++ b/app/Models/EntryDAOSQLite.php
@@ -13,24 +13,24 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {
}
} else {
$this->bd->beginTransaction();
- $sql = 'UPDATE `' . $this->prefix . 'entry` e SET e.is_read = ? WHERE e.id=? AND e.is_read<>?';
+ $sql = 'UPDATE `' . $this->prefix . 'entry` SET is_read=? WHERE id=? AND 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);
+ Minz_Log::record('SQL error markRead 1: ' . $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=?)';
+ $sql = 'UPDATE `' . $this->prefix . 'feed` SET cache_nbUnreads=cache_nbUnreads' . ($is_read ? '-' : '+') . '1 '
+ . 'WHERE 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);
+ Minz_Log::record('SQL error markRead 2: ' . $info[2], Minz_Log::ERROR);
$this->bd->rollBack ();
return false;
}
diff --git a/app/Models/Factory.php b/app/Models/Factory.php
index 3ef68c41d..95d21a277 100644
--- a/app/Models/Factory.php
+++ b/app/Models/Factory.php
@@ -2,6 +2,15 @@
class FreshRSS_Factory {
+ public static function createFeedDao() {
+ $db = Minz_Configuration::dataBase();
+ if ($db['type'] === 'sqlite') {
+ return new FreshRSS_FeedDAOSQLite();
+ } else {
+ return new FreshRSS_FeedDAO();
+ }
+ }
+
public static function createEntryDao() {
$db = Minz_Configuration::dataBase();
if ($db['type'] === 'sqlite') {
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index ba142c8c8..8093b2bfd 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -87,7 +87,7 @@ class FreshRSS_Feed extends Minz_Model {
}
public function nbEntries () {
if ($this->nbEntries < 0) {
- $feedDAO = new FreshRSS_FeedDAO ();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
$this->nbEntries = $feedDAO->countEntries ($this->id ());
}
@@ -95,7 +95,7 @@ class FreshRSS_Feed extends Minz_Model {
}
public function nbNotRead () {
if ($this->nbNotRead < 0) {
- $feedDAO = new FreshRSS_FeedDAO ();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
$this->nbNotRead = $feedDAO->countNotRead ($this->id ());
}
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index 3f3847aa4..9534d61bd 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -84,15 +84,15 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
public function updateLastUpdate ($id, $inError = 0, $updateCache = true) {
if ($updateCache) {
- $sql = 'UPDATE `' . $this->prefix . 'feed` f ' //2 sub-requests with FOREIGN KEY(e.id_feed), INDEX(e.is_read) faster than 1 request with GROUP BY or CASE
- . 'SET f.cache_nbEntries=(SELECT COUNT(e1.id) FROM `' . $this->prefix . 'entry` e1 WHERE e1.id_feed=f.id),'
- . 'f.cache_nbUnreads=(SELECT COUNT(e2.id) FROM `' . $this->prefix . 'entry` e2 WHERE e2.id_feed=f.id AND e2.is_read=0),'
+ $sql = 'UPDATE `' . $this->prefix . 'feed` ' //2 sub-requests with FOREIGN KEY(e.id_feed), INDEX(e.is_read) faster than 1 request with GROUP BY or CASE
+ . 'SET cache_nbEntries=(SELECT COUNT(e1.id) FROM `' . $this->prefix . 'entry` e1 WHERE e1.id_feed=feed.id),'
+ . 'cache_nbUnreads=(SELECT COUNT(e2.id) FROM `' . $this->prefix . 'entry` e2 WHERE e2.id_feed=feed.id AND e2.is_read=0),'
. 'lastUpdate=?, error=? '
- . 'WHERE f.id=?';
+ . 'WHERE id=?';
} else {
- $sql = 'UPDATE `' . $this->prefix . 'feed` f '
+ $sql = 'UPDATE `' . $this->prefix . 'feed` '
. 'SET lastUpdate=?, error=? '
- . 'WHERE f.id=?';
+ . 'WHERE id=?';
}
$values = array (
@@ -320,8 +320,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
}
$affected = $stm->rowCount();
- $sql = 'UPDATE `' . $this->prefix . 'feed` f '
- . 'SET f.cache_nbEntries=0, f.cache_nbUnreads=0 WHERE f.id=?';
+ $sql = 'UPDATE `' . $this->prefix . 'feed` '
+ . 'SET cache_nbEntries=0, cache_nbUnreads=0 WHERE id=?';
$values = array ($id);
$stm = $this->bd->prepare ($sql);
if (!($stm && $stm->execute ($values))) {
diff --git a/app/Models/FeedDAOSQLite.php b/app/Models/FeedDAOSQLite.php
new file mode 100644
index 000000000..f3c92149e
--- /dev/null
+++ b/app/Models/FeedDAOSQLite.php
@@ -0,0 +1,5 @@
+<?php
+
+class FreshRSS_FeedDAOSQLite extends FreshRSS_FeedDAO {
+
+}