aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2018-05-20 12:17:08 +0200
committerGravatar GitHub <noreply@github.com> 2018-05-20 12:17:08 +0200
commit6881d362b1ff4e153580ee7bf5cdf80a4428516d (patch)
treee5cc70f85e84e6273f55004f4ae3bccfcbe02f58 /app/Models
parent967dc041a7da1f4ed42cd1b32719641bcbea3e0d (diff)
Detection of non-unique GUIDs (#1887)
* Detection of non-unique GUIDs Some feeds are using GUIDs, but fail to make them unique. Example: https://www.kbh-sprogcenter.dk/en/category/danish-break/feed/ This patch detects non-unique GUIDs, and disable GUIDs in that specific case. * Add state and log
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/Feed.php25
1 files changed, 24 insertions, 1 deletions
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 5ed9b1834..7eb079f15 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -335,6 +335,8 @@ class FreshRSS_Feed extends Minz_Model {
public function loadEntries($feed) {
$entries = array();
+ $guids = array();
+ $hasUniqueGuids = true;
foreach ($feed->get_items() as $item) {
$title = html_only_entity_decode(strip_tags($item->get_title()));
@@ -375,9 +377,13 @@ class FreshRSS_Feed extends Minz_Model {
}
}
+ $guid = $item->get_id(false, false);
+ $hasUniqueGuids &= empty($guids['_' . $guid]);
+ $guids['_' . $guid] = true;
+
$entry = new FreshRSS_Entry(
$this->id(),
- $item->get_id(false, false),
+ $guid,
$title === null ? '' : $title,
$author === null ? '' : html_only_entity_decode(strip_tags($author->name == null ? $author->email : $author->name)),
$content === null ? '' : $content,
@@ -392,6 +398,23 @@ class FreshRSS_Feed extends Minz_Model {
unset($item);
}
+ $hasBadGuids = $this->attributes('hasBadGuids');
+ if ($hasBadGuids != !$hasUniqueGuids) {
+ $hasBadGuids = !$hasUniqueGuids;
+ if ($hasBadGuids) {
+ Minz_Log::warning('Feed has invalid GUIDs: ' . $this->url);
+ } else {
+ Minz_Log::warning('Feed has valid GUIDs again: ' . $this->url);
+ }
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ $feedDAO->updateFeedAttribute($this, 'hasBadGuids', $hasBadGuids);
+ }
+ if (!$hasUniqueGuids) {
+ foreach ($entries as $entry) {
+ $entry->_guid('');
+ }
+ }
+
$this->entries = $entries;
}