aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/Feed.php26
-rw-r--r--app/Models/FeedDAO.php52
2 files changed, 55 insertions, 23 deletions
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 1fc2eebf4..6f6b83af0 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -649,15 +649,37 @@ class FreshRSS_Feed extends Minz_Model {
$this->nbPendingNotRead += $n;
}
+ /**
+ * Remember to call updateCachedValue($id_feed) or updateCachedValues() just after.
+ * @return int|false the number of lines affected, or false if not applicable
+ */
public function keepMaxUnread() {
$keepMaxUnread = $this->attributes('keep_max_n_unread');
- if ($keepMaxUnread == false) {
+ if ($keepMaxUnread === null) {
$keepMaxUnread = FreshRSS_Context::$user_conf->mark_when['max_n_unread'];
}
if ($keepMaxUnread > 0 && $this->nbNotRead(false) + $this->nbPendingNotRead > $keepMaxUnread) {
$feedDAO = FreshRSS_Factory::createFeedDao();
- $feedDAO->keepMaxUnread($this->id(), max(0, $keepMaxUnread - $this->nbPendingNotRead));
+ return $feedDAO->keepMaxUnread($this->id(), max(0, $keepMaxUnread - $this->nbPendingNotRead));
}
+ return false;
+ }
+
+ /**
+ * Applies the *mark as read upon gone* policy, if enabled.
+ * Remember to call updateCachedValue($id_feed) or updateCachedValues() just after.
+ * @return int|false the number of lines affected, or false if not applicable
+ */
+ public function markAsReadUponGone() {
+ $readUponGone = $this->attributes('read_upon_gone');
+ if ($readUponGone === null) {
+ $readUponGone = FreshRSS_Context::$user_conf->mark_when['gone'];
+ }
+ if ($readUponGone) {
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ return $feedDAO->markAsReadUponGone($this->id());
+ }
+ return false;
}
/**
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index 86ba70d5c..ec507b324 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -447,7 +447,8 @@ SQL;
}
/**
- * @return int|false
+ * Remember to call updateCachedValues() after calling this function
+ * @return int|false number of lines affected or false in case of error
*/
public function keepMaxUnread(int $id, int $n) {
//Double SELECT for MySQL workaround ERROR 1093 (HY000)
@@ -461,32 +462,41 @@ WHERE id_feed=:id_feed1 AND is_read=0 AND id <= (SELECT e3.id FROM (
OFFSET :limit) e3)
SQL;
- $stm = $this->pdo->prepare($sql);
- $stm->bindParam(':id_feed1', $id, PDO::PARAM_INT);
- $stm->bindParam(':id_feed2', $id, PDO::PARAM_INT);
- $stm->bindParam(':limit', $n, PDO::PARAM_INT);
-
- if (!$stm || !$stm->execute()) {
+ if (($stm = $this->pdo->prepare($sql)) &&
+ $stm->bindParam(':id_feed1', $id, PDO::PARAM_INT) &&
+ $stm->bindParam(':id_feed2', $id, PDO::PARAM_INT) &&
+ $stm->bindParam(':limit', $n, PDO::PARAM_INT) &&
+ $stm->execute()) {
+ return $stm->rowCount();
+ } else {
$info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error keepMaxUnread: ' . json_encode($info));
return false;
}
- $affected = $stm->rowCount();
+ }
- if ($affected > 0) {
- $sql = 'UPDATE `_feed` '
- . 'SET `cache_nbUnreads`=`cache_nbUnreads`-' . $affected
- . ' WHERE id=:id';
- $stm = $this->pdo->prepare($sql);
- $stm->bindParam(':id', $id, PDO::PARAM_INT);
- if (!($stm && $stm->execute())) {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
- Minz_Log::error('SQL error keepMaxUnread cache: ' . json_encode($info));
- return false;
- }
- }
+ /**
+ * Remember to call updateCachedValues() after calling this function
+ * @return int|false number of lines affected or false in case of error
+ */
+ public function markAsReadUponGone(int $id) {
+ //Double SELECT for MySQL workaround ERROR 1093 (HY000)
+ $sql = <<<'SQL'
+UPDATE `_entry` SET is_read=1
+WHERE id_feed=:id_feed1 AND is_read=0 AND `lastSeen` < (SELECT e3.maxlastseen FROM (
+ SELECT MAX(e2.`lastSeen`) AS maxlastseen FROM `_entry` e2 WHERE e2.id_feed = :id_feed2) e3)
+SQL;
- return $affected;
+ if (($stm = $this->pdo->prepare($sql)) &&
+ $stm->bindParam(':id_feed1', $id, PDO::PARAM_INT) &&
+ $stm->bindParam(':id_feed2', $id, PDO::PARAM_INT) &&
+ $stm->execute()) {
+ return $stm->rowCount();
+ } else {
+ $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ Minz_Log::error('SQL error markAsReadUponGone: ' . json_encode($info));
+ return false;
+ }
}
/**