diff options
| author | 2018-02-24 12:02:16 +0100 | |
|---|---|---|
| committer | 2018-02-24 12:02:16 +0100 | |
| commit | 5ebeb9e3e5d46195a83211140c1d28d58be19b2a (patch) | |
| tree | 6b93ae52a1206b6045087f893dde67a04b4e1bda /app/Models/FeedDAO.php | |
| parent | 889888f20eb6f3dd476b78c0f59672f7c7962354 (diff) | |
| parent | 294f9336ad0f315574c74d6b527b1bb8a280f3c6 (diff) | |
Merge pull request #1786 from FreshRSS/dev1.10.0
FreshRSS 1.10.0
Diffstat (limited to 'app/Models/FeedDAO.php')
| -rw-r--r-- | app/Models/FeedDAO.php | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index 0de6d98be..011b3d112 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, ?, ?)'; $stm = $this->bd->prepare($sql); $valuesTmp['url'] = safe_ascii($valuesTmp['url']); @@ -32,6 +32,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable { substr($valuesTmp['description'], 0, 1023), $valuesTmp['lastUpdate'], base64_encode($valuesTmp['httpAuth']), + FreshRSS_Feed::KEEP_HISTORY_DEFAULT, + FreshRSS_Feed::TTL_DEFAULT, ); if ($stm && $stm->execute($values)) { @@ -249,18 +251,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)); } @@ -409,8 +407,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable { $myFeed->_pathEntries(isset($dao['pathEntries']) ? $dao['pathEntries'] : ''); $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->_keepHistory(isset($dao['keep_history']) ? $dao['keep_history'] : FreshRSS_Feed::KEEP_HISTORY_DEFAULT); + $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 +419,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)); + } + } } |
