Compare commits
314 Commits
release-20
...
master
Author | SHA1 | Date |
---|---|---|
Andrew Dolgov | 9f734c9050 | 3 years ago |
Andrew Dolgov | 3b70d1f622 | 3 years ago |
Andrew Dolgov | 2a5c2be6cd | 3 years ago |
Andrew Dolgov | 41245da8a6 | 3 years ago |
Andrew Dolgov | 6fe0751038 | 3 years ago |
Andrew Dolgov | 377e0b812c | 3 years ago |
Andrew Dolgov | dd30825b94 | 3 years ago |
fox | d1ffe6d6cf | 3 years ago |
Philip Klempin | aead30a041 | 3 years ago |
Andrew Dolgov | a936e80630 | 3 years ago |
Andrew Dolgov | 9e7e0e84d7 | 3 years ago |
Andrew Dolgov | c6f5902cbc | 3 years ago |
Andrew Dolgov | a9646b9574 | 3 years ago |
Andrew Dolgov | 145fc31625 | 3 years ago |
Andrew Dolgov | 949e2ab4d2 | 3 years ago |
Andrew Dolgov | 8ed927dbd2 | 3 years ago |
Andrew Dolgov | 78ff7770d1 | 3 years ago |
fox | 012a9fdee3 | 3 years ago |
Jon Schewe | e44f0cb937 | 3 years ago |
Andrew Dolgov | 36e174750e | 3 years ago |
fox | b8f82ca12f | 3 years ago |
jmechnich | e8f9567d79 | 3 years ago |
Andrew Dolgov | a1173ab06a | 3 years ago |
Andrew Dolgov | 2c931df77c | 3 years ago |
Andrew Dolgov | 5c60254474 | 3 years ago |
Andrew Dolgov | 0808123179 | 3 years ago |
fox | 5ed108dce4 | 3 years ago |
fox | 28eafa2bcd | 3 years ago |
wn_ | 23b4152c9e | 3 years ago |
wn_ | 992e9cd9e3 | 3 years ago |
Nils Gotzhein | b6b6771d8d | 3 years ago |
fox | a73e3bec45 | 3 years ago |
wn_ | cf0ec06b8c | 3 years ago |
Andrew Dolgov | 73d14338ab | 3 years ago |
Andrew Dolgov | 9669bb94de | 3 years ago |
Andrew Dolgov | 44c5d0feba | 3 years ago |
fox | cd26dbe64c | 3 years ago |
Philip Klempin | 14d57d9a14 | 3 years ago |
fox | 7bd9572aa1 | 3 years ago |
Philip Klempin | 1d4d3bc49c | 3 years ago |
Weblate | f16fc3bf41 | 3 years ago |
Andrew Dolgov | 93a5ba55d3 | 3 years ago |
Andrew Dolgov | 800ebd6373 | 3 years ago |
Andrew Dolgov | 69f261c41d | 3 years ago |
Andrew Dolgov | e9c062a189 | 3 years ago |
fox | 34807bacd4 | 3 years ago |
Andrew Dolgov | 4e9c3500fb | 3 years ago |
Philip Klempin | b3bedd0a94 | 3 years ago |
Andrew Dolgov | 8ed8a10965 | 3 years ago |
Andrew Dolgov | 92c78beb90 | 3 years ago |
Andrew Dolgov | 8e1281b41e | 3 years ago |
Andrew Dolgov | 326850845d | 3 years ago |
Andrew Dolgov | dff479af64 | 3 years ago |
Andrew Dolgov | d09a64d6f9 | 3 years ago |
Andrew Dolgov | 8574532b7f | 3 years ago |
Andrew Dolgov | 4795c4a2a9 | 3 years ago |
Eike | 0f51350e9f | 3 years ago |
Andrew Dolgov | 295fc1f88a | 3 years ago |
Andrew Dolgov | 2adf364c2c | 3 years ago |
Andrew Dolgov | 9f6237a1b8 | 3 years ago |
Andrew Dolgov | 57cd8acfc9 | 3 years ago |
fox | 77031575ab | 3 years ago |
linkai | 983655165e | 3 years ago |
kdan | 6c06a26649 | 3 years ago |
Andrew Dolgov | f423874e05 | 3 years ago |
Andrew Dolgov | b5a559a1a7 | 3 years ago |
Andrew Dolgov | e3c4724dc1 | 3 years ago |
fox | 82749ee7a7 | 3 years ago |
Jacek Tomasiak | 0c38dc8456 | 3 years ago |
kdan | 2ccf0e50a2 | 3 years ago |
linkai | acf0e0d266 | 3 years ago |
Andrew Dolgov | b2f888e386 | 3 years ago |
Andrew Dolgov | fea59de26b | 3 years ago |
Andrew Dolgov | 86300a0ca8 | 3 years ago |
Andrew Dolgov | d11718c89c | 3 years ago |
linkai | 0574675ed6 | 3 years ago |
Andrew Dolgov | e8f78181f1 | 3 years ago |
Andrew Dolgov | 88a7130d79 | 3 years ago |
Andrew Dolgov | e8e4fc641e | 3 years ago |
Andrew Dolgov | df145c8064 | 3 years ago |
Andrew Dolgov | c6befcddb7 | 3 years ago |
Andrew Dolgov | 5a71426ea5 | 3 years ago |
Andrew Dolgov | b3d45a4a5d | 3 years ago |
Andrew Dolgov | cc634ba91d | 3 years ago |
Eike | b12072fef9 | 3 years ago |
fox | a6c5dda7e0 | 3 years ago |
Oliver Haucke | cfd9e6b53b | 3 years ago |
fox | 0f61675cd0 | 3 years ago |
Rodney Stromlund | c18383d1ea | 3 years ago |
Andrew Dolgov | 3e22368962 | 3 years ago |
Andrew Dolgov | eadaaebd58 | 3 years ago |
fox | 61b4a678ea | 3 years ago |
Cyb10101 | c15c1dfb0b | 3 years ago |
Andrew Dolgov | a61348e2b7 | 3 years ago |
Andrew Dolgov | a5af15cfe9 | 3 years ago |
Andrew Dolgov | 49ef15f11d | 3 years ago |
Andrew Dolgov | c0fba62fa0 | 3 years ago |
Andrew Dolgov | 0acd33abe3 | 3 years ago |
Андрій Жук | 0294297ccc | 3 years ago |
Piotr | a4f82fddf4 | 3 years ago |
Glandos | 49b25a6430 | 3 years ago |
fox | f2f2b6d1f4 | 3 years ago |
wn_ | 5d5c034a90 | 3 years ago |
fox | 0b82afabd5 | 3 years ago |
wn_ | 2ed5a79e64 | 3 years ago |
Andrew Dolgov | 8c32ed76df | 3 years ago |
Andrew Dolgov | ceb8179ccc | 3 years ago |
Andrew Dolgov | 19c277391e | 3 years ago |
Andrew Dolgov | 58ab641fea | 3 years ago |
Andrew Dolgov | be2d1602bd | 3 years ago |
Andrew Dolgov | e3c51b0e6c | 3 years ago |
Andrew Dolgov | c34a4c85bd | 3 years ago |
Andrew Dolgov | 0f6644880a | 3 years ago |
Andrew Dolgov | 98251022d4 | 3 years ago |
Andrew Dolgov | 334a361e79 | 3 years ago |
Andrew Dolgov | d275134f26 | 3 years ago |
Andrew Dolgov | 2e6d48ead7 | 3 years ago |
Andrew Dolgov | 43744412f4 | 3 years ago |
Andrew Dolgov | ef5d6b9b78 | 3 years ago |
Andrew Dolgov | e12a6ca540 | 3 years ago |
Andrew Dolgov | 1f5adf1600 | 3 years ago |
Andrew Dolgov | 68299c914b | 3 years ago |
fox | 56f7b25e85 | 3 years ago |
wn_ | 711e8e70e0 | 3 years ago |
Andrew Dolgov | 718c9f07fa | 3 years ago |
Andrew Dolgov | 43ea36d030 | 3 years ago |
fox | ce9955c6ff | 3 years ago |
wn_ | cd52ca80ab | 3 years ago |
wn_ | baf3ecd4cf | 3 years ago |
Andrew Dolgov | 968270ed48 | 3 years ago |
wn_ | 541a07250c | 3 years ago |
wn_ | f057c124d1 | 3 years ago |
wn_ | 7ea48f7a4b | 3 years ago |
wn_ | b6ae280446 | 3 years ago |
Andrew Dolgov | db0315e596 | 3 years ago |
Andrew Dolgov | 88534a8ae4 | 3 years ago |
Andrew Dolgov | 82bed1e651 | 3 years ago |
fox | 7c2b473d12 | 3 years ago |
wn_ | 401b22666d | 3 years ago |
Andrew Dolgov | 0f5fd9ea13 | 3 years ago |
Andrew Dolgov | 32c080bec0 | 3 years ago |
Andrew Dolgov | 166517240e | 3 years ago |
Andrew Dolgov | 7a1e1630d8 | 3 years ago |
Andrew Dolgov | 92f859add2 | 3 years ago |
Andrew Dolgov | a0e41f41a4 | 3 years ago |
Andrew Dolgov | 7ec8a6cad0 | 3 years ago |
Andrew Dolgov | d9ba403927 | 3 years ago |
Andrew Dolgov | 44b274b6d4 | 3 years ago |
fox | c134aa387d | 3 years ago |
Andrew Dolgov | f81a579386 | 3 years ago |
JustAMacUser | 39bbbef030 | 3 years ago |
Andrew Dolgov | 1870fe172b | 3 years ago |
Andrew Dolgov | b23ba3e236 | 3 years ago |
Andrew Dolgov | a0ce7f556b | 3 years ago |
Andrew Dolgov | 1664b87821 | 3 years ago |
Andrew Dolgov | 13210747d8 | 3 years ago |
Andrew Dolgov | 15b39a534d | 3 years ago |
Andrew Dolgov | f7ee812db2 | 3 years ago |
fox | 1b71cd9f44 | 3 years ago |
Jordan Galby | 3d801b1ac5 | 3 years ago |
Andrew Dolgov | 2f402d598d | 3 years ago |
Andrew Dolgov | 38ab3ef11c | 3 years ago |
Andrew Dolgov | 4ddcd54e8d | 3 years ago |
fox | 06ebb81eb8 | 3 years ago |
Philip Klempin | fa22e1bc35 | 3 years ago |
Andrew Dolgov | 4e81233ac9 | 3 years ago |
Andrew Dolgov | fcce1c443e | 3 years ago |
Andrew Dolgov | bc73bf0f67 | 3 years ago |
Andrew Dolgov | efde6d36c7 | 3 years ago |
Andrew Dolgov | e85cba5958 | 3 years ago |
Marek Pavelka | f9d366f028 | 3 years ago |
Andrew Dolgov | 52d1a5c96d | 3 years ago |
Andrew Dolgov | 580eccd3da | 3 years ago |
Andrew Dolgov | b9268fcc88 | 3 years ago |
Andrew Dolgov | 96d89fe912 | 3 years ago |
Andrew Dolgov | bd1630d278 | 3 years ago |
Andrew Dolgov | 76a6060ca3 | 3 years ago |
Andrew Dolgov | 4949e1a590 | 3 years ago |
Andrew Dolgov | 146b1e0feb | 3 years ago |
Andrew Dolgov | 6e0474a7c8 | 3 years ago |
Andrew Dolgov | f67d2623b7 | 3 years ago |
Andrew Dolgov | a4da2f1e62 | 3 years ago |
Andrew Dolgov | 755072de91 | 3 years ago |
Andrew Dolgov | de47082ca6 | 3 years ago |
Andrew Dolgov | f9a381ecca | 3 years ago |
Andrew Dolgov | 27ab16b6dc | 3 years ago |
Andrew Dolgov | 324aef9f6f | 3 years ago |
Andrew Dolgov | 03361dda34 | 3 years ago |
Andrew Dolgov | 24e64b8c78 | 3 years ago |
Andrew Dolgov | 21e0b28cf1 | 3 years ago |
Andrew Dolgov | f9a9fcbb56 | 3 years ago |
Andrew Dolgov | 3e1b3e8ea8 | 3 years ago |
Andrew Dolgov | 143617afb1 | 3 years ago |
Andrew Dolgov | 84fe383ed4 | 3 years ago |
Andrew Dolgov | 16726ec07f | 3 years ago |
Andrew Dolgov | a0dd5baa51 | 3 years ago |
Andrew Dolgov | 5e738ec278 | 3 years ago |
Andrew Dolgov | 71b12857e0 | 3 years ago |
Andrew Dolgov | 353ee40378 | 3 years ago |
Andrew Dolgov | 668b0ac7a6 | 3 years ago |
Andrew Dolgov | fb89c3bad0 | 3 years ago |
Andrew Dolgov | 5bc47451e1 | 3 years ago |
Andrew Dolgov | 36ad46e60d | 3 years ago |
Ptsa Daniel | 02af69328f | 3 years ago |
Dario Di Ludovico | 4aa595e3ba | 3 years ago |
Andrew Dolgov | 96031c80bf | 3 years ago |
Andrew Dolgov | e826c9e055 | 3 years ago |
Andrew Dolgov | f58879c1dc | 3 years ago |
Andrew Dolgov | bdc72e5b63 | 3 years ago |
Andrew Dolgov | df9c389cbf | 3 years ago |
Andrew Dolgov | b6033d0bbd | 3 years ago |
Andrew Dolgov | 0b93d8d013 | 3 years ago |
Andrew Dolgov | 089fa5ec26 | 3 years ago |
Andrew Dolgov | 87d13e826f | 3 years ago |
Andrew Dolgov | eba8c97f36 | 3 years ago |
Andrew Dolgov | a3ab4020bf | 3 years ago |
Andrew Dolgov | ddfa39015e | 3 years ago |
Andrew Dolgov | 6ec66d0ce5 | 3 years ago |
Andrew Dolgov | f804caec90 | 3 years ago |
Andrew Dolgov | ae7b87bca9 | 3 years ago |
Andrew Dolgov | 2160a86092 | 3 years ago |
Andrew Dolgov | 4e1c78374f | 3 years ago |
Andrew Dolgov | 74391ec30a | 3 years ago |
Andrew Dolgov | dd9d017f7d | 3 years ago |
Andrew Dolgov | 9b321be270 | 3 years ago |
Andrew Dolgov | 4fe2e6bbf1 | 3 years ago |
Andrew Dolgov | b1961163b8 | 3 years ago |
Andrew Dolgov | bc7cb76379 | 3 years ago |
Weblate | 63ca6333a5 | 3 years ago |
Andrew Dolgov | ea25c49eb9 | 3 years ago |
Andrew Dolgov | fe4c284858 | 3 years ago |
fox | 9b2267510b | 3 years ago |
wn_ | fed5158ec5 | 3 years ago |
Andrew Dolgov | cfb4882591 | 3 years ago |
Andrew Dolgov | 28dd255c30 | 3 years ago |
Andrew Dolgov | bfeaf4d6a4 | 3 years ago |
Andrew Dolgov | ef03f8188c | 3 years ago |
Andrew Dolgov | c26f58d8a5 | 3 years ago |
Andrew Dolgov | a125e8540d | 3 years ago |
Andrew Dolgov | 1fb7125f90 | 3 years ago |
Andrew Dolgov | 46b77fc6b7 | 3 years ago |
Andrew Dolgov | 5db6939dc9 | 3 years ago |
Andrew Dolgov | 603cc89638 | 3 years ago |
Andrew Dolgov | f4d0e7bb6d | 3 years ago |
Andrew Dolgov | 72c04123d4 | 3 years ago |
Andrew Dolgov | 518e677a6b | 3 years ago |
Andrew Dolgov | 266c8a6eae | 3 years ago |
Andrew Dolgov | ac6a59914b | 3 years ago |
Andrew Dolgov | ffb93d72ac | 3 years ago |
Andrew Dolgov | 773bad1490 | 3 years ago |
Andrew Dolgov | 1dcc36deca | 3 years ago |
Andrew Dolgov | c036c27ec7 | 3 years ago |
Andrew Dolgov | 17650775d2 | 3 years ago |
Andrew Dolgov | 5bb8714839 | 3 years ago |
Andrew Dolgov | 77b5201b7d | 3 years ago |
Andrew Dolgov | d6fd0d5462 | 3 years ago |
Andrew Dolgov | 39c570a9ff | 3 years ago |
Andrew Dolgov | b27218a1e3 | 3 years ago |
fox | cb81b784e8 | 3 years ago |
Andrew Dolgov | 1d9fa2a42e | 3 years ago |
ltGuillaume | 825e362f0e | 3 years ago |
Andrew Dolgov | 7b0b5b55c7 | 3 years ago |
Andrew Dolgov | 68ecf52594 | 3 years ago |
Andrew Dolgov | 473ea6255c | 3 years ago |
Andrew Dolgov | 217922899d | 3 years ago |
Andrew Dolgov | 270f0c3132 | 3 years ago |
Andrew Dolgov | 63651bd91d | 3 years ago |
Andrew Dolgov | e5469479c1 | 3 years ago |
Andrew Dolgov | 42e057c808 | 3 years ago |
Andrew Dolgov | 53dcd4b229 | 3 years ago |
fox | 42cb2e5112 | 3 years ago |
wn_ | 2e8b064236 | 3 years ago |
Andrew Dolgov | 2cd159e2ce | 3 years ago |
Andrew Dolgov | 2aed79d729 | 3 years ago |
Andrew Dolgov | ecb94ec23d | 3 years ago |
Andrew Dolgov | 5c1f9f31bd | 3 years ago |
Andrew Dolgov | fe06416f17 | 3 years ago |
Andrew Dolgov | 98c75a9e43 | 3 years ago |
Andrew Dolgov | b649d2240f | 3 years ago |
Andrew Dolgov | c8883d3440 | 3 years ago |
Andrew Dolgov | bc2953b5e7 | 3 years ago |
Andrew Dolgov | 198c9b4069 | 3 years ago |
Andrew Dolgov | e8e6329040 | 3 years ago |
Andrew Dolgov | c744cfe2dc | 3 years ago |
Andrew Dolgov | d016f7a499 | 3 years ago |
Andrew Dolgov | 476965b161 | 3 years ago |
fox | c9b0196de0 | 3 years ago |
Threk | 9442ceb7bd | 3 years ago |
Andrew Dolgov | f398fea414 | 3 years ago |
Andrew Dolgov | cb4b730e42 | 3 years ago |
Andrew Dolgov | 386dc415d9 | 3 years ago |
Andrew Dolgov | 9b8b07376f | 3 years ago |
Andrew Dolgov | f90531ae40 | 3 years ago |
Andrew Dolgov | 6cf771f2bc | 3 years ago |
Andrew Dolgov | c50a4296a5 | 3 years ago |
Andrew Dolgov | 04128c7870 | 3 years ago |
Andrew Dolgov | 2f6ea8b387 | 3 years ago |
Andrew Dolgov | b74e313844 | 3 years ago |
Andrew Dolgov | 4fda5ccd0e | 3 years ago |
Andrew Dolgov | 30765805fd | 3 years ago |
Andrew Dolgov | 31b29e0a56 | 3 years ago |
Andrew Dolgov | 8f8ca49e4b | 3 years ago |
Andrew Dolgov | 4ede76280b | 3 years ago |
Andrew Dolgov | bd4ade6329 | 3 years ago |
Andrew Dolgov | 5eb0f3d640 | 3 years ago |
Andrew Dolgov | e19570f422 | 3 years ago |
Andrew Dolgov | c0fb0a5ec0 | 3 years ago |
Andrew Dolgov | 921569e5da | 3 years ago |
Andrew Dolgov | 8256ab5dd9 | 3 years ago |
Andrew Dolgov | 0cb719a404 | 3 years ago |
Marek Pavelka | 5c6c123676 | 3 years ago |
Andrew Dolgov | dfdb746a76 | 3 years ago |
Andrew Dolgov | cb7f322f09 | 3 years ago |
Ptsa Daniel | 5832b0b040 | 3 years ago |
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
class Db_Migrations {
|
||||
|
||||
private $base_filename = "schema.sql";
|
||||
private $base_path;
|
||||
private $migrations_path;
|
||||
private $migrations_table;
|
||||
private $base_is_latest;
|
||||
private $pdo;
|
||||
|
||||
private $cached_version;
|
||||
private $cached_max_version;
|
||||
private $max_version_override;
|
||||
|
||||
function __construct() {
|
||||
$this->pdo = Db::pdo();
|
||||
}
|
||||
|
||||
function initialize_for_plugin(Plugin $plugin, bool $base_is_latest = true, string $schema_suffix = "sql") {
|
||||
$plugin_dir = PluginHost::getInstance()->get_plugin_dir($plugin);
|
||||
$this->initialize($plugin_dir . "/${schema_suffix}",
|
||||
strtolower("ttrss_migrations_plugin_" . get_class($plugin)),
|
||||
$base_is_latest);
|
||||
}
|
||||
|
||||
function initialize(string $root_path, string $migrations_table, bool $base_is_latest = true, int $max_version_override = 0) {
|
||||
$this->base_path = "$root_path/" . Config::get(Config::DB_TYPE);
|
||||
$this->migrations_path = $this->base_path . "/migrations";
|
||||
$this->migrations_table = $migrations_table;
|
||||
$this->base_is_latest = $base_is_latest;
|
||||
$this->max_version_override = $max_version_override;
|
||||
}
|
||||
|
||||
private function set_version(int $version) {
|
||||
Debug::log("Updating table {$this->migrations_table} with version ${version}...", Debug::LOG_EXTENDED);
|
||||
|
||||
$sth = $this->pdo->query("SELECT * FROM {$this->migrations_table}");
|
||||
|
||||
if ($res = $sth->fetch()) {
|
||||
$sth = $this->pdo->prepare("UPDATE {$this->migrations_table} SET schema_version = ?");
|
||||
} else {
|
||||
$sth = $this->pdo->prepare("INSERT INTO {$this->migrations_table} (schema_version) VALUES (?)");
|
||||
}
|
||||
|
||||
$sth->execute([$version]);
|
||||
|
||||
$this->cached_version = $version;
|
||||
}
|
||||
|
||||
function get_version() : int {
|
||||
if (isset($this->cached_version))
|
||||
return $this->cached_version;
|
||||
|
||||
try {
|
||||
$sth = $this->pdo->query("SELECT * FROM {$this->migrations_table}");
|
||||
|
||||
if ($res = $sth->fetch()) {
|
||||
return (int) $res['schema_version'];
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$this->create_migrations_table();
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private function create_migrations_table() {
|
||||
$this->pdo->query("CREATE TABLE IF NOT EXISTS {$this->migrations_table} (schema_version integer not null)");
|
||||
}
|
||||
|
||||
private function migrate_to(int $version) {
|
||||
try {
|
||||
if ($version <= $this->get_version()) {
|
||||
Debug::log("Refusing to apply version $version: current version is higher", Debug::LOG_VERBOSE);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($version == 0)
|
||||
Debug::log("Loading base database schema...", Debug::LOG_VERBOSE);
|
||||
else
|
||||
Debug::log("Starting migration to $version...", Debug::LOG_VERBOSE);
|
||||
|
||||
$lines = $this->get_lines($version);
|
||||
|
||||
if (count($lines) > 0) {
|
||||
// mysql doesn't support transactions for DDL statements
|
||||
if (Config::get(Config::DB_TYPE) != "mysql")
|
||||
$this->pdo->beginTransaction();
|
||||
|
||||
foreach ($lines as $line) {
|
||||
Debug::log($line, Debug::LOG_EXTENDED);
|
||||
try {
|
||||
$this->pdo->query($line);
|
||||
} catch (PDOException $e) {
|
||||
Debug::log("Failed on line: $line", Debug::LOG_VERBOSE);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
if ($version == 0 && $this->base_is_latest)
|
||||
$this->set_version($this->get_max_version());
|
||||
else
|
||||
$this->set_version($version);
|
||||
|
||||
if (Config::get(Config::DB_TYPE) != "mysql")
|
||||
$this->pdo->commit();
|
||||
|
||||
Debug::log("Migration finished, current version: " . $this->get_version(), Debug::LOG_VERBOSE);
|
||||
|
||||
Logger::log(E_USER_NOTICE, "Applied migration to version $version for {$this->migrations_table}");
|
||||
} else {
|
||||
Debug::log("Migration failed: schema file is empty or missing.", Debug::LOG_VERBOSE);
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
Debug::log("Migration failed: " . $e->getMessage(), Debug::LOG_VERBOSE);
|
||||
try {
|
||||
$this->pdo->rollback();
|
||||
} catch (PDOException $ie) {
|
||||
//
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
function get_max_version() : int {
|
||||
if ($this->max_version_override > 0)
|
||||
return $this->max_version_override;
|
||||
|
||||
if (isset($this->cached_max_version))
|
||||
return $this->cached_max_version;
|
||||
|
||||
$migrations = glob("{$this->migrations_path}/*.sql");
|
||||
|
||||
if (count($migrations) > 0) {
|
||||
natsort($migrations);
|
||||
|
||||
$this->cached_max_version = (int) basename(array_pop($migrations), ".sql");
|
||||
|
||||
} else {
|
||||
$this->cached_max_version = 0;
|
||||
}
|
||||
|
||||
return $this->cached_max_version;
|
||||
}
|
||||
|
||||
function is_migration_needed() : bool {
|
||||
return $this->get_version() != $this->get_max_version();
|
||||
}
|
||||
|
||||
function migrate() : bool {
|
||||
|
||||
if ($this->get_version() == -1) {
|
||||
try {
|
||||
$this->migrate_to(0);
|
||||
} catch (PDOException $e) {
|
||||
user_error("Failed to load base schema for {$this->migrations_table}: " . $e->getMessage(), E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = $this->get_version() + 1; $i <= $this->get_max_version(); $i++) {
|
||||
try {
|
||||
$this->migrate_to($i);
|
||||
} catch (PDOException $e) {
|
||||
user_error("Failed to apply migration ${i} for {$this->migrations_table}: " . $e->getMessage(), E_USER_WARNING);
|
||||
return false;
|
||||
//throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->is_migration_needed();
|
||||
}
|
||||
|
||||
private function get_lines(int $version) : array {
|
||||
if ($version > 0)
|
||||
$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;
|
||||
});
|
||||
|
||||
return array_filter(explode(";", implode("", $lines)), function ($line) {
|
||||
return strlen(trim($line)) > 0 && !in_array(strtolower($line), ["begin", "commit"]);
|
||||
});
|
||||
|
||||
} else {
|
||||
user_error("Requested schema file ${filename} not found.", E_USER_ERROR);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
<?php
|
||||
class Db_Updater {
|
||||
const SCHEMA_VERSION = 142;
|
||||
|
||||
private $pdo;
|
||||
private $db_type;
|
||||
|
||||
function __construct($pdo, $db_type) {
|
||||
$this->pdo = $pdo;
|
||||
$this->db_type = $db_type;
|
||||
}
|
||||
|
||||
/** always returns actual (=uncached) value */
|
||||
private static function get_schema_version() {
|
||||
return Config::get_schema_version(true);
|
||||
}
|
||||
|
||||
static function is_update_required() {
|
||||
return self::get_schema_version() < self::SCHEMA_VERSION;
|
||||
}
|
||||
|
||||
function get_schema_lines($version) {
|
||||
$filename = "schema/versions/".$this->db_type."/$version.sql";
|
||||
|
||||
if (file_exists($filename)) {
|
||||
return explode(";", (string)preg_replace("/[\r\n]/", "", (string)file_get_contents($filename)));
|
||||
} else {
|
||||
user_error("DB Updater: schema file for version $version is not found.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function update_to($version, $html_output = true) {
|
||||
if ($this->get_schema_version() == $version - 1) {
|
||||
|
||||
$lines = $this->get_schema_lines($version);
|
||||
|
||||
if (is_array($lines)) {
|
||||
|
||||
$this->pdo->beginTransaction();
|
||||
|
||||
foreach ($lines as $line) {
|
||||
if (strpos($line, "--") !== 0 && $line) {
|
||||
|
||||
if ($html_output)
|
||||
print "<pre>$line</pre>";
|
||||
else
|
||||
Debug::log("> $line");
|
||||
|
||||
try {
|
||||
$this->pdo->query($line); // PDO returns errors as exceptions now
|
||||
} catch (PDOException $e) {
|
||||
if ($html_output) {
|
||||
print "<div class='text-error'>Error: " . $e->getMessage() . "</div>";
|
||||
} else {
|
||||
Debug::log("Error: " . $e->getMessage());
|
||||
}
|
||||
|
||||
$this->pdo->rollBack();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$db_version = self::get_schema_version();
|
||||
|
||||
if ($db_version == $version) {
|
||||
$this->pdo->commit();
|
||||
return true;
|
||||
} else {
|
||||
$this->pdo->rollBack();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.0 KiB |
@ -0,0 +1,17 @@
|
||||
<!-- By Sam Herbert (@sherb), for everyone. More @ http://goo.gl/7AJzbL -->
|
||||
<svg width="38" height="38" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg" stroke="#257aa7">
|
||||
<g fill="none" fill-rule="evenodd">
|
||||
<g stroke-width="8" transform="matrix(0.83009609,0,0,0.83009609,4.0582705,4.0582705)">
|
||||
<circle stroke-opacity=".5" cx="18" cy="18" r="18"/>
|
||||
<path d="M 36,18 C 36,8.06 27.94,0 18,0">
|
||||
<animateTransform
|
||||
attributeName="transform"
|
||||
type="rotate"
|
||||
from="0 18 18"
|
||||
to="360 18 18"
|
||||
dur="1s"
|
||||
repeatCount="indefinite"/>
|
||||
</path>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 740 B |
@ -0,0 +1,33 @@
|
||||
<!-- By Sam Herbert (@sherb), for everyone. More @ http://goo.gl/7AJzbL -->
|
||||
<svg width="120" height="30" viewBox="0 0 120 30" xmlns="http://www.w3.org/2000/svg" fill="#257aa7">
|
||||
<circle cx="15" cy="15" r="15">
|
||||
<animate attributeName="r" from="15" to="15"
|
||||
begin="0s" dur="0.8s"
|
||||
values="15;9;15" calcMode="linear"
|
||||
repeatCount="indefinite" />
|
||||
<animate attributeName="fill-opacity" from="1" to="1"
|
||||
begin="0s" dur="0.8s"
|
||||
values="1;.5;1" calcMode="linear"
|
||||
repeatCount="indefinite" />
|
||||
</circle>
|
||||
<circle cx="60" cy="15" r="9" fill-opacity="0.3">
|
||||
<animate attributeName="r" from="9" to="9"
|
||||
begin="0s" dur="0.8s"
|
||||
values="9;15;9" calcMode="linear"
|
||||
repeatCount="indefinite" />
|
||||
<animate attributeName="fill-opacity" from="0.5" to="0.5"
|
||||
begin="0s" dur="0.8s"
|
||||
values=".5;1;.5" calcMode="linear"
|
||||
repeatCount="indefinite" />
|
||||
</circle>
|
||||
<circle cx="105" cy="15" r="15">
|
||||
<animate attributeName="r" from="15" to="15"
|
||||
begin="0s" dur="0.8s"
|
||||
values="15;9;15" calcMode="linear"
|
||||
repeatCount="indefinite" />
|
||||
<animate attributeName="fill-opacity" from="1" to="1"
|
||||
begin="0s" dur="0.8s"
|
||||
values="1;.5;1" calcMode="linear"
|
||||
repeatCount="indefinite" />
|
||||
</circle>
|
||||
</svg>
|
After Width: | Height: | Size: 1.5 KiB |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue