From 5129ed710bbd0e493a0365ee7043d8abfa00e950 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Wed, 18 Jan 2023 13:26:14 -0500 Subject: [PATCH] Small fixe-ups - Process subscription addition in Miniflux correctly - Honour user stricture when updating feeds --- lib/Database.php | 10 +++++----- lib/REST/Miniflux/V1.php | 16 +++++++--------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/Database.php b/lib/Database.php index c28571f..24ffed1 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -1217,17 +1217,17 @@ class Database { public function subscriptionUpdate(?string $user, $subID, bool $throwError = false): bool { // check to make sure the feed exists if (!V::id($subID)) { - throw new Db\ExceptionInput("typeViolation", ["action" => __FUNCTION__, "field" => "feed", 'id' => $id, 'type' => "int > 0"]); + throw new Db\ExceptionInput("typeViolation", ["action" => __FUNCTION__, "field" => "feed", 'id' => $subID, 'type' => "int > 0"]); } $f = $this->db->prepareArray( "SELECT url, las_mod as modified, etag, err_count, scrape as scrapers, keep_rule, block_rule FROM arsse_subscriptions - where id = ?", - ["int"] - )->run($subID)->getRow(); + where id = ? and owner = coalesce(?, owner)", + ["int", "str"] + )->run($subID, $user)->getRow(); if (!$f) { - throw new Db\ExceptionInput("subjectMissing", ["action" => __FUNCTION__, "field" => "feed", 'id' => $id]); + throw new Db\ExceptionInput("subjectMissing", ["action" => __FUNCTION__, "field" => "feed", 'id' => $subID]); } // determine whether the feed's items should be scraped for full content from the source Web site $scrape = (Arsse::$conf->fetchEnableScraping && ($scrapeOverride ?? $f['scrapers'])); diff --git a/lib/REST/Miniflux/V1.php b/lib/REST/Miniflux/V1.php index 2b981c5..0806144 100644 --- a/lib/REST/Miniflux/V1.php +++ b/lib/REST/Miniflux/V1.php @@ -813,16 +813,14 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler { } protected function createFeed(array $data): ResponseInterface { + $properties = [ + 'folder' => $data['category_id'] - 1, + 'scrape' => (bool) $data['crawler'], + 'keep_rule' => $data['keeplist_rules'], + 'block_rule' => $data['blocklist_rules'], + ]; try { - Arsse::$db->feedAdd($data['feed_url'], (string) $data['username'], (string) $data['password'], false, (bool) $data['crawler']); - $tr = Arsse::$db->begin(); - $id = Arsse::$db->subscriptionAdd(Arsse::$user->id, $data['feed_url'], (string) $data['username'], (string) $data['password'], false, (bool) $data['crawler']); - Arsse::$db->subscriptionPropertiesSet(Arsse::$user->id, $id, ['folder' => $data['category_id'] - 1, 'scrape' => (bool) $data['crawler']]); - $tr->commit(); - if (strlen($data['keeplist_rules'] ?? "") || strlen($data['blocklist_rules'] ?? "")) { - // we do rules separately so as not to tie up the database - Arsse::$db->subscriptionPropertiesSet(Arsse::$user->id, $id, ['keep_rule' => $data['keeplist_rules'], 'block_rule' => $data['blocklist_rules']]); - } + $id = Arsse::$db->subscriptionAdd(Arsse::$user->id, $data['feed_url'], (string) $data['username'], (string) $data['password'], false, $properties); } catch (FeedException $e) { $msg = [ 10502 => "Fetch404",