Skip to content

A free, self-hostable news aggregator…

Fix muting of feeds gone with HTTP 410 (#9391)

Nikolai Shcheglova93bd27b7d5e
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index 625a329b6..51fe49458 100644
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -606,8 +606,8 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
if ($e->getCode() === 410) {
// HTTP 410 Gone
Minz_Log::warning('Muting gone feed: ' . $feed->url(false));
- $feedDAO->mute($feed->id(), true);
- $feed->_ttl(-abs($feed->ttl())); // Replicate behavior of line above which acts directly into the DB
+ $feed->_mute(true);
+ $feedDAO->updateFeed($feed->id(), ['ttl' => $feed->ttl(raw: true)]); // Also when the feed has the default TTL (0)
}
$feed->unlock();
continue;
diff --git a/app/Exceptions/FeedException.php b/app/Exceptions/FeedException.php
index 26d042f6f..1389c280e 100644
--- a/app/Exceptions/FeedException.php
+++ b/app/Exceptions/FeedException.php
@@ -3,4 +3,11 @@ declare(strict_types=1);
class FreshRSS_Feed_Exception extends Minz_Exception {
+ /**
+ * @param int $code The HTTP status code when known, e.g. 410 Gone, which mutes the feed
+ */
+ public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null) {
+ parent::__construct($message, previous: $previous);
+ $this->code = $code; // Minz_Exception would reset it, keeping only its own error levels
+ }
}
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index d8530fbc8..1e09c45b5 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -261,24 +261,6 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
}
}
- public function mute(int $id, bool $value = true): int|false {
- $sign = $value ? '-' : '';
- $sql = <<<SQL
- UPDATE `_feed`
- SET ttl = {$sign}ABS(ttl)
- WHERE id = :id
- SQL;
- $stm = $this->pdo->prepare($sql);
- if ($stm !== false &&
- $stm->bindValue(':id', $id, PDO::PARAM_INT) &&
- $stm->execute()) {
- return $stm->rowCount();
- }
- $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
- Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
- return false;
- }
-
public function changeCategory(int $idOldCat, int $idNewCat): int|false {
$catDAO = FreshRSS_Factory::createCategoryDao();
$newCat = $catDAO->searchById($idNewCat);
diff --git a/tests/app/Exceptions/FeedExceptionTest.php b/tests/app/Exceptions/FeedExceptionTest.php
new file mode 100644
index 000000000..a4f6de60b
--- /dev/null
+++ b/tests/app/Exceptions/FeedExceptionTest.php
@@ -0,0 +1,14 @@
+<?php
+declare(strict_types=1);
+
+final class FeedExceptionTest extends \PHPUnit\Framework\TestCase {
+
+ public function test_keepsHttpStatusCode(): void {
+ $previous = new RuntimeException('previous');
+ $e = new FreshRSS_Feed_Exception('Gone', 410, $previous);
+ self::assertSame(410, $e->getCode()); // feedController mutes a feed on HTTP 410 Gone
+ self::assertSame('Gone', $e->getMessage());
+ self::assertSame($previous, $e->getPrevious());
+ self::assertSame(0, (new FreshRSS_Feed_Exception())->getCode());
+ }
+}