From bbdc4f7672fe8931822b84c294193aba7a537d06 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Wed, 15 Mar 2023 19:33:52 -0400 Subject: [PATCH] Fix MySQL failure and shore up coverage This marks the end of the feed reduplication effort --- lib/AbstractException.php | 2 +- lib/Database.php | 23 +++++++++++++++-------- locale/en.php | 2 +- tests/cases/Database/SeriesArticle.php | 2 +- tests/cases/Misc/TestValueInfo.php | 1 + 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/AbstractException.php b/lib/AbstractException.php index 5be10081..6de35d9f 100644 --- a/lib/AbstractException.php +++ b/lib/AbstractException.php @@ -38,7 +38,7 @@ abstract class AbstractException extends \Exception { "Db/Exception.updateFileUnreadable" => 10216, "Db/Exception.updateFileError" => 10217, "Db/Exception.updateFileIncomplete" => 10218, - "Db/Exception.updateSchemaChange" => 10219, + "Db/Exception.updateSchemaDowngrade" => 10219, "Db/Exception.paramTypeInvalid" => 10221, "Db/Exception.paramTypeUnknown" => 10222, "Db/Exception.paramTypeMissing" => 10223, diff --git a/lib/Database.php b/lib/Database.php index 6a06b90d..0d34f375 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -84,8 +84,9 @@ class Database { if ($initialize) { if ($ver < self::SCHEMA_VERSION) { $this->db->schemaUpdate(self::SCHEMA_VERSION); - } elseif ($ver != self::SCHEMA_VERSION) { - throw new Db\Exception("updateSchemaChange"); + } elseif ($ver != self::SCHEMA_VERSION) {// @codeCoverageIgnore + // This will only occur if an old version of the software is used with a newer database schema + throw new Db\Exception("updateSchemaDowngrade"); // @codeCoverageIgnore } } } @@ -1151,7 +1152,6 @@ class Database { try { $keep = Rule::prep($sub['keep']); $block = Rule::prep($sub['block']); - $feed = $sub['id']; } catch (RuleException $e) { // @codeCoverageIgnore // invalid rules should not normally appear in the database, but it's possible // in this case we should halt evaluation and just leave things as they are @@ -1277,13 +1277,17 @@ class Database { // prepare the keep and block rules try { $keep = Rule::prep($f['keep_rule'] ?? ""); - } catch (RuleException $e) { - $keep = ""; + } catch (RuleException $e) { // @codeCoverageIgnore + // invalid rules should not normally appear in the database, but it's possible + // in this case we act as if the rule were not defined + $keep = ""; // @codeCoverageIgnore } try { $block = Rule::prep($f['block_rule'] ?? ""); - } catch (RuleException $e) { - $block = ""; + } catch (RuleException $e) { // @codeCoverageIgnore + // invalid rules should not normally appear in the database, but it's possible + // in this case we act as if the rule were not defined + $block = ""; // @codeCoverageIgnore } // determine if the feed icon needs to be updated, and update it if appropriate $tr = $this->db->begin(); @@ -2473,10 +2477,13 @@ class Database { * @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 { + $integerType = $this->db->sqlToken("integer"); return $this->db->prepareArray( "SELECT * FROM ( SELECT - id,name,coalesce(subscriptions,0) as subscriptions + id, + name, + cast(coalesce(subscriptions,0) as $integerType) as subscriptions -- this cast is required for MySQL for unclear reasons from arsse_tags left join ( SELECT diff --git a/locale/en.php b/locale/en.php index 1348af03..85b87f35 100644 --- a/locale/en.php +++ b/locale/en.php @@ -147,7 +147,7 @@ return [ 0 {Automatic updating of the {driver_name} database failed because it is already up to date with the requested version, {target}} other {Automatic updating of the {driver_name} database failed because its version, {current}, is newer than the requested version, {target}} }', - 'Exception.JKingWeb/Arsse/Db/Exception.updateSchemaChange' => 'Database schema version is newer than the application schema version', + 'Exception.JKingWeb/Arsse/Db/Exception.updateSchemaDowngrade' => 'Database schema version is newer than the application schema version', 'Exception.JKingWeb/Arsse/Db/Exception.engineErrorGeneral' => '{0}', // indicates programming error 'Exception.JKingWeb/Arsse/Db/Exception.savepointStatusUnknown' => 'Savepoint status code {0} not implemented', diff --git a/tests/cases/Database/SeriesArticle.php b/tests/cases/Database/SeriesArticle.php index 5588424b..835f6ed8 100644 --- a/tests/cases/Database/SeriesArticle.php +++ b/tests/cases/Database/SeriesArticle.php @@ -815,7 +815,7 @@ trait SeriesArticle { } public function testMarkMultipleMissingEditions(): void { - $this->assertSame(0, Arsse::$db->articleMark($this->user, ['starred' => true], (new Context)->editions([500,501]))); + $this->assertSame(0, Arsse::$db->articleMark($this->user, ['starred' => true], (new Context)->editions([56458, 1851855]))); $state = $this->primeExpectations($this->data, $this->checkTables); $this->compareExpectations(static::$drv, $state); } diff --git a/tests/cases/Misc/TestValueInfo.php b/tests/cases/Misc/TestValueInfo.php index b8f624e3..5f19ac3a 100644 --- a/tests/cases/Misc/TestValueInfo.php +++ b/tests/cases/Misc/TestValueInfo.php @@ -531,6 +531,7 @@ class TestValueInfo extends \JKingWeb\Arsse\Test\AbstractTest { [$this->i("P2DT1H"), [null,true], [true, false], [(48 + 1) * 60 * 60, false], [1.0 * (48 + 1) * 60 * 60, false], ["P2DT1H", true], [[$this->i("P2DT1H")], false], [$this->i("P2DT1H"), true]], [$this->i("PT0H"), [null,true], [true, false], [0, false], [0.0, false], ["PT0S", true], [[$this->i("PT0H")], false], [$this->i("PT0H"), true]], [$dateDiff, [null,true], [true, false], [366 * 24 * 60 * 60, false], [1.0 * 366 * 24 * 60 * 60, false], ["P366D", true], [[$dateDiff], false], [$dateNorm, true]], + ["1 year, 2 days", [null,true], [true, false], [0, false], [0.0, false], ["1 year, 2 days", true], [["1 year, 2 days"], false], [\DateInterval::createFromDateString("1 year, 2 days"), false]], ["P1Y2D", [null,true], [true, false], [0, false], [0.0, false], ["P1Y2D", true], [["P1Y2D"], false], [$this->i("P1Y2D"), true]], ] as $set) { // shift the input value off the set