A free, self-hostable news aggregator…
Mise à jour de f.url en base de données lorsque SimplePie découvre que l'adresse a changé
Alexandre Alapetite43fd0a543900
diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.phpindex 1c3c56c4d..26f3422ca 100755--- a/app/Controllers/entryController.php+++ b/app/Controllers/entryController.php@@ -131,7 +131,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController {$nb = $feedDAO->cleanOldEntries($feed->id(), $date_min, $feedHistory);if ($nb > 0) {$nbTotal += $nb;- Minz_Log::record($nb . ' old entries cleaned in feed ' . $feed->id(), Minz_Log::DEBUG);+ Minz_Log::record($nb . ' old entries cleaned in feed [' . $feed->url() . ']', Minz_Log::DEBUG);$feedDAO->updateLastUpdate($feed->id());}}diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.phpindex dc8a854a9..ca230232f 100755--- a/app/Controllers/feedController.php+++ b/app/Controllers/feedController.php@@ -20,15 +20,6 @@ class FreshRSS_feed_Controller extends Minz_ActionController {$this->catDAO->checkDefault ();}- private static function entryDateComparer($e1, $e2) {- $d1 = $e1->date(true);- $d2 = $e2->date(true);- if ($d1 === $d2) {- return 0;- }- return ($d1 < $d2) ? -1 : 1;- }-public function addAction () {@set_time_limit(300);@@ -55,7 +46,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {}$feed->_httpAuth ($httpAuth);- $feed->load ();+ $feed->load(true);$feedDAO = new FreshRSS_FeedDAO ();$values = array (@@ -91,8 +82,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {$is_read = $this->view->conf->markUponReception() === 'yes' ? 1 : 0;$entryDAO = new FreshRSS_EntryDAO ();- $entries = $feed->entries ();- usort($entries, 'self::entryDateComparer');+ $entries = array_reverse($feed->entries()); //We want chronological order and SimplePie uses reverse order// on calcule la date des articles les plus anciens qu'on accepte$nb_month_old = $this->view->conf->oldEntries ();@@ -199,10 +189,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController {$flux_update = 0;foreach ($feeds as $feed) {try {- $feed->load ();- $feed->faviconPrepare();- $entries = $feed->entries ();- usort($entries, 'self::entryDateComparer');+ $url = $feed->url();+ $feed->load(false);+ $entries = array_reverse($feed->entries()); //We want chronological order and SimplePie uses reverse order$is_read = $this->view->conf->markUponReception() === 'yes' ? 1 : 0;@@ -231,7 +220,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {if (($feedHistory >= 0) && (rand(0, 30) === 1)) {$nb = $feedDAO->cleanOldEntries ($feed->id (), $date_min, max($feedHistory, count($entries) + 10));if ($nb > 0) {- Minz_Log::record ($nb . ' old entries cleaned in feed ' . $feed->id (), Minz_Log::DEBUG);+ Minz_Log::record ($nb . ' old entries cleaned in feed [' . $feed->url() . ']', Minz_Log::DEBUG);}}@@ -239,6 +228,10 @@ class FreshRSS_feed_Controller extends Minz_ActionController {$feedDAO->updateLastUpdate ($feed->id ());$feedDAO->commit ();$flux_update++;+ if ($feed->url() !== $url) { //URL has changed (auto-discovery)+ $feedDAO->updateFeed($feed->id(), array('url' => $feed->url()));+ }+ $feed->faviconPrepare();} catch (FreshRSS_Feed_Exception $e) {Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE);$feedDAO->updateLastUpdate ($feed->id (), 1);diff --git a/app/Models/Feed.php b/app/Models/Feed.phpindex 4f90b9872..0f467f776 100644--- a/app/Models/Feed.php+++ b/app/Models/Feed.php@@ -16,6 +16,7 @@ class FreshRSS_Feed extends Minz_Model {private $httpAuth = '';private $error = false;private $keep_history = -2;+ private $hash = null;public function __construct ($url, $validate=true) {if ($validate) {@@ -30,7 +31,10 @@ class FreshRSS_Feed extends Minz_Model {}public function hash() {- return hash('crc32b', Minz_Configuration::salt() . $this->url);+ if ($this->hash === null) {+ $this->hash = hash('crc32b', Minz_Configuration::salt() . $this->url);+ }+ return $this->hash;}public function url () {@@ -184,7 +188,7 @@ class FreshRSS_Feed extends Minz_Model {$this->nbEntries = intval($value);}- public function load () {+ public function load ($loadDetails = false) {if (!is_null ($this->url)) {if (CACHE_PATH === false) {throw new Minz_FileNotExistException (@@ -256,11 +260,13 @@ class FreshRSS_Feed extends Minz_Model {$this->_url ($subscribe_url);}- $title = htmlspecialchars(html_only_entity_decode($feed->get_title()), ENT_COMPAT, 'UTF-8');- $this->_name (!is_null ($title) ? $title : $this->url);+ if ($loadDetails) {+ $title = htmlspecialchars(html_only_entity_decode($feed->get_title()), ENT_COMPAT, 'UTF-8');+ $this->_name (!is_null ($title) ? $title : $this->url);- $this->_website(html_only_entity_decode($feed->get_link()));- $this->_description(html_only_entity_decode($feed->get_description()));+ $this->_website(html_only_entity_decode($feed->get_link()));+ $this->_description(html_only_entity_decode($feed->get_description()));+ }// et on charge les articles du flux$this->loadEntries ($feed);