diff --git a/lib/AbstractException.php b/lib/AbstractException.php index cde92dc..5be1008 100644 --- a/lib/AbstractException.php +++ b/lib/AbstractException.php @@ -38,6 +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.paramTypeInvalid" => 10221, "Db/Exception.paramTypeUnknown" => 10222, "Db/Exception.paramTypeMissing" => 10223, diff --git a/lib/Database.php b/lib/Database.php index 2049f27..19b163d 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -25,7 +25,7 @@ use JKingWeb\Arsse\Rule\Exception as RuleException; * * - Users * - Subscriptions to feeds, which belong to users - * - Folders, which belong to users and contain subscriptions + * - Folders, which belong to users and contain subscriptions or other folders * - Tags, which belong to users and can be assigned to multiple subscriptions * - Icons, which are associated with subscriptions * - Articles, which belong to subscriptions @@ -76,9 +76,15 @@ class Database { public function __construct($initialize = true) { $driver = Arsse::$conf->dbDriver; $this->db = $driver::create(); + $this->checkSchemaVersion($initialize); + } + + public function checkSchemaVersion(bool $initialize = false): void { $ver = $this->db->schemaVersion(); if ($initialize && $ver < self::SCHEMA_VERSION) { $this->db->schemaUpdate(self::SCHEMA_VERSION); + } elseif ($ver != self::SCHEMA_VERSION) { + throw new Db\Exception("updateSchemaChange"); } } diff --git a/lib/Service.php b/lib/Service.php index 79a5346..0bbbdd1 100644 --- a/lib/Service.php +++ b/lib/Service.php @@ -66,6 +66,7 @@ class Service { } public function checkIn(): bool { + Arsse::$db->checkSchemaVersion(); return Arsse::$db->metaSet("service_last_checkin", time(), "datetime"); } diff --git a/locale/en.php b/locale/en.php index c954647..b6b37bb 100644 --- a/locale/en.php +++ b/locale/en.php @@ -147,6 +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 has changed since the application was started; application restart is required', 'Exception.JKingWeb/Arsse/Db/Exception.engineErrorGeneral' => '{0}', // indicates programming error 'Exception.JKingWeb/Arsse/Db/Exception.savepointStatusUnknown' => 'Savepoint status code {0} not implemented',