Skip to content

Commit

Permalink
Fix MySQL failure and shore up coverage
Browse files Browse the repository at this point in the history
This marks the end of the feed reduplication effort
  • Loading branch information
JKingweb committed Mar 15, 2023
1 parent eed42dd commit bbdc4f7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/AbstractException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 15 additions & 8 deletions lib/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ public function checkSchemaVersion(bool $initialize = false): void {
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
}
}
}
Expand Down Expand Up @@ -1151,7 +1152,6 @@ protected function subscriptionRulesApply(string $user, int $id): void {
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
Expand Down Expand Up @@ -1277,13 +1277,17 @@ public function subscriptionUpdate(?string $user, $subID, bool $throwError = fal
// 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();
Expand Down Expand Up @@ -2473,10 +2477,13 @@ public function tagAdd(string $user, array $data): int {
* @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
Expand Down
2 changes: 1 addition & 1 deletion locale/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
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',
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/Database/SeriesArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ public function testMarkMultipleEditions(): void {
}

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);
}
Expand Down
1 change: 1 addition & 0 deletions tests/cases/Misc/TestValueInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ public function provideSimpleNormalizationValues(): iterable {
[$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
Expand Down

0 comments on commit bbdc4f7

Please sign in to comment.