From dbe83f8a747a792add9045e645f9be78e7a13148 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 24 May 2020 18:43:26 +0200 Subject: [PATCH] Move migration into separate file + add into admin panel This fixes some rare bugs when database is no up-to-date and someone enters admin panel --- admin/index.php | 1 + index.php | 21 +-------------------- system/migrate.php | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 system/migrate.php diff --git a/admin/index.php b/admin/index.php index 41f817c4..73267e64 100644 --- a/admin/index.php +++ b/admin/index.php @@ -34,6 +34,7 @@ $hooks->load(); require SYSTEM . 'status.php'; require SYSTEM . 'login.php'; +require SYSTEM . 'migrate.php'; require ADMIN . 'includes/functions.php'; $twig->addGlobal('config', $config); diff --git a/index.php b/index.php index ff1801c4..32e8599c 100644 --- a/index.php +++ b/index.php @@ -186,26 +186,7 @@ if(!$db->hasTable('myaac_account_actions')) { throw new RuntimeException('Seems that the table myaac_account_actions of MyAAC doesn\'t exist in the database. This is a fatal error. You can try to reinstall MyAAC by visiting this url.'); } -// database migrations -$tmp = ''; -if(fetchDatabaseConfig('database_version', $tmp)) { // we got version - $tmp = (int)$tmp; - if($tmp < DATABASE_VERSION) { // import if older - $db->revalidateCache(); - for($i = $tmp + 1; $i <= DATABASE_VERSION; $i++) { - require SYSTEM . 'migrations/' . $i . '.php'; - updateDatabaseConfig('database_version', $i); - } - } -} -else { // register first version - registerDatabaseConfig('database_version', 0); - $db->revalidateCache(); - for($i = 1; $i <= DATABASE_VERSION; $i++) { - require SYSTEM . 'migrations/' . $i . '.php'; - updateDatabaseConfig('database_version', $i); - } -} +require SYSTEM . 'migrate.php'; $hooks->trigger(HOOK_STARTUP); diff --git a/system/migrate.php b/system/migrate.php new file mode 100644 index 00000000..46daeef6 --- /dev/null +++ b/system/migrate.php @@ -0,0 +1,22 @@ +revalidateCache(); + for($i = $tmp + 1; $i <= DATABASE_VERSION; $i++) { + require SYSTEM . 'migrations/' . $i . '.php'; + updateDatabaseConfig('database_version', $i); + } + } +} +else { // register first version + registerDatabaseConfig('database_version', 0); + $db->revalidateCache(); + for($i = 1; $i <= DATABASE_VERSION; $i++) { + require SYSTEM . 'migrations/' . $i . '.php'; + updateDatabaseConfig('database_version', $i); + } +} \ No newline at end of file