Browse Source

CS fixes

microsub
J. King 7 years ago
parent
commit
79f9808f1f
  1. 88
      lib/Database.php
  2. 3
      lib/Feed.php
  3. 3
      lib/Misc/ValueInfo.php
  4. 2
      lib/REST/TinyTinyRSS/API.php
  5. 2
      lib/User.php

88
lib/Database.php

@ -448,7 +448,11 @@ class Database {
((select dest from target) is null or exists(select id from arsse_folders join target on owner = user and coalesce(id,0) = coalesce(dest,0))) as extant, ((select dest from target) is null or exists(select id from arsse_folders join target on owner = user and coalesce(id,0) = coalesce(dest,0))) as extant,
not exists(select id from folders where id = coalesce((select dest from target),0)) as valid, not exists(select id from folders where id = coalesce((select dest from target),0)) as valid,
not exists(select id from arsse_folders join target on coalesce(parent,0) = coalesce(dest,0) and name = coalesce((select rename from target),(select name from arsse_folders join target on id = source))) as available not exists(select id from arsse_folders join target on coalesce(parent,0) = coalesce(dest,0) and name = coalesce((select rename from target),(select name from arsse_folders join target on id = source))) as available
", "str", "strict int", "int", "str" ",
"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
@ -687,7 +691,9 @@ class Database {
// 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->prepare(
"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', 'str', 'int' 'datetime',
'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;
@ -703,7 +709,17 @@ class Database {
if (sizeof($feed->newItems)) { if (sizeof($feed->newItems)) {
$qInsertArticle = $this->db->prepare( $qInsertArticle = $this->db->prepare(
"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', 'datetime', 'datetime', 'str', 'str', 'str', 'str', 'str', 'int' 'str',
'str',
'str',
'datetime',
'datetime',
'str',
'str',
'str',
'str',
'str',
'int'
); );
} }
if (sizeof($feed->changedItems)) { if (sizeof($feed->changedItems)) {
@ -712,7 +728,17 @@ class Database {
$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->prepare(
"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', 'datetime', 'datetime', 'str', 'str', 'str', 'str', 'str', 'int' 'str',
'str',
'str',
'datetime',
'datetime',
'str',
'str',
'str',
'str',
'str',
'int'
); );
} }
// actually perform updates // actually perform updates
@ -767,7 +793,15 @@ class Database {
// lastly update the feed database itself with updated information. // lastly update the feed database itself with updated information.
$this->db->prepare( $this->db->prepare(
"UPDATE arsse_feeds SET url = ?, title = ?, favicon = ?, source = ?, updated = CURRENT_TIMESTAMP, modified = ?, etag = ?, err_count = 0, err_msg = '', next_fetch = ?, size = ? WHERE id = ?", "UPDATE arsse_feeds SET url = ?, title = ?, favicon = ?, source = ?, updated = CURRENT_TIMESTAMP, modified = ?, etag = ?, err_count = 0, err_msg = '', next_fetch = ?, size = ? WHERE id = ?",
'str', 'str', 'str', 'str', 'datetime', 'str', 'datetime', 'int', 'int' 'str',
'str',
'str',
'str',
'datetime',
'str',
'datetime',
'int',
'int'
)->run( )->run(
$feed->data->feedUrl, $feed->data->feedUrl,
$feed->data->title, $feed->data->title,
@ -804,7 +838,8 @@ class Database {
public function feedMatchLatest(int $feedID, int $count): Db\Result { public function feedMatchLatest(int $feedID, int $count): Db\Result {
return $this->db->prepare( return $this->db->prepare(
"SELECT id, edited, guid, url_title_hash, url_content_hash, title_content_hash FROM arsse_articles WHERE feed = ? ORDER BY modified desc, id desc limit ?", "SELECT id, edited, guid, url_title_hash, url_content_hash, title_content_hash FROM arsse_articles WHERE feed = ? ORDER BY modified desc, id desc limit ?",
'int', 'int' 'int',
'int'
)->run($feedID, $count); )->run($feedID, $count);
} }
@ -817,7 +852,11 @@ class Database {
// perform the query // perform the query
return $articles = $this->db->prepare( return $articles = $this->db->prepare(
"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', $tId, $tHashUT, $tHashUC, $tHashTC 'int',
$tId,
$tHashUT,
$tHashUC,
$tHashTC
)->run($feedID, $ids, $hashesUT, $hashesUC, $hashesTC); )->run($feedID, $ids, $hashesUT, $hashesUC, $hashesTC);
} }
@ -881,7 +920,8 @@ class Database {
throw new Db\ExceptionInput("tooLong", ['field' => "editions", 'action' => __FUNCTION__, 'max' => self::LIMIT_ARTICLES]); // @codeCoverageIgnore throw new Db\ExceptionInput("tooLong", ['field' => "editions", 'action' => __FUNCTION__, 'max' => self::LIMIT_ARTICLES]); // @codeCoverageIgnore
} }
list($inParams, $inTypes) = $this->generateIn($context->editions, "int"); list($inParams, $inTypes) = $this->generateIn($context->editions, "int");
$q->setCTE("requested_articles(id,edition)", $q->setCTE(
"requested_articles(id,edition)",
"SELECT article,id as edition from arsse_editions where edition in ($inParams)", "SELECT article,id as edition from arsse_editions where edition in ($inParams)",
$inTypes, $inTypes,
$context->editions $context->editions
@ -895,7 +935,8 @@ class Database {
throw new Db\ExceptionInput("tooLong", ['field' => "articles", 'action' => __FUNCTION__, 'max' => self::LIMIT_ARTICLES]); // @codeCoverageIgnore throw new Db\ExceptionInput("tooLong", ['field' => "articles", 'action' => __FUNCTION__, 'max' => self::LIMIT_ARTICLES]); // @codeCoverageIgnore
} }
list($inParams, $inTypes) = $this->generateIn($context->articles, "int"); list($inParams, $inTypes) = $this->generateIn($context->articles, "int");
$q->setCTE("requested_articles(id,edition)", $q->setCTE(
"requested_articles(id,edition)",
"SELECT id,(select max(id) from arsse_editions where article = arsse_articles.id) as edition from arsse_articles where arsse_articles.id in ($inParams)", "SELECT id,(select max(id) from arsse_editions where article = arsse_articles.id) as edition from arsse_articles where arsse_articles.id in ($inParams)",
$inTypes, $inTypes,
$context->articles $context->articles
@ -1005,12 +1046,14 @@ class Database {
$columns = array_merge($columns, [ $columns = array_merge($columns, [
"(select note from arsse_marks where article = arsse_articles.id and subscription in (select sub from subscribed_feeds)) as note", "(select note from arsse_marks where article = arsse_articles.id and subscription in (select sub from subscribed_feeds)) as note",
]); ]);
// no break
case self::LIST_TYPICAL: // conservative, plus content case self::LIST_TYPICAL: // conservative, plus content
$columns = array_merge($columns, [ $columns = array_merge($columns, [
"content", "content",
"arsse_enclosures.url as media_url", // enclosures are potentially large due to data: URLs "arsse_enclosures.url as media_url", // enclosures are potentially large due to data: URLs
"arsse_enclosures.type as media_type", // FIXME: enclosures should eventually have their own fetch method "arsse_enclosures.type as media_type", // FIXME: enclosures should eventually have their own fetch method
]); ]);
// no break
case self::LIST_CONSERVATIVE: // base metadata, plus anything that is not likely to be large text case self::LIST_CONSERVATIVE: // base metadata, plus anything that is not likely to be large text
$columns = array_merge($columns, [ $columns = array_merge($columns, [
"arsse_articles.url as url", "arsse_articles.url as url",
@ -1022,6 +1065,7 @@ class Database {
"edited as edited_date", "edited as edited_date",
"url_title_hash||':'||url_content_hash||':'||title_content_hash as fingerprint", "url_title_hash||':'||url_content_hash||':'||title_content_hash as fingerprint",
]); ]);
// no break
case self::LIST_MINIMAL: // base metadata (always included: required for context matching) case self::LIST_MINIMAL: // base metadata (always included: required for context matching)
$columns = array_merge($columns, [ $columns = array_merge($columns, [
// id, subscription, feed, modified_date, marked_date, unread, starred, edition // id, subscription, feed, modified_date, marked_date, unread, starred, edition
@ -1150,7 +1194,8 @@ class Database {
coalesce(sum(read),0) as read coalesce(sum(read),0) as read
FROM ( FROM (
select read from arsse_marks where starred = 1 and subscription in (select id from arsse_subscriptions where owner = ?) select read from arsse_marks where starred = 1 and subscription in (select id from arsse_subscriptions where owner = ?)
)", "str" )",
"str"
)->run($user)->getRow(); )->run($user)->getRow();
} }
@ -1203,7 +1248,11 @@ class Database {
coalesce((select max(modified) from arsse_marks where article = arsse_articles.id),modified) <= ? coalesce((select max(modified) from arsse_marks where article = arsse_articles.id),modified) <= ?
or ((select max(subs) from target_feed) = (select count(*) from arsse_marks where article = arsse_articles.id and read = 1) and coalesce((select max(modified) from arsse_marks where article = arsse_articles.id),modified) <= ?) or ((select max(subs) from target_feed) = (select count(*) from arsse_marks where article = arsse_articles.id and read = 1) and coalesce((select max(modified) from arsse_marks where article = arsse_articles.id),modified) <= ?)
) )
", "int", "int", "datetime", "datetime" ",
"int",
"int",
"datetime",
"datetime"
); );
$limitRead = null; $limitRead = null;
$limitUnread = null; $limitUnread = null;
@ -1233,7 +1282,8 @@ class Database {
join arsse_subscriptions on arsse_subscriptions.feed = arsse_feeds.id join arsse_subscriptions on arsse_subscriptions.feed = arsse_feeds.id
WHERE WHERE
arsse_articles.id = ? and arsse_subscriptions.owner = ?", arsse_articles.id = ? and arsse_subscriptions.owner = ?",
"int", "str" "int",
"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]);
@ -1256,7 +1306,8 @@ class Database {
join arsse_subscriptions on arsse_subscriptions.feed = arsse_feeds.id join arsse_subscriptions on arsse_subscriptions.feed = arsse_feeds.id
WHERE WHERE
edition = ? and arsse_subscriptions.owner = ?", edition = ? and arsse_subscriptions.owner = ?",
"int", "str" "int",
"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]);
@ -1308,7 +1359,9 @@ class Database {
where label = id and assigned = 1 and read = 1 where label = id and assigned = 1 and read = 1
) as read ) as read
FROM arsse_labels where owner = ? and articles >= ? order by name FROM arsse_labels where owner = ? and articles >= ? order by name
", "str", "int" ",
"str",
"int"
)->run($user, !$includeEmpty); )->run($user, !$includeEmpty);
} }
@ -1342,7 +1395,9 @@ class Database {
where label = id and assigned = 1 and read = 1 where label = id and assigned = 1 and read = 1
) as read ) as read
FROM arsse_labels where $field = ? and owner = ? FROM arsse_labels 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" => "label", 'id' => $id]); throw new Db\ExceptionInput("subjectMissing", ["action" => __FUNCTION__, "field" => "label", 'id' => $id]);
@ -1427,7 +1482,8 @@ class Database {
?,id, ?,id,
(select id from arsse_subscriptions join user on user = owner where arsse_subscriptions.feed = target_articles.feed) (select id from arsse_subscriptions join user on user = owner where arsse_subscriptions.feed = target_articles.feed)
FROM target_articles", FROM target_articles",
"int", $id "int",
$id
); );
$out += $this->db->prepare($q->getQuery(), $q->getTypes())->run($q->getValues())->changes(); $out += $this->db->prepare($q->getQuery(), $q->getTypes())->run($q->getValues())->changes();
} }

3
lib/Feed.php

@ -77,7 +77,8 @@ class Feed {
} }
protected static function configure(): Config { protected static function configure(): Config {
$userAgent = Arsse::$conf->fetchUserAgentString ?? sprintf('Arsse/%s (%s %s; %s; https://thearsse.com/) PicoFeed (https://github.com/miniflux/picoFeed)', $userAgent = Arsse::$conf->fetchUserAgentString ?? sprintf(
'Arsse/%s (%s %s; %s; https://thearsse.com/) PicoFeed (https://github.com/miniflux/picoFeed)',
Arsse::VERSION, // Arsse version Arsse::VERSION, // Arsse version
php_uname('s'), // OS php_uname('s'), // OS
php_uname('r'), // OS version php_uname('r'), // OS version

3
lib/Misc/ValueInfo.php

@ -103,6 +103,7 @@ class ValueInfo {
} else { } else {
return 0; return 0;
} }
break;
case self::T_FLOAT: case self::T_FLOAT:
if (is_float($value)) { if (is_float($value)) {
return $value; return $value;
@ -160,6 +161,7 @@ class ValueInfo {
} else { } else {
return (string) $value; return (string) $value;
} }
break;
case self::T_DATE: case self::T_DATE:
if ($value instanceof \DateTimeImmutable) { if ($value instanceof \DateTimeImmutable) {
return $value->setTimezone(new \DateTimeZone("UTC")); return $value->setTimezone(new \DateTimeZone("UTC"));
@ -237,6 +239,7 @@ class ValueInfo {
return [$value]; return [$value];
} }
} }
break;
default: default:
throw new ExceptionType("typeUnknown", $type); // @codeCoverageIgnore throw new ExceptionType("typeUnknown", $type); // @codeCoverageIgnore
} }

2
lib/REST/TinyTinyRSS/API.php

@ -266,7 +266,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
} }
// do a third pass on categories, building a final category list; this is done so that the original sort order is retained // do a third pass on categories, building a final category list; this is done so that the original sort order is retained
foreach ($categories as $c) { foreach ($categories as $c) {
$cats[] = ['id' => $c['id'], 'kind' => "cat", 'counter' => $catCounts[$c['id']]]; $cats[] = ['id' => $c['id'], 'kind' => "cat", 'counter' => $catCounts[$c['id']]];
} }
// prepare data for the virtual feeds and other counters // prepare data for the virtual feeds and other counters
$special = [ $special = [

2
lib/User.php

@ -162,6 +162,7 @@ class User {
} else { } else {
return $this->u->auth($user, $password); return $this->u->auth($user, $password);
} }
break;
case User\Driver::FUNCT_NOT_IMPLEMENTED: case User\Driver::FUNCT_NOT_IMPLEMENTED:
return false; return false;
} }
@ -194,6 +195,7 @@ class User {
throw new User\ExceptionAuthz("notAuthorized", ["action" => $func, "user" => "all users"]); throw new User\ExceptionAuthz("notAuthorized", ["action" => $func, "user" => "all users"]);
} }
} }
// no break
case User\Driver::FUNC_INTERNAL: case User\Driver::FUNC_INTERNAL:
// internal functions handle their own authorization // internal functions handle their own authorization
return $this->u->userList($domain); return $this->u->userList($domain);

Loading…
Cancel
Save