mirror of
https://github.com/slawkens/myaac.git
synced 2025-11-03 17:26:23 +01:00
Refactor migrations with $up & $down
This commit is contained in:
@@ -1,17 +1,31 @@
|
||||
<?php
|
||||
if($db->hasTable(TABLE_PREFIX . 'forum_sections'))
|
||||
$db->query('RENAME TABLE `' . TABLE_PREFIX . 'forum_sections` TO `' . TABLE_PREFIX . 'forum_boards`;');
|
||||
|
||||
/**
|
||||
* @var OTS_DB_MySQL $db
|
||||
*/
|
||||
|
||||
$up = function ($db) {
|
||||
if ($db->hasTable(TABLE_PREFIX . 'forum_sections')) {
|
||||
$db->renameTable(TABLE_PREFIX . 'forum_sections', TABLE_PREFIX . 'forum_boards');
|
||||
}
|
||||
|
||||
$query = $db->query('SELECT `id` FROM `' . TABLE_PREFIX . 'forum_boards` WHERE `ordering` > 0;');
|
||||
if($query->rowCount() == 0) {
|
||||
$boards = array(
|
||||
if ($query->rowCount() == 0) {
|
||||
$boards = [
|
||||
'News',
|
||||
'Trade',
|
||||
'Quests',
|
||||
'Pictures',
|
||||
'Bug Report'
|
||||
);
|
||||
|
||||
foreach($boards as $id => $board)
|
||||
];
|
||||
|
||||
foreach ($boards as $id => $board) {
|
||||
$db->query('UPDATE `' . TABLE_PREFIX . 'forum_boards` SET `ordering` = ' . $id . ' WHERE `name` = ' . $db->quote($board));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$down = function () use ($db) {
|
||||
if ($db->hasTable(TABLE_PREFIX . 'forum_boards')) {
|
||||
$db->renameTable(TABLE_PREFIX . 'forum_boards', TABLE_PREFIX . 'forum_sections');
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user