From 2332cd52a36e76bd563da1fb1f2d2aee9c250913 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Sun, 4 Jun 2017 08:15:10 -0400 Subject: [PATCH] Cleanup --- composer.json | 2 ++ composer.lock | 6 ++-- lib/Database.php | 44 ++++++++++++------------ tests/REST/NextCloudNews/TestNCNV1_2.php | 2 +- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index 1c3eb17b..874963db 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,8 @@ "require": { "php": "^7.0", "ext-intl": "*", + "ext-json": "*", + "ext-hash": "*", "fguillot/picofeed": ">=0.1.31", "jkingweb/druuid": "^3.0.0", "phpseclib/phpseclib": "^2.0.4", diff --git a/composer.lock b/composer.lock index b4aa0a60..71364999 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "716302e991c06ae6308829749b16a078", + "content-hash": "16548deb9ff155dc6c48bbfe664bf4a0", "packages": [ { "name": "fguillot/picofeed", @@ -1787,7 +1787,9 @@ "prefer-lowest": false, "platform": { "php": "^7.0", - "ext-intl": "*" + "ext-intl": "*", + "ext-json": "*", + "ext-hash": "*" }, "platform-dev": [] } diff --git a/lib/Database.php b/lib/Database.php index a7172f26..78821a25 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -449,28 +449,6 @@ class Database { return $out; } - public function articleStarredCount(string $user, array $context = []): int { - if(!Data::$user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]); - return $this->db->prepare("SELECT count(*) from arsse_marks where owner is ? and starred is 1", "str")->run($user)->getValue(); - } - - public function editionLatest(string $user, array $context = []): int { - if(!Data::$user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]); - if(array_key_exists("subscription", $context)) { - $id = $context['subscription']; - $sub = $this->subscriptionValidateId($user, $id); - return (int) $this->db->prepare( - "SELECT max(arsse_editions.id) - from arsse_editions - left join arsse_articles on article is arsse_articles.id - left join arsse_feeds on arsse_articles.feed is arsse_feeds.id - where arsse_feeds.id is ?", - "int" - )->run($sub['feed'])->getValue(); - } - return (int) $this->db->prepare("SELECT max(id) from arsse_editions")->run()->getValue(); - } - public function feedListStale(): array { $feeds = $this->db->prepare("SELECT id from arsse_feeds where next_fetch <= CURRENT_TIMESTAMP")->run()->getAll(); return array_column($feeds,'id'); @@ -608,4 +586,26 @@ class Database { 'int', $tId, $tHashUT, $tHashUC, $tHashTC )->run($feedID, $ids, $hashesUT, $hashesUC, $hashesTC); } + + public function articleStarredCount(string $user, array $context = []): int { + if(!Data::$user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]); + return $this->db->prepare("SELECT count(*) from arsse_marks where owner is ? and starred is 1", "str")->run($user)->getValue(); + } + + public function editionLatest(string $user, array $context = []): int { + if(!Data::$user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]); + if(array_key_exists("subscription", $context)) { + $id = $context['subscription']; + $sub = $this->subscriptionValidateId($user, $id); + return (int) $this->db->prepare( + "SELECT max(arsse_editions.id) + from arsse_editions + left join arsse_articles on article is arsse_articles.id + left join arsse_feeds on arsse_articles.feed is arsse_feeds.id + where arsse_feeds.id is ?", + "int" + )->run($sub['feed'])->getValue(); + } + return (int) $this->db->prepare("SELECT max(id) from arsse_editions")->run()->getValue(); + } } \ No newline at end of file diff --git a/tests/REST/NextCloudNews/TestNCNV1_2.php b/tests/REST/NextCloudNews/TestNCNV1_2.php index f0834f56..7e85a4a4 100644 --- a/tests/REST/NextCloudNews/TestNCNV1_2.php +++ b/tests/REST/NextCloudNews/TestNCNV1_2.php @@ -393,7 +393,7 @@ class TestNCNV1_2 extends \PHPUnit\Framework\TestCase { $this->assertEquals($exp, $this->h->dispatch(new Request("GET", "/feeds/update", json_encode($in[2]), 'application/json'))); $exp = new Response(422); $this->assertEquals($exp, $this->h->dispatch(new Request("GET", "/feeds/update", json_encode($in[3]), 'application/json'))); - // retrieving the list when not an admin fails + // updating a feed when not an admin fails Phake::when(Data::$user)->rightsGet->thenReturn(0); $exp = new Response(403); $this->assertEquals($exp, $this->h->dispatch(new Request("GET", "/feeds/update", json_encode($in[0]), 'application/json')));