summaryrefslogtreecommitdiff
path: root/classes/db/migrations.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/db/migrations.php')
-rw-r--r--classes/db/migrations.php57
1 files changed, 18 insertions, 39 deletions
diff --git a/classes/db/migrations.php b/classes/db/migrations.php
index aecd9186c..d63736987 100644
--- a/classes/db/migrations.php
+++ b/classes/db/migrations.php
@@ -1,33 +1,15 @@
<?php
class Db_Migrations {
- // TODO: class properties can be switched to PHP typing if/when the minimum PHP_VERSION is raised to 7.4.0+
- /** @var string */
- private $base_filename = "schema.sql";
-
- /** @var string */
- private $base_path;
-
- /** @var string */
- private $migrations_path;
-
- /** @var string */
- private $migrations_table;
-
- /** @var bool */
- private $base_is_latest;
-
- /** @var PDO */
- private $pdo;
-
- /** @var int */
- private $cached_version = 0;
-
- /** @var int */
- private $cached_max_version = 0;
-
- /** @var int */
- private $max_version_override;
+ private string $base_filename = "schema.sql";
+ private string $base_path;
+ private string $migrations_path;
+ private string $migrations_table;
+ private bool $base_is_latest;
+ private PDO $pdo;
+ private int $cached_version = 0;
+ private int $cached_max_version = 0;
+ private int $max_version_override;
function __construct() {
$this->pdo = Db::pdo();
@@ -35,7 +17,7 @@ class Db_Migrations {
function initialize_for_plugin(Plugin $plugin, bool $base_is_latest = true, string $schema_suffix = "sql"): void {
$plugin_dir = PluginHost::getInstance()->get_plugin_dir($plugin);
- $this->initialize($plugin_dir . "/${schema_suffix}",
+ $this->initialize("{$plugin_dir}/{$schema_suffix}",
strtolower("ttrss_migrations_plugin_" . get_class($plugin)),
$base_is_latest);
}
@@ -49,7 +31,7 @@ class Db_Migrations {
}
private function set_version(int $version): void {
- Debug::log("Updating table {$this->migrations_table} with version ${version}...", Debug::LOG_EXTENDED);
+ Debug::log("Updating table {$this->migrations_table} with version {$version}...", Debug::LOG_EXTENDED);
$sth = $this->pdo->query("SELECT * FROM {$this->migrations_table}");
@@ -188,7 +170,7 @@ class Db_Migrations {
try {
$this->migrate_to($i);
} catch (PDOException $e) {
- user_error("Failed to apply migration ${i} for {$this->migrations_table}: " . $e->getMessage(), E_USER_WARNING);
+ user_error("Failed to apply migration {$i} for {$this->migrations_table}: " . $e->getMessage(), E_USER_WARNING);
return false;
//throw $e;
}
@@ -202,22 +184,19 @@ class Db_Migrations {
*/
private function get_lines(int $version) : array {
if ($version > 0)
- $filename = "{$this->migrations_path}/${version}.sql";
+ $filename = "{$this->migrations_path}/{$version}.sql";
else
$filename = "{$this->base_path}/{$this->base_filename}";
if (file_exists($filename)) {
- $lines = array_filter(preg_split("/[\r\n]/", file_get_contents($filename)),
- function ($line) {
- return strlen(trim($line)) > 0 && strpos($line, "--") !== 0;
- });
+ $lines = array_filter(preg_split("/[\r\n]/", file_get_contents($filename)),
+ fn($line) => strlen(trim($line)) > 0 && strpos($line, "--") !== 0);
- return array_filter(explode(";", implode("", $lines)), function ($line) {
- return strlen(trim($line)) > 0 && !in_array(strtolower($line), ["begin", "commit"]);
- });
+ return array_filter(explode(";", implode("", $lines)),
+ fn($line) => strlen(trim($line)) > 0 && !in_array(strtolower($line), ["begin", "commit"]));
} else {
- user_error("Requested schema file ${filename} not found.", E_USER_ERROR);
+ user_error("Requested schema file {$filename} not found.", E_USER_ERROR);
return [];
}
}