Browse Source

Work around possible MySQL bug

reader
J. King 2 years ago
parent
commit
e6505a5fda
  1. 6
      CHANGELOG
  2. 2
      lib/Db/MySQL/Driver.php
  3. 8
      lib/Misc/ValueInfo.php
  4. 6
      tests/cases/Misc/TestValueInfo.php

6
CHANGELOG

@ -1,3 +1,9 @@
Version 0.1?.? (2022-??-??)
===========================
Bug fixes:
- Perform MySQL table maintenance more reliably
Version 0.10.2 (2022-04-04) Version 0.10.2 (2022-04-04)
=========================== ===========================

2
lib/Db/MySQL/Driver.php

@ -224,7 +224,7 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
public function maintenance(): bool { public function maintenance(): bool {
// with MySQL each table must be analyzed separately, so we first have to get a list of tables // with MySQL each table must be analyzed separately, so we first have to get a list of tables
foreach ($this->query("SHOW TABLES like 'arsse\\_%'") as $table) { foreach ($this->query("SHOW TABLES like 'arsse%'") as $table) {
$table = array_pop($table); $table = array_pop($table);
if (!preg_match("/^arsse_[a-z_]+$/D", $table)) { if (!preg_match("/^arsse_[a-z_]+$/D", $table)) {
// table is not one of ours // table is not one of ours

8
lib/Misc/ValueInfo.php

@ -283,12 +283,8 @@ class ValueInfo {
} }
return $out->setTimezone(new \DateTimeZone("UTC")); return $out->setTimezone(new \DateTimeZone("UTC"));
} else { } else {
$out = new \DateTimeImmutable($value, new \DateTimeZone("UTC")); // if the string fails to parse it will produce an exception which is caught just below
if ($out) { return (new \DateTimeImmutable($value, new \DateTimeZone("UTC")))->setTimezone(new \DateTimeZone("UTC"));
return $out->setTimezone(new \DateTimeZone("UTC"));
} elseif ($strict && !$drop) {
throw new \Exception;
}
} }
} catch (\Exception $e) { } catch (\Exception $e) {
if ($strict && !$drop) { if ($strict && !$drop) {

6
tests/cases/Misc/TestValueInfo.php

@ -568,7 +568,7 @@ class TestValueInfo extends \JKingWeb\Arsse\Test\AbstractTest {
null, null,
]; ];
foreach ([ foreach ([
/* Input value microtime iso8601 iso8601m http sql date time unix float '!M j, Y (D)' *strtotime* (null) */ /* Input value microtime iso8601 iso8601m http sql date time unix float '!M j, Y (D)' *strtotime* (null) */
[null, null, null, null, null, null, null, null, null, null, null, null], [null, null, null, null, null, null, null, null, null, null, null, null],
[INF, null, null, null, null, null, null, null, null, null, null, null], [INF, null, null, null, null, null, null, null, null, null, null, null],
[NAN, null, null, null, null, null, null, null, null, null, null, null], [NAN, null, null, null, null, null, null, null, null, null, null, null],
@ -600,7 +600,7 @@ class TestValueInfo extends \JKingWeb\Arsse\Test\AbstractTest {
[[], null, null, null, null, null, null, null, null, null, null, null], [[], null, null, null, null, null, null, null, null, null, null, null],
[$this->i("P1Y2D"), null, null, null, null, null, null, null, null, null, null, null], [$this->i("P1Y2D"), null, null, null, null, null, null, null, null, null, null, null],
["P1Y2D", null, null, null, null, null, null, null, null, null, null, null], ["P1Y2D", null, null, null, null, null, null, null, null, null, null, null],
] as $set) { ] as $k => $set) {
// shift the input value off the set // shift the input value off the set
$input = array_shift($set); $input = array_shift($set);
// generate a set of tests for each target date formats // generate a set of tests for each target date formats
@ -612,7 +612,7 @@ class TestValueInfo extends \JKingWeb\Arsse\Test\AbstractTest {
[false, true], [false, true],
[true, true], [true, true],
] as [$strict, $drop]) { ] as [$strict, $drop]) {
yield [$input, $formats[$format], $exp, $strict, $drop]; yield "Index #$k format \"$format\" strict:$strict drop:$drop" => [$input, $formats[$format], $exp, $strict, $drop];
} }
} }
} }

Loading…
Cancel
Save