aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2018-03-01 19:25:40 +0100
committerGravatar GitHub <noreply@github.com> 2018-03-01 19:25:40 +0100
commit5872a11eb75958f12fd37c144a26c12c693d8a4a (patch)
treeb6d3064c7669270c1f947975ba7272a8f19193aa /app/Models
parent0c066cb4285feb54cd9947c01dd759afdc0f37fb (diff)
cleanOldEntries call autoUpdateDb (#1804)
* cleanOldEntries call autoUpdateDb https://github.com/FreshRSS/FreshRSS/issues/1803 * Fix feedDAO autoUpdateDb * Move cleanOldEntries to EntryDAO Only the entry table is concerned
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/EntryDAO.php27
-rw-r--r--app/Models/FeedDAO.php24
2 files changed, 27 insertions, 24 deletions
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 70135e7a0..8cdebedc5 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -560,6 +560,33 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
return $affected;
}
+ public function cleanOldEntries($id_feed, $date_min, $keep = 15) { //Remember to call updateCachedValue($id_feed) or updateCachedValues() just after
+ $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 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);
+
+ if ($stm) {
+ $id_max = intval($date_min) . '000000';
+ $stm->bindParam(':id_feed', $id_feed, PDO::PARAM_INT);
+ $stm->bindParam(':id_max', $id_max, PDO::PARAM_STR);
+ $stm->bindParam(':keep', $keep, PDO::PARAM_INT);
+ }
+
+ if ($stm && $stm->execute()) {
+ return $stm->rowCount();
+ } else {
+ $info = $stm == null ? array(0 => '', 1 => '', 2 => 'syntax error') : $stm->errorInfo();
+ if ($this->autoUpdateDb($info)) {
+ return $this->cleanOldEntries($id_feed, $date_min, $keep);
+ }
+ Minz_Log::error('SQL error cleanOldEntries: ' . $info[2]);
+ return false;
+ }
+ }
+
public function searchByGuid($id_feed, $guid) {
// un guid est unique pour un flux donné
$sql = 'SELECT id, guid, title, author, '
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index 011b3d112..0c25ab0ba 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -353,30 +353,6 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
return $affected;
}
- public function cleanOldEntries($id, $date_min, $keep = 15) { //Remember to call updateCachedValue($id) or updateCachedValues() just after
- $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 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);
-
- if ($stm) {
- $id_max = intval($date_min) . '000000';
- $stm->bindParam(':id_feed', $id, PDO::PARAM_INT);
- $stm->bindParam(':id_max', $id_max, PDO::PARAM_STR);
- $stm->bindParam(':keep', $keep, PDO::PARAM_INT);
- }
-
- if ($stm && $stm->execute()) {
- return $stm->rowCount();
- } else {
- $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo();
- Minz_Log::error('SQL error cleanOldEntries: ' . $info[2]);
- return false;
- }
- }
-
public static function daoToFeed($listDAO, $catID = null) {
$list = array();