1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Style fixes

This commit is contained in:
J. King 2020-12-22 16:13:12 -05:00
parent a81760e39d
commit d66cf32c1f
10 changed files with 73 additions and 105 deletions

View file

@ -660,20 +660,27 @@ class Database {
// make sure both that the prospective parent exists, and that the it is not one of its children (a circular dependence); // make sure both that the prospective parent exists, and that the it is not one of its children (a circular dependence);
// also make sure that a folder with the same prospective name and parent does not already exist: if the parent is null, // also make sure that a folder with the same prospective name and parent does not already exist: if the parent is null,
// SQL will happily accept duplicates (null is not unique), so we must do this check ourselves // SQL will happily accept duplicates (null is not unique), so we must do this check ourselves
$p = $this->db->prepare( $p = $this->db->prepareArray(
"WITH RECURSIVE "WITH RECURSIVE
target as (select ? as userid, ? as source, ? as dest, ? as new_name), target as (
folders as (SELECT id from arsse_folders join target on owner = userid and coalesce(parent,0) = source union all select arsse_folders.id as id from arsse_folders join folders on arsse_folders.parent=folders.id) SELECT ? as userid, ? as source, ? as dest, ? as new_name
". ),
"SELECT folders as (
case when ((select dest from target) is null or exists(select id from arsse_folders join target on owner = userid and coalesce(id,0) = coalesce(dest,0))) then 1 else 0 end as extant, SELECT id from arsse_folders join target on owner = userid and coalesce(parent,0) = source
case when not exists(select id from folders where id = coalesce((select dest from target),0)) then 1 else 0 end as valid, union all
case when not exists(select id from arsse_folders join target on coalesce(parent,0) = coalesce(dest,0) and name = coalesce((select new_name from target),(select name from arsse_folders join target on id = source))) then 1 else 0 end as available select arsse_folders.id as id from arsse_folders join folders on arsse_folders.parent=folders.id
", )
"str", SELECT
"strict int", case when
"int", ((select dest from target) is null or exists(select id from arsse_folders join target on owner = userid and coalesce(id,0) = coalesce(dest,0)))
"str" then 1 else 0 end as extant,
case when
not exists(select id from folders where id = coalesce((select dest from target),0))
then 1 else 0 end as valid,
case when
not exists(select id from arsse_folders join target on coalesce(parent,0) = coalesce(dest,0) and name = coalesce((select new_name from target),(select name from arsse_folders join target on id = source)))
then 1 else 0 end as available",
["str", "strict int", "int", "str"]
)->run($user, $id, $parent, $name)->getRow(); )->run($user, $id, $parent, $name)->getRow();
if (!$p['extant']) { if (!$p['extant']) {
// if the parent doesn't exist or doesn't below to the user, throw an exception // if the parent doesn't exist or doesn't below to the user, throw an exception
@ -757,7 +764,13 @@ class Database {
left join topmost as t on t.f_id = s.folder left join topmost as t on t.f_id = s.folder
join arsse_feeds as f on f.id = s.feed join arsse_feeds as f on f.id = s.feed
left join arsse_icons as i on i.id = f.icon left join arsse_icons as i on i.id = f.icon
left join (select feed, count(*) as articles from arsse_articles group by feed) as article_stats on article_stats.feed = s.feed left join (
select
feed,
count(*) as articles
from arsse_articles
group by feed
) as article_stats on article_stats.feed = s.feed
left join ( left join (
select select
subscription, subscription,
@ -1042,11 +1055,9 @@ class Database {
} }
} catch (Feed\Exception $e) { } catch (Feed\Exception $e) {
// update the database with the resultant error and the next fetch time, incrementing the error count // update the database with the resultant error and the next fetch time, incrementing the error count
$this->db->prepare( $this->db->prepareArray(
"UPDATE arsse_feeds SET updated = CURRENT_TIMESTAMP, next_fetch = ?, err_count = err_count + 1, err_msg = ? WHERE id = ?", "UPDATE arsse_feeds SET updated = CURRENT_TIMESTAMP, next_fetch = ?, err_count = err_count + 1, err_msg = ? WHERE id = ?",
'datetime', ['datetime', 'str', 'int']
'str',
'int'
)->run(Feed::nextFetchOnError($f['err_count']), $e->getMessage(), $feedID); )->run(Feed::nextFetchOnError($f['err_count']), $e->getMessage(), $feedID);
if ($throwError) { if ($throwError) {
throw $e; throw $e;
@ -1060,38 +1071,18 @@ class Database {
$qInsertEdition = $this->db->prepare("INSERT INTO arsse_editions(article) values(?)", 'int'); $qInsertEdition = $this->db->prepare("INSERT INTO arsse_editions(article) values(?)", 'int');
} }
if (sizeof($feed->newItems)) { if (sizeof($feed->newItems)) {
$qInsertArticle = $this->db->prepare( $qInsertArticle = $this->db->prepareArray(
"INSERT INTO arsse_articles(url,title,author,published,edited,guid,content,url_title_hash,url_content_hash,title_content_hash,feed) values(?,?,?,?,?,?,?,?,?,?,?)", "INSERT INTO arsse_articles(url,title,author,published,edited,guid,content,url_title_hash,url_content_hash,title_content_hash,feed) values(?,?,?,?,?,?,?,?,?,?,?)",
'str', ['str', 'str', 'str', 'datetime', 'datetime', 'str', 'str', 'str', 'str', 'str', 'int']
'str',
'str',
'datetime',
'datetime',
'str',
'str',
'str',
'str',
'str',
'int'
); );
} }
if (sizeof($feed->changedItems)) { if (sizeof($feed->changedItems)) {
$qDeleteEnclosures = $this->db->prepare("DELETE FROM arsse_enclosures WHERE article = ?", 'int'); $qDeleteEnclosures = $this->db->prepare("DELETE FROM arsse_enclosures WHERE article = ?", 'int');
$qDeleteCategories = $this->db->prepare("DELETE FROM arsse_categories WHERE article = ?", 'int'); $qDeleteCategories = $this->db->prepare("DELETE FROM arsse_categories WHERE article = ?", 'int');
$qClearReadMarks = $this->db->prepare("UPDATE arsse_marks SET \"read\" = 0, modified = CURRENT_TIMESTAMP WHERE article = ? and \"read\" = 1", 'int'); $qClearReadMarks = $this->db->prepare("UPDATE arsse_marks SET \"read\" = 0, modified = CURRENT_TIMESTAMP WHERE article = ? and \"read\" = 1", 'int');
$qUpdateArticle = $this->db->prepare( $qUpdateArticle = $this->db->prepareArray(
"UPDATE arsse_articles SET url = ?, title = ?, author = ?, published = ?, edited = ?, modified = CURRENT_TIMESTAMP, guid = ?, content = ?, url_title_hash = ?, url_content_hash = ?, title_content_hash = ? WHERE id = ?", "UPDATE arsse_articles SET url = ?, title = ?, author = ?, published = ?, edited = ?, modified = CURRENT_TIMESTAMP, guid = ?, content = ?, url_title_hash = ?, url_content_hash = ?, title_content_hash = ? WHERE id = ?",
'str', ['str', 'str', 'str', 'datetime', 'datetime', 'str', 'str', 'str', 'str', 'str', 'int']
'str',
'str',
'datetime',
'datetime',
'str',
'str',
'str',
'str',
'str',
'int'
); );
} }
// determine if the feed icon needs to be updated, and update it if appropriate // determine if the feed icon needs to be updated, and update it if appropriate
@ -1159,16 +1150,9 @@ class Database {
$qClearReadMarks->run($articleID); $qClearReadMarks->run($articleID);
} }
// lastly update the feed database itself with updated information. // lastly update the feed database itself with updated information.
$this->db->prepare( $this->db->prepareArray(
"UPDATE arsse_feeds SET title = ?, source = ?, updated = CURRENT_TIMESTAMP, modified = ?, etag = ?, err_count = 0, err_msg = '', next_fetch = ?, size = ?, icon = ? WHERE id = ?", "UPDATE arsse_feeds SET title = ?, source = ?, updated = CURRENT_TIMESTAMP, modified = ?, etag = ?, err_count = 0, err_msg = '', next_fetch = ?, size = ?, icon = ? WHERE id = ?",
'str', ['str', 'str', 'datetime', 'strict str', 'datetime', 'int', 'int', 'int']
'str',
'datetime',
'strict str',
'datetime',
'int',
'int',
'int'
)->run( )->run(
$feed->data->title, $feed->data->title,
$feed->data->siteUrl, $feed->data->siteUrl,
@ -1258,13 +1242,9 @@ class Database {
[$cHashUC, $tHashUC, $vHashUC] = $this->generateIn($hashesUC, "str"); [$cHashUC, $tHashUC, $vHashUC] = $this->generateIn($hashesUC, "str");
[$cHashTC, $tHashTC, $vHashTC] = $this->generateIn($hashesTC, "str"); [$cHashTC, $tHashTC, $vHashTC] = $this->generateIn($hashesTC, "str");
// perform the query // perform the query
return $this->db->prepare( return $this->db->prepareArray(
"SELECT id, edited, guid, url_title_hash, url_content_hash, title_content_hash FROM arsse_articles WHERE feed = ? and (guid in($cId) or url_title_hash in($cHashUT) or url_content_hash in($cHashUC) or title_content_hash in($cHashTC))", "SELECT id, edited, guid, url_title_hash, url_content_hash, title_content_hash FROM arsse_articles WHERE feed = ? and (guid in($cId) or url_title_hash in($cHashUT) or url_content_hash in($cHashUC) or title_content_hash in($cHashTC))",
'int', ['int', $tId, $tHashUT, $tHashUC, $tHashTC]
$tId,
$tHashUT,
$tHashUC,
$tHashTC
)->run($feedID, $vId, $vHashUT, $vHashUC, $vHashTC); )->run($feedID, $vId, $vHashUT, $vHashUC, $vHashTC);
} }
@ -1880,15 +1860,14 @@ class Database {
if (!V::id($id)) { if (!V::id($id)) {
throw new Db\ExceptionInput("typeViolation", ["action" => $this->caller(), "field" => "article", 'type' => "int > 0"]); // @codeCoverageIgnore throw new Db\ExceptionInput("typeViolation", ["action" => $this->caller(), "field" => "article", 'type' => "int > 0"]); // @codeCoverageIgnore
} }
$out = $this->db->prepare( $out = $this->db->prepareArray(
"SELECT articles.article as article, max(arsse_editions.id) as edition from ( "SELECT articles.article as article, max(arsse_editions.id) as edition from (
select arsse_articles.id as article select arsse_articles.id as article
FROM arsse_articles FROM arsse_articles
join arsse_subscriptions on arsse_subscriptions.feed = arsse_articles.feed join arsse_subscriptions on arsse_subscriptions.feed = arsse_articles.feed
WHERE arsse_articles.id = ? and arsse_subscriptions.owner = ? WHERE arsse_articles.id = ? and arsse_subscriptions.owner = ?
) as articles join arsse_editions on arsse_editions.article = articles.article group by articles.article", ) as articles join arsse_editions on arsse_editions.article = articles.article group by articles.article",
"int", ["int", "str"]
"str"
)->run($id, $user)->getRow(); )->run($id, $user)->getRow();
if (!$out) { if (!$out) {
throw new Db\ExceptionInput("subjectMissing", ["action" => $this->caller(), "field" => "article", 'id' => $id]); throw new Db\ExceptionInput("subjectMissing", ["action" => $this->caller(), "field" => "article", 'id' => $id]);
@ -1907,7 +1886,7 @@ class Database {
if (!V::id($id)) { if (!V::id($id)) {
throw new Db\ExceptionInput("typeViolation", ["action" => $this->caller(), "field" => "edition", 'type' => "int > 0"]); // @codeCoverageIgnore throw new Db\ExceptionInput("typeViolation", ["action" => $this->caller(), "field" => "edition", 'type' => "int > 0"]); // @codeCoverageIgnore
} }
$out = $this->db->prepare( $out = $this->db->prepareArray(
"SELECT "SELECT
arsse_editions.id, arsse_editions.article, edition_stats.edition as current arsse_editions.id, arsse_editions.article, edition_stats.edition as current
from arsse_editions from arsse_editions
@ -1915,8 +1894,7 @@ class Database {
join arsse_subscriptions on arsse_subscriptions.feed = arsse_articles.feed join arsse_subscriptions on arsse_subscriptions.feed = arsse_articles.feed
join (select article, max(id) as edition from arsse_editions group by article) as edition_stats on edition_stats.article = arsse_editions.article join (select article, max(id) as edition from arsse_editions group by article) as edition_stats on edition_stats.article = arsse_editions.article
where arsse_editions.id = ? and arsse_subscriptions.owner = ?", where arsse_editions.id = ? and arsse_subscriptions.owner = ?",
"int", ["int", "str"]
"str"
)->run($id, $user)->getRow(); )->run($id, $user)->getRow();
if (!$out) { if (!$out) {
throw new Db\ExceptionInput("subjectMissing", ["action" => $this->caller(), "field" => "edition", 'id' => $id]); throw new Db\ExceptionInput("subjectMissing", ["action" => $this->caller(), "field" => "edition", 'id' => $id]);
@ -1968,7 +1946,7 @@ class Database {
* @param boolean $includeEmpty Whether to include (true) or supress (false) labels which have no articles assigned to them * @param boolean $includeEmpty Whether to include (true) or supress (false) labels which have no articles assigned to them
*/ */
public function labelList(string $user, bool $includeEmpty = true): Db\Result { public function labelList(string $user, bool $includeEmpty = true): Db\Result {
return $this->db->prepare( return $this->db->prepareArray(
"SELECT * FROM ( "SELECT * FROM (
SELECT SELECT
id, id,
@ -1992,11 +1970,8 @@ class Database {
) as mark_stats on mark_stats.label = arsse_labels.id ) as mark_stats on mark_stats.label = arsse_labels.id
WHERE owner = ? WHERE owner = ?
) as label_data ) as label_data
where articles >= ? order by name where articles >= ? order by name",
", ["str", "str", "int"]
"str",
"str",
"int"
)->run($user, $user, !$includeEmpty); )->run($user, $user, !$includeEmpty);
} }
@ -2036,7 +2011,7 @@ class Database {
$this->labelValidateId($user, $id, $byName, false); $this->labelValidateId($user, $id, $byName, false);
$field = $byName ? "name" : "id"; $field = $byName ? "name" : "id";
$type = $byName ? "str" : "int"; $type = $byName ? "str" : "int";
$out = $this->db->prepare( $out = $this->db->prepareArray(
"SELECT "SELECT
id, id,
name, name,
@ -2057,11 +2032,8 @@ class Database {
where arsse_subscriptions.owner = ? where arsse_subscriptions.owner = ?
group by label group by label
) as mark_stats on mark_stats.label = arsse_labels.id ) as mark_stats on mark_stats.label = arsse_labels.id
WHERE $field = ? and owner = ? WHERE $field = ? and owner = ?",
", ["str", $type, "str"]
"str",
$type,
"str"
)->run($user, $id, $user)->getRow(); )->run($user, $id, $user)->getRow();
if (!$out) { if (!$out) {
throw new Db\ExceptionInput("subjectMissing", ["action" => __FUNCTION__, "field" => "label", 'id' => $id]); throw new Db\ExceptionInput("subjectMissing", ["action" => __FUNCTION__, "field" => "label", 'id' => $id]);
@ -2113,6 +2085,7 @@ class Database {
} }
try { try {
$q = $this->articleQuery($user, $c); $q = $this->articleQuery($user, $c);
$q->setOrder("id");
$out = $this->db->prepare((string) $q, $q->getTypes())->run($q->getValues())->getAll(); $out = $this->db->prepare((string) $q, $q->getTypes())->run($q->getValues())->getAll();
} catch (Db\ExceptionInput $e) { } catch (Db\ExceptionInput $e) {
if ($e->getCode() === 10235) { if ($e->getCode() === 10235) {
@ -2261,7 +2234,7 @@ class Database {
* @param boolean $includeEmpty Whether to include (true) or supress (false) tags which have no subscriptions assigned to them * @param boolean $includeEmpty Whether to include (true) or supress (false) tags which have no subscriptions assigned to them
*/ */
public function tagList(string $user, bool $includeEmpty = true): Db\Result { public function tagList(string $user, bool $includeEmpty = true): Db\Result {
return $this->db->prepare( return $this->db->prepareArray(
"SELECT * FROM ( "SELECT * FROM (
SELECT SELECT
id,name,coalesce(subscriptions,0) as subscriptions id,name,coalesce(subscriptions,0) as subscriptions
@ -2269,10 +2242,8 @@ class Database {
left join (SELECT tag, sum(assigned) as subscriptions from arsse_tag_members group by tag) as tag_stats on tag_stats.tag = arsse_tags.id left join (SELECT tag, sum(assigned) as subscriptions from arsse_tag_members group by tag) as tag_stats on tag_stats.tag = arsse_tags.id
WHERE owner = ? WHERE owner = ?
) as tag_data ) as tag_data
where subscriptions >= ? order by name where subscriptions >= ? order by name",
", ["str", "int"]
"str",
"int"
)->run($user, !$includeEmpty); )->run($user, !$includeEmpty);
} }
@ -2288,7 +2259,7 @@ class Database {
* @param string $user The user whose tags are to be listed * @param string $user The user whose tags are to be listed
*/ */
public function tagSummarize(string $user): Db\Result { public function tagSummarize(string $user): Db\Result {
return $this->db->prepare( return $this->db->prepareArray(
"SELECT "SELECT
arsse_tags.id as id, arsse_tags.id as id,
arsse_tags.name as name, arsse_tags.name as name,
@ -2296,7 +2267,7 @@ class Database {
FROM arsse_tag_members FROM arsse_tag_members
join arsse_tags on arsse_tags.id = arsse_tag_members.tag join arsse_tags on arsse_tags.id = arsse_tag_members.tag
WHERE arsse_tags.owner = ? and assigned = 1", WHERE arsse_tags.owner = ? and assigned = 1",
"str" ["str"]
)->run($user); )->run($user);
} }
@ -2335,15 +2306,13 @@ class Database {
$this->tagValidateId($user, $id, $byName, false); $this->tagValidateId($user, $id, $byName, false);
$field = $byName ? "name" : "id"; $field = $byName ? "name" : "id";
$type = $byName ? "str" : "int"; $type = $byName ? "str" : "int";
$out = $this->db->prepare( $out = $this->db->prepareArray(
"SELECT "SELECT
id,name,coalesce(subscriptions,0) as subscriptions id,name,coalesce(subscriptions,0) as subscriptions
FROM arsse_tags FROM arsse_tags
left join (SELECT tag, sum(assigned) as subscriptions from arsse_tag_members group by tag) as tag_stats on tag_stats.tag = arsse_tags.id left join (SELECT tag, sum(assigned) as subscriptions from arsse_tag_members group by tag) as tag_stats on tag_stats.tag = arsse_tags.id
WHERE $field = ? and owner = ? WHERE $field = ? and owner = ?",
", [$type, "str"]
$type,
"str"
)->run($id, $user)->getRow(); )->run($id, $user)->getRow();
if (!$out) { if (!$out) {
throw new Db\ExceptionInput("subjectMissing", ["action" => __FUNCTION__, "field" => "tag", 'id' => $id]); throw new Db\ExceptionInput("subjectMissing", ["action" => __FUNCTION__, "field" => "tag", 'id' => $id]);

View file

@ -318,7 +318,7 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
return new ErrorResponse($msg, 500); return new ErrorResponse($msg, 500);
} }
$out = []; $out = [];
foreach($list as $url) { foreach ($list as $url) {
// TODO: This needs to be refined once PicoFeed is replaced // TODO: This needs to be refined once PicoFeed is replaced
$out[] = ['title' => "Feed", 'type' => "rss", 'url' => $url]; $out[] = ['title' => "Feed", 'type' => "rss", 'url' => $url];
} }

View file

@ -209,7 +209,7 @@ trait SeriesLabel {
[11, 20,1,0,'2017-01-01 00:00:00',0], [11, 20,1,0,'2017-01-01 00:00:00',0],
[12, 3,0,1,'2017-01-01 00:00:00',0], [12, 3,0,1,'2017-01-01 00:00:00',0],
[12, 4,1,1,'2017-01-01 00:00:00',0], [12, 4,1,1,'2017-01-01 00:00:00',0],
[4, 8,0,0,'2000-01-02 02:00:00',1] [4, 8,0,0,'2000-01-02 02:00:00',1],
], ],
], ],
'arsse_labels' => [ 'arsse_labels' => [

View file

@ -23,7 +23,7 @@ trait SeriesSubscription {
'rows' => [ 'rows' => [
["jane.doe@example.com", "", 1], ["jane.doe@example.com", "", 1],
["john.doe@example.com", "", 2], ["john.doe@example.com", "", 2],
["jill.doe@example.com", "", 3] ["jill.doe@example.com", "", 3],
], ],
], ],
'arsse_folders' => [ 'arsse_folders' => [

View file

@ -157,7 +157,7 @@ trait SeriesUser {
public function testSetNoMetadata(): void { public function testSetNoMetadata(): void {
$in = [ $in = [
'num' => 2112, 'num' => 2112,
'stylesheet' => "body {background:lightgray}", 'stylesheet' => "body {background:lightgray}",
]; ];
$this->assertTrue(Arsse::$db->userPropertiesSet("john.doe@example.com", $in)); $this->assertTrue(Arsse::$db->userPropertiesSet("john.doe@example.com", $in));

View file

@ -62,7 +62,7 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
'extra' => [ 'extra' => [
'custom_css' => "", 'custom_css' => "",
], ],
] ],
]; ];
protected function req(string $method, string $target, $data = "", array $headers = [], ?string $user = "john.doe@example.com", bool $body = true): ResponseInterface { protected function req(string $method, string $target, $data = "", array $headers = [], ?string $user = "john.doe@example.com", bool $body = true): ResponseInterface {
@ -185,8 +185,8 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
/** @dataProvider provideUserQueries */ /** @dataProvider provideUserQueries */
public function testQueryUsers(bool $admin, string $route, ResponseInterface $exp): void { public function testQueryUsers(bool $admin, string $route, ResponseInterface $exp): void {
$u = [ $u = [
['num'=> 1, 'admin' => true, 'theme' => "custom", 'lang' => "fr_CA", 'tz' => "Asia/Gaza", 'sort_asc' => true, 'page_size' => 200, 'shortcuts' => false, 'reading_time' => false, 'swipe' => false, 'stylesheet' => "p {}"], ['num' => 1, 'admin' => true, 'theme' => "custom", 'lang' => "fr_CA", 'tz' => "Asia/Gaza", 'sort_asc' => true, 'page_size' => 200, 'shortcuts' => false, 'reading_time' => false, 'swipe' => false, 'stylesheet' => "p {}"],
['num'=> 2, 'admin' => false, 'theme' => null, 'lang' => null, 'tz' => null, 'sort_asc' => null, 'page_size' => null, 'shortcuts' => null, 'reading_time' => null, 'swipe' => null, 'stylesheet' => null], ['num' => 2, 'admin' => false, 'theme' => null, 'lang' => null, 'tz' => null, 'sort_asc' => null, 'page_size' => null, 'shortcuts' => null, 'reading_time' => null, 'swipe' => null, 'stylesheet' => null],
new ExceptionConflict("doesNotExist"), new ExceptionConflict("doesNotExist"),
]; ];
$user = $admin ? "john.doe@example.com" : "jane.doe@example.com"; $user = $admin ? "john.doe@example.com" : "jane.doe@example.com";

View file

@ -98,7 +98,6 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::verify(Arsse::$db)->userLookup(2112); \Phake::verify(Arsse::$db)->userLookup(2112);
} }
public function testAddAUser(): void { public function testAddAUser(): void {
$user = "john.doe@example.com"; $user = "john.doe@example.com";
$pass = "secret"; $pass = "secret";
@ -439,7 +438,7 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
[['tz' => false], new ExceptionInput("invalidValue")], [['tz' => false], new ExceptionInput("invalidValue")],
[['lang' => "en-ca"], ['lang' => "en-CA"]], [['lang' => "en-ca"], ['lang' => "en-CA"]],
[['lang' => null], ['lang' => null]], [['lang' => null], ['lang' => null]],
[['page_size' => 0], new ExceptionInput("invalidNonZeroInteger")] [['page_size' => 0], new ExceptionInput("invalidNonZeroInteger")],
]; ];
} }