mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
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
This commit is contained in:
parent
d1c50f00a0
commit
dbe83f8a74
@ -34,6 +34,7 @@ $hooks->load();
|
|||||||
|
|
||||||
require SYSTEM . 'status.php';
|
require SYSTEM . 'status.php';
|
||||||
require SYSTEM . 'login.php';
|
require SYSTEM . 'login.php';
|
||||||
|
require SYSTEM . 'migrate.php';
|
||||||
require ADMIN . 'includes/functions.php';
|
require ADMIN . 'includes/functions.php';
|
||||||
|
|
||||||
$twig->addGlobal('config', $config);
|
$twig->addGlobal('config', $config);
|
||||||
|
21
index.php
21
index.php
@ -186,26 +186,7 @@ if(!$db->hasTable('myaac_account_actions')) {
|
|||||||
throw new RuntimeException('Seems that the table <strong>myaac_account_actions</strong> of MyAAC doesn\'t exist in the database. This is a fatal error. You can try to reinstall MyAAC by visiting <a href="' . BASE_URL . 'install">this</a> url.');
|
throw new RuntimeException('Seems that the table <strong>myaac_account_actions</strong> of MyAAC doesn\'t exist in the database. This is a fatal error. You can try to reinstall MyAAC by visiting <a href="' . BASE_URL . 'install">this</a> url.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// database migrations
|
require SYSTEM . 'migrate.php';
|
||||||
$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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$hooks->trigger(HOOK_STARTUP);
|
$hooks->trigger(HOOK_STARTUP);
|
||||||
|
|
||||||
|
22
system/migrate.php
Normal file
22
system/migrate.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user