Pārlūkot izejas kodu

Mise à jour de f.url en base de données lorsque SimplePie découvre que l'adresse a changé

Et correction problème favicon lorsque l'adresse du flux a changé du
point de vue de SimplePie.
Plus petites optimisations.
Alexandre Alapetite 12 gadi atpakaļ
vecāks
revīzija
43fd0a5439

+ 1 - 1
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());
 				}
 			}

+ 10 - 17
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);

+ 12 - 6
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);