summaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexis Degrugillier <aledeg@users.noreply.github.com> 2018-01-01 20:34:06 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2018-01-01 20:34:06 +0100
commit8c2113f9e6eb86b630a4e861513229d7abf219b8 (patch)
tree6e9ca68cf291a21d573f82ff7818c66e40a7ec30 /app/Models
parente73fae159168b1ed9c0469e1d5bce55a3ef1f911 (diff)
Add mute strategy configuration (#1750)
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/CategoryDAO.php5
-rw-r--r--app/Models/EntryDAO.php40
-rw-r--r--app/Models/Feed.php23
-rw-r--r--app/Models/FeedDAO.php33
4 files changed, 70 insertions, 31 deletions
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index f219c275f..68db17db3 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -106,13 +106,14 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchable
public 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`, f.ttl ')
. 'FROM `' . $this->prefix . 'category` c '
. 'LEFT OUTER JOIN `' . $this->prefix . 'feed` f ON f.category=c.id '
+ . 'WHERE f.priority >= :priority_normal '
. 'GROUP BY f.id, c_id '
. 'ORDER BY c.name, f.name';
$stm = $this->bd->prepare($sql);
- $stm->execute();
+ $stm->execute(array(':priority_normal' => FreshRSS_Feed::PRIORITY_NORMAL));
return self::daoToCategoryPrepopulated($stm->fetchAll(PDO::FETCH_ASSOC));
} else {
$sql = 'SELECT * FROM `' . $this->prefix . 'category` ORDER BY name';
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index e8b6dcdae..9e291f4ed 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -726,23 +726,23 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$values = array();
switch ($type) {
case 'a':
- $where .= 'f.priority > 0 ';
- $joinFeed = true;
+ $where .= 'f.priority > ' . FreshRSS_Feed::PRIORITY_NORMAL . ' ';
break;
case 's': //Deprecated: use $state instead
- $where .= 'e.is_favorite=1 ';
+ $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_NORMAL . ' ';
+ $where .= 'AND e.is_favorite=1 ';
break;
case 'c':
- $where .= 'f.category=? ';
+ $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_NORMAL . ' ';
+ $where .= 'AND f.category=? ';
$values[] = intval($id);
- $joinFeed = true;
break;
case 'f':
$where .= 'e.id_feed=? ';
$values[] = intval($id);
break;
case 'A':
- $where .= '1=1 ';
+ $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_NORMAL . ' ';
break;
default:
throw new FreshRSS_EntriesGetter_Exception('Bad type in Entry->listByType: [' . $type . ']!');
@@ -752,7 +752,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
return array(array_merge($values, $searchValues),
'SELECT e.id FROM `' . $this->prefix . 'entry` e '
- . ($joinFeed ? 'INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed=f.id ' : '')
+ . 'INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id '
. 'WHERE ' . $where
. $search
. 'ORDER BY e.id ' . $order
@@ -873,12 +873,28 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
}
public function countUnreadReadFavorites() {
- $sql = 'SELECT c FROM ('
- . 'SELECT COUNT(id) AS c, 1 as o FROM `' . $this->prefix . 'entry` WHERE is_favorite=1 '
- . 'UNION SELECT COUNT(id) AS c, 2 AS o FROM `' . $this->prefix . 'entry` WHERE is_favorite=1 AND is_read=0'
- . ') u ORDER BY o';
+ $sql = <<<SQL
+ SELECT c
+ FROM (
+ SELECT COUNT(e1.id) AS c
+ , 1 AS o
+ FROM `{$this->prefix}entry` AS e1
+ JOIN `{$this->prefix}feed` AS f1 ON e1.id_feed = f1.id
+ WHERE e1.is_favorite = 1
+ AND f1.priority >= :priority_normal
+ UNION
+ SELECT COUNT(e2.id) AS c
+ , 2 AS o
+ FROM `{$this->prefix}entry` AS e2
+ JOIN `{$this->prefix}feed` AS f2 ON e2.id_feed = f2.id
+ WHERE e2.is_favorite = 1
+ AND e2.is_read = 0
+ AND f2.priority >= :priority_normal
+ ) u
+ORDER BY o
+SQL;
$stm = $this->bd->prepare($sql);
- $stm->execute();
+ $stm->execute(array(':priority_normal' => FreshRSS_Feed::PRIORITY_NORMAL));
$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
$all = empty($res[0]) ? 0 : $res[0];
$unread = empty($res[1]) ? 0 : $res[1];
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 560f7415d..216a26d44 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -1,6 +1,12 @@
<?php
class FreshRSS_Feed extends Minz_Model {
+ const PRIORITY_MAIN_STREAM = 10;
+ const PRIORITY_NORMAL = 0;
+ const PRIORITY_ARCHIVED = -10;
+
+ const TTL_DEFAULT = 0;
+
private $id = 0;
private $url;
private $category = 1;
@@ -11,12 +17,13 @@ class FreshRSS_Feed extends Minz_Model {
private $website = '';
private $description = '';
private $lastUpdate = 0;
- private $priority = 10;
+ private $priority = self::PRIORITY_MAIN_STREAM;
private $pathEntries = '';
private $httpAuth = '';
private $error = false;
private $keep_history = -2;
- private $ttl = -2;
+ private $ttl = self::TTL_DEFAULT;
+ private $mute = false;
private $hash = null;
private $lockPath = '';
private $hubUrl = '';
@@ -104,9 +111,12 @@ class FreshRSS_Feed extends Minz_Model {
public function ttl() {
return $this->ttl;
}
+ public function mute() {
+ return $this->mute;
+ }
// public function ttlExpire() {
// $ttl = $this->ttl;
- // if ($ttl == -2) { //Default
+ // if ($ttl == self::TTL_DEFAULT) { //Default
// $ttl = FreshRSS_Context::$user_conf->ttl_default;
// }
// if ($ttl == -1) { //Never
@@ -198,8 +208,7 @@ class FreshRSS_Feed extends Minz_Model {
$this->lastUpdate = $value;
}
public function _priority($value) {
- $value = intval($value);
- $this->priority = $value >= 0 ? $value : 10;
+ $this->priority = intval($value);
}
public function _pathEntries($value) {
$this->pathEntries = $value;
@@ -219,8 +228,8 @@ class FreshRSS_Feed extends Minz_Model {
public function _ttl($value) {
$value = intval($value);
$value = min($value, 100000000);
- $value = max($value, -2);
- $this->ttl = $value;
+ $this->ttl = abs($value);
+ $this->mute = $value < self::TTL_DEFAULT;
}
public function _nbNotRead($value) {
$this->nbNotRead = intval($value);
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index 0de6d98be..deda02c63 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -18,7 +18,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
ttl
)
VALUES
- (?, ?, ?, ?, ?, ?, 10, ?, 0, -2, -2)';
+ (?, ?, ?, ?, ?, ?, 10, ?, 0, -2, ?)';
$stm = $this->bd->prepare($sql);
$valuesTmp['url'] = safe_ascii($valuesTmp['url']);
@@ -32,6 +32,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
substr($valuesTmp['description'], 0, 1023),
$valuesTmp['lastUpdate'],
base64_encode($valuesTmp['httpAuth']),
+ FreshRSS_Feed::TTL_DEFAULT,
);
if ($stm && $stm->execute($values)) {
@@ -249,18 +250,14 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
* Use $defaultCacheDuration == -1 to return all feeds, without filtering them by TTL.
*/
public function listFeedsOrderUpdate($defaultCacheDuration = 3600) {
+ $this->updateTTL();
$sql = 'SELECT id, url, name, website, `lastUpdate`, `pathEntries`, `httpAuth`, keep_history, ttl '
. 'FROM `' . $this->prefix . 'feed` '
- . ($defaultCacheDuration < 0 ? '' : 'WHERE ttl <> -1 AND `lastUpdate` < (' . (time() + 60) . '-(CASE WHEN ttl=-2 THEN ' . intval($defaultCacheDuration) . ' ELSE ttl END)) ')
+ . ($defaultCacheDuration < 0 ? '' : 'WHERE ttl >= ' . FreshRSS_Feed::TTL_DEFAULT
+ . ' AND `lastUpdate` < (' . (time() + 60) . '-(CASE WHEN ttl=' . FreshRSS_Feed::TTL_DEFAULT . ' 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
- $stm = $this->bd->prepare($sql2);
- $stm->execute();
- $stm = $this->bd->prepare($sql);
- $stm->execute();
- }
+ $stm->execute();
return self::daoToFeed($stm->fetchAll(PDO::FETCH_ASSOC));
}
@@ -410,7 +407,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$myFeed->_httpAuth(isset($dao['httpAuth']) ? base64_decode($dao['httpAuth']) : '');
$myFeed->_error(isset($dao['error']) ? $dao['error'] : 0);
$myFeed->_keepHistory(isset($dao['keep_history']) ? $dao['keep_history'] : -2);
- $myFeed->_ttl(isset($dao['ttl']) ? $dao['ttl'] : -2);
+ $myFeed->_ttl(isset($dao['ttl']) ? $dao['ttl'] : FreshRSS_Feed::TTL_DEFAULT);
$myFeed->_nbNotRead(isset($dao['cache_nbUnreads']) ? $dao['cache_nbUnreads'] : 0);
$myFeed->_nbEntries(isset($dao['cache_nbEntries']) ? $dao['cache_nbEntries'] : 0);
if (isset($dao['id'])) {
@@ -421,4 +418,20 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
return $list;
}
+
+ public function updateTTL() {
+ $sql = <<<SQL
+UPDATE `{$this->prefix}feed`
+ SET ttl = :new_value
+ WHERE ttl = :old_value
+SQL;
+ $stm = $this->bd->prepare($sql);
+ if (!($stm && $stm->execute(array(':new_value' => FreshRSS_Feed::TTL_DEFAULT, ':old_value' => -2)))) {
+ $sql2 = 'ALTER TABLE `' . $this->prefix . 'feed` ADD COLUMN ttl INT NOT NULL DEFAULT ' . FreshRSS_Feed::TTL_DEFAULT; //v0.7.3
+ $stm = $this->bd->prepare($sql2);
+ $stm->execute();
+ } else {
+ $stm->execute(array(':new_value' => -3600, ':old_value' => -1));
+ }
+ }
}