A free, self-hostable news aggregator…
Quoted upper-cases instead of string replace
Alexandre Alapetitef66be86e41d8
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.phpindex 3b1519c20..1dab60ea9 100644--- a/app/Models/CategoryDAO.php+++ b/app/Models/CategoryDAO.php@@ -100,7 +100,7 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchablepublic function listCategories($prePopulateFeeds = true, $details = false) {if ($prePopulateFeeds) {$sql = 'SELECT c.id AS c_id, c.name AS c_name, '- . ($details ? 'f.* ' : 'f.id, f.name, f.url, f.website, f.priority, f.error, f.cache_nbEntries, f.cache_nbUnreads ')+ . ($details ? 'f.* ' : 'f.id, f.name, f.url, f.website, f.priority, f.error, f.`cache_nbEntries`, f.`cache_nbUnreads` '). 'FROM `' . $this->prefix . 'category` c '. 'LEFT OUTER JOIN `' . $this->prefix . 'feed` f ON f.category=c.id '. 'GROUP BY f.id, c_id 'diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.phpindex 8d136cd6c..d39f0237c 100644--- a/app/Models/EntryDAO.php+++ b/app/Models/EntryDAO.php@@ -28,7 +28,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {$this->bd->beginTransaction();$hasTransaction = true;}- $stm = $this->bd->prepare('ALTER TABLE `' . $this->prefix . 'entry` ADD COLUMN lastSeen INT(11) DEFAULT 0');+ $stm = $this->bd->prepare('ALTER TABLE `' . $this->prefix . 'entry` ADD COLUMN `lastSeen` INT(11) DEFAULT 0');if ($stm && $stm->execute()) {$stm = $this->bd->prepare('CREATE INDEX entry_lastSeen_index ON `' . $this->prefix . 'entry`(`lastSeen`);'); //"IF NOT EXISTS" does not exist in MySQL 5.7if ($stm && $stm->execute()) {@@ -113,7 +113,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {if ($this->addEntryPrepared === null) {$sql = 'INSERT INTO `' . $this->prefix . 'entry` (id, guid, title, author, '. ($this->isCompressed() ? 'content_bin' : 'content')- . ', link, date, lastSeen, hash, is_read, is_favorite, id_feed, tags) '+ . ', link, date, `lastSeen`, hash, is_read, is_favorite, id_feed, tags) '. 'VALUES(:id, :guid, :title, :author, '. ($this->isCompressed() ? 'COMPRESS(:content)' : ':content'). ', :link, :date, :last_seen, '@@ -174,7 +174,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {$sql = 'UPDATE `' . $this->prefix . 'entry` '. 'SET title=?, author=?, '. ($this->isCompressed() ? 'content_bin=COMPRESS(?)' : 'content=?')- . ', link=?, date=?, lastSeen=?, hash='+ . ', link=?, date=?, `lastSeen`=?, hash='. ($this->hasNativeHex() ? 'X?' : '?') //TODO PostgreSQL. ', ' . ($valuesTmp['is_read'] === null ? '' : 'is_read=?, '). 'tags=? '@@ -265,7 +265,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {. 'WHERE e.is_read=0 '. 'GROUP BY e.id_feed'. ') x ON x.id_feed=f.id '- . 'SET f.cache_nbUnreads=COALESCE(x.nbUnreads, 0) '+ . 'SET f.`cache_nbUnreads`=COALESCE(x.nbUnreads, 0) '. 'WHERE 1';$values = array();if ($feedId !== false) {@@ -328,7 +328,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {} else {$sql = 'UPDATE `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed=f.id '. 'SET e.is_read=?,'- . 'f.cache_nbUnreads=f.cache_nbUnreads' . ($is_read ? '-' : '+') . '1 '+ . 'f.`cache_nbUnreads`=f.`cache_nbUnreads`' . ($is_read ? '-' : '+') . '1 '. 'WHERE e.id=? AND e.is_read=?';$values = array($is_read ? 1 : 0, $ids, $is_read ? 0 : 1);$stm = $this->bd->prepare($sql);@@ -467,7 +467,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {if ($affected > 0) {$sql = 'UPDATE `' . $this->prefix . 'feed` '- . 'SET cache_nbUnreads=cache_nbUnreads-' . $affected+ . 'SET `cache_nbUnreads`=`cache_nbUnreads`-' . $affected. ' WHERE id=?';$values = array($id_feed);$stm = $this->bd->prepare($sql);@@ -703,7 +703,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {if (count($guids) < 1) {return 0;}- $sql = 'UPDATE `' . $this->prefix . 'entry` SET lastSeen=? WHERE id_feed=? AND guid IN (' . str_repeat('?,', count($guids) - 1). '?)';+ $sql = 'UPDATE `' . $this->prefix . 'entry` SET `lastSeen`=? WHERE id_feed=? AND guid IN (' . str_repeat('?,', count($guids) - 1). '?)';$stm = $this->bd->prepare($sql);$values = array(time(), $id_feed);$values = array_merge($values, $guids);diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.phpindex 80dbcca6b..fd5d25bf6 100644--- a/app/Models/EntryDAOSQLite.php+++ b/app/Models/EntryDAOSQLite.php@@ -28,7 +28,7 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {protected function updateCacheUnreads($catId = false, $feedId = false) {$sql = 'UPDATE `' . $this->prefix . 'feed` '- . 'SET cache_nbUnreads=('+ . 'SET `cache_nbUnreads`=('. 'SELECT COUNT(*) AS nbUnreads FROM `' . $this->prefix . 'entry` e '. 'WHERE e.id_feed=`' . $this->prefix . 'feed`.id AND e.is_read=0) '. 'WHERE 1';@@ -86,7 +86,7 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {}$affected = $stm->rowCount();if ($affected > 0) {- $sql = 'UPDATE `' . $this->prefix . 'feed` SET cache_nbUnreads=cache_nbUnreads' . ($is_read ? '-' : '+') . '1 '+ $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);diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.phpindex ce65ed8b1..6e6d8857b 100644--- a/app/Models/FeedDAO.php+++ b/app/Models/FeedDAO.php@@ -2,7 +2,7 @@class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {public function addFeed($valuesTmp) {- $sql = 'INSERT INTO `' . $this->prefix . 'feed` (url, category, name, website, description, lastUpdate, priority, httpAuth, error, keep_history, ttl) VALUES(?, ?, ?, ?, ?, ?, 10, ?, 0, -2, -2)';+ $sql = 'INSERT INTO `' . $this->prefix . 'feed` (url, category, name, website, description, `lastUpdate`, priority, `httpAuth`, error, keep_history, ttl) VALUES(?, ?, ?, ?, ?, ?, 10, ?, 0, -2, -2)';$stm = $this->bd->prepare($sql);$values = array(@@ -85,13 +85,13 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {public function updateLastUpdate($id, $inError = 0, $updateCache = true) {if ($updateCache) {$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=`' . $this->prefix . 'feed`.id),'- . 'cache_nbUnreads=(SELECT COUNT(e2.id) FROM `' . $this->prefix . 'entry` e2 WHERE e2.id_feed=`' . $this->prefix . 'feed`.id AND e2.is_read=0),'- . 'lastUpdate=?, error=? '+ . 'SET `cache_nbEntries`=(SELECT COUNT(e1.id) FROM `' . $this->prefix . 'entry` e1 WHERE e1.id_feed=`' . $this->prefix . 'feed`.id),'+ . '`cache_nbUnreads`=(SELECT COUNT(e2.id) FROM `' . $this->prefix . 'entry` e2 WHERE e2.id_feed=`' . $this->prefix . 'feed`.id AND e2.is_read=0),'+ . '`lastUpdate`=?, error=? '. 'WHERE id=?';} else {$sql = 'UPDATE `' . $this->prefix . 'feed` '- . 'SET lastUpdate=?, error=? '+ . 'SET `lastUpdate`=?, error=? '. 'WHERE id=?';}@@ -226,10 +226,10 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {if ($defaultCacheDuration < 0) {$defaultCacheDuration = 2147483647;}- $sql = 'SELECT id, url, name, website, lastUpdate, pathEntries, httpAuth, keep_history, ttl '+ $sql = 'SELECT id, url, name, website, `lastUpdate`, `pathEntries`, `httpAuth`, keep_history, ttl '. 'FROM `' . $this->prefix . 'feed` '- . 'WHERE ttl <> -1 AND lastUpdate < (' . (time() + 60) . '-(CASE WHEN ttl=-2 THEN ' . intval($defaultCacheDuration) . ' ELSE ttl END)) '- . 'ORDER BY lastUpdate';+ . 'WHERE ttl <> -1 AND `lastUpdate` < (' . (time() + 60) . '-(CASE WHEN ttl=-2 THEN ' . intval($defaultCacheDuration) . ' ELSE ttl END)) '+ . 'ORDER BY `lastUpdate`';$stm = $this->bd->prepare($sql);if (!($stm && $stm->execute())) {$sql2 = 'ALTER TABLE `' . $this->prefix . 'feed` ADD COLUMN ttl INT NOT NULL DEFAULT -2'; //v0.7.3@@ -282,7 +282,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {. 'FROM `' . $this->prefix . 'entry` e '. 'GROUP BY e.id_feed'. ') x ON x.id_feed=f.id '- . 'SET f.cache_nbEntries=x.nbEntries, f.cache_nbUnreads=x.nbUnreads';+ . 'SET f.`cache_nbEntries`=x.nbEntries, f.`cache_nbUnreads`=x.nbUnreads';$stm = $this->bd->prepare($sql);if ($stm && $stm->execute()) {@@ -308,7 +308,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {$affected = $stm->rowCount();$sql = 'UPDATE `' . $this->prefix . 'feed` '- . 'SET cache_nbEntries=0, cache_nbUnreads=0 WHERE id=?';+ . 'SET `cache_nbEntries`=0, `cache_nbUnreads`=0 WHERE id=?';$values = array($id);$stm = $this->bd->prepare($sql);if (!($stm && $stm->execute($values))) {@@ -326,7 +326,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {$sql = 'DELETE FROM `' . $this->prefix . 'entry` '. 'WHERE id_feed=:id_feed AND id<=:id_max '. 'AND is_favorite=0 ' //Do not remove favourites- . 'AND lastSeen < (SELECT maxLastSeen FROM (SELECT (MAX(e3.lastSeen)-99) AS maxLastSeen FROM `' . $this->prefix . 'entry` e3 WHERE e3.id_feed=:id_feed) recent) ' //Do not remove the most newly seen articles, plus a few seconds of tolerance+ . 'AND `lastSeen` < (SELECT maxLastSeen FROM (SELECT (MAX(e3.`lastSeen`)-99) AS maxLastSeen FROM `' . $this->prefix . 'entry` e3 WHERE e3.id_feed=:id_feed) recent) ' //Do not remove the most newly seen articles, plus a few seconds of tolerance. 'AND id NOT IN (SELECT id FROM (SELECT e2.id FROM `' . $this->prefix . 'entry` e2 WHERE e2.id_feed=:id_feed ORDER BY id DESC LIMIT :keep) keep)'; //Double select: MySQL doesn't support 'LIMIT & IN/ALL/ANY/SOME subquery'$stm = $this->bd->prepare($sql);diff --git a/app/Models/FeedDAOSQLite.php b/app/Models/FeedDAOSQLite.phpindex 7599fda53..440ae74da 100644--- a/app/Models/FeedDAOSQLite.php+++ b/app/Models/FeedDAOSQLite.php@@ -4,8 +4,8 @@ class FreshRSS_FeedDAOSQLite extends FreshRSS_FeedDAO {public function updateCachedValues() { //For one single feed, call updateLastUpdate($id)$sql = 'UPDATE `' . $this->prefix . 'feed` '- . 'SET cache_nbEntries=(SELECT COUNT(e1.id) FROM `' . $this->prefix . 'entry` e1 WHERE e1.id_feed=`' . $this->prefix . 'feed`.id),'- . 'cache_nbUnreads=(SELECT COUNT(e2.id) FROM `' . $this->prefix . 'entry` e2 WHERE e2.id_feed=`' . $this->prefix . 'feed`.id AND e2.is_read=0)';+ . 'SET `cache_nbEntries`=(SELECT COUNT(e1.id) FROM `' . $this->prefix . 'entry` e1 WHERE e1.id_feed=`' . $this->prefix . 'feed`.id),'+ . '`cache_nbUnreads`=(SELECT COUNT(e2.id) FROM `' . $this->prefix . 'entry` e2 WHERE e2.id_feed=`' . $this->prefix . 'feed`.id AND e2.is_read=0)';$stm = $this->bd->prepare($sql);if ($stm && $stm->execute()) {return $stm->rowCount();diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.phpindex 93a22fc3d..78b44ea7f 100644--- a/lib/Minz/ModelPdo.php+++ b/lib/Minz/ModelPdo.php@@ -156,9 +156,6 @@ class MinzPDOMSQLite extends MinzPDO {class MinzPDOPGSQL extends MinzPDO {protected function compatibility($statement) {- return str_replace(- array('`', 'lastUpdate', 'pathEntries', 'httpAuth', 'cache_nbEntries', 'cache_nbUnreads', 'lastSeen'),- array('"', '"lastUpdate"', '"pathEntries"', '"httpAuth"', '"cache_nbEntries"', '"cache_nbUnreads"', '"lastSeen"'),- $statement);+ return str_replace('`', '"', $statement);}}