diff --git a/aac b/aac index d87042f80..d4ce7b7dd 100644 --- a/aac +++ b/aac @@ -9,14 +9,13 @@ if(!IS_CLI) { } require_once SYSTEM . 'functions.php'; -require_once SYSTEM . 'init.php'; define('SELF_NAME', basename(__FILE__)); use MyAAC\Plugins; use Symfony\Component\Console\Application; -$application = new Application(); +$application = new Application('MyAAC', MYAAC_VERSION); $commandsGlob = glob(SYSTEM . 'src/Commands/*.php'); foreach ($commandsGlob as $item) { @@ -34,7 +33,4 @@ foreach ($pluginCommands as $item) { $application->add(require $item); } -$application->setName('MyAAC'); -$application->setVersion(MYAAC_VERSION); - $application->run(); diff --git a/install/steps/5-database.php b/install/steps/5-database.php index 4f87bc497..cb4f14a33 100644 --- a/install/steps/5-database.php +++ b/install/steps/5-database.php @@ -40,6 +40,7 @@ $configToSave['gzip_output'] = false; $configToSave['cache_engine'] = 'auto'; $configToSave['cache_prefix'] = 'myaac_' . generateRandomString(8, true, false, true); + $configToSave['database_auto_migrate'] = true; if(!$error) { $content = ''; diff --git a/system/init.php b/system/init.php index 1102fb564..68122dba8 100644 --- a/system/init.php +++ b/system/init.php @@ -17,6 +17,7 @@ defined('MYAAC') or die('Direct access not allowed!'); +global $config; if(!isset($config['installed']) || !$config['installed']) { throw new RuntimeException('MyAAC has not been installed yet or there was error during installation. Please install again.'); } @@ -142,7 +143,10 @@ } // execute migrations -require SYSTEM . 'migrate.php'; +$configDatabaseAutoMigrate = config('database_auto_migrate'); +if (!isset($configDatabaseAutoMigrate) || $configDatabaseAutoMigrate) { + require SYSTEM . 'migrate.php'; +} // settings $settings = Settings::getInstance(); diff --git a/system/libs/pot/OTS_Base_DB.php b/system/libs/pot/OTS_Base_DB.php index 6ef39bc5f..1d7ae287c 100644 --- a/system/libs/pot/OTS_Base_DB.php +++ b/system/libs/pot/OTS_Base_DB.php @@ -235,6 +235,30 @@ public function delete($table, $data, $limit = 1) $this->exec($query); return true; } + + public function addColumn($table, $column, $definition): void { + $this->exec('ALTER TABLE ' . $this->tableName($table) . ' ADD ' . $this->fieldName($column) . ' ' . $definition . ';'); + } + + public function modifyColumn($table, $column, $definition): void { + $this->exec('ALTER TABLE ' . $this->tableName($table) . ' MODIFY ' . $this->fieldName($column) . ' ' . $definition . ';'); + } + + public function changeColumn($table, $from, $to, $definition): void { + $this->exec('ALTER TABLE ' . $this->tableName($table) . ' CHANGE ' . $this->fieldName($from) . ' ' . $this->fieldName($to) . ' ' . $definition . ';'); + } + + public function dropColumn($table, $column): void { + $this->exec('ALTER TABLE ' . $this->tableName($table) . ' DROP COLUMN ' . $this->fieldName($column) . ';'); + } + + public function renameTable($from, $to): void { + $this->exec('RENAME TABLE ' . $this->tableName($from) . ' TO ' . $this->tableName($to) . ';'); + } + + public function dropTable($table, $ifExists = true): void { + $this->exec('DROP TABLE ' . ($ifExists ? 'IF EXISTS' : '') . ' ' . $this->tableName($table) . ';'); + } /** * LIMIT/OFFSET clause for queries. * diff --git a/system/migrate.php b/system/migrate.php index 4eb7bf7a2..2199fd730 100644 --- a/system/migrate.php +++ b/system/migrate.php @@ -17,6 +17,12 @@ $db->revalidateCache(); for($i = $tmp + 1; $i <= DATABASE_VERSION; $i++) { require SYSTEM . 'migrations/' . $i . '.php'; + + if (isset($up)) { + $up(); + unset($up); + } + updateDatabaseConfig('database_version', $i); } } @@ -26,6 +32,12 @@ $db->revalidateCache(); for($i = 1; $i <= DATABASE_VERSION; $i++) { require SYSTEM . 'migrations/' . $i . '.php'; + + if (isset($up)) { + $up(); + unset($up); + } + updateDatabaseConfig('database_version', $i); } } diff --git a/system/migrations/1-hooks.sql b/system/migrations/1-hooks.sql new file mode 100644 index 000000000..218988ce7 --- /dev/null +++ b/system/migrations/1-hooks.sql @@ -0,0 +1,8 @@ +CREATE TABLE `myaac_hooks` +( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(30) NOT NULL DEFAULT '', + `type` INT(2) NOT NULL DEFAULT 0, + `file` VARCHAR(100) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; diff --git a/system/migrations/1.php b/system/migrations/1.php index 6e4f3252a..a3c38f66b 100644 --- a/system/migrations/1.php +++ b/system/migrations/1.php @@ -1,16 +1,16 @@ query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` MODIFY `ip` INT(11) NOT NULL DEFAULT 0;"); - $db->query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` MODIFY `date` INT(11) NOT NULL DEFAULT 0;"); - $db->query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` MODIFY `action` VARCHAR(255) NOT NULL DEFAULT '';"); - $db->query(" - CREATE TABLE `myaac_hooks` -( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(30) NOT NULL DEFAULT '', - `type` INT(2) NOT NULL DEFAULT 0, - `file` VARCHAR(100) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; -"); +/** + * @var OTS_DB_MySQL $db + */ -?> +$up = function () use ($db) { + $db->modifyColumn(TABLE_PREFIX . 'account_actions', 'ip', "INT(11) NOT NULL DEFAULT 0"); + $db->modifyColumn(TABLE_PREFIX . 'account_actions', 'date', "INT(11) NOT NULL DEFAULT 0"); + $db->modifyColumn(TABLE_PREFIX . 'account_actions', 'action', "VARCHAR(255) NOT NULL DEFAULT ''"); + + $db->query(file_get_contents(__DIR__ . '/1-hooks.sql')); +}; + +$down = function () use ($db) { + $db->dropTable(TABLE_PREFIX . 'hooks'); +}; diff --git a/system/migrations/10-admin_menu.sql b/system/migrations/10-admin_menu.sql new file mode 100644 index 000000000..72083c35a --- /dev/null +++ b/system/migrations/10-admin_menu.sql @@ -0,0 +1,10 @@ +CREATE TABLE `myaac_admin_menu` +( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NOT NULL DEFAULT '', + `page` VARCHAR(255) NOT NULL DEFAULT '', + `ordering` INT(11) NOT NULL DEFAULT 0, + `flags` INT(11) NOT NULL DEFAULT 0, + `enabled` INT(1) NOT NULL DEFAULT 1, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; diff --git a/system/migrations/10.php b/system/migrations/10.php index da660ab9e..8783dbf0f 100644 --- a/system/migrations/10.php +++ b/system/migrations/10.php @@ -1,17 +1,24 @@ hasColumn(TABLE_PREFIX . 'hooks', 'ordering')) - $db->query("ALTER TABLE `" . TABLE_PREFIX . "hooks` ADD `ordering` INT(11) NOT NULL DEFAULT 0 AFTER `file`;"); +/** + * @var OTS_DB_MySQL $db + */ - if(!$db->hasTable(TABLE_PREFIX . 'admin_menu')) - $db->query(" -CREATE TABLE `myaac_admin_menu` -( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(255) NOT NULL DEFAULT '', - `page` VARCHAR(255) NOT NULL DEFAULT '', - `ordering` INT(11) NOT NULL DEFAULT 0, - `flags` INT(11) NOT NULL DEFAULT 0, - `enabled` INT(1) NOT NULL DEFAULT 1, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; -"); \ No newline at end of file +$up = function () use ($db) { + if (!$db->hasColumn(TABLE_PREFIX . 'hooks', 'ordering')) { + $db->addColumn(TABLE_PREFIX . 'hooks', 'ordering', "INT(11) NOT NULL DEFAULT 0 AFTER `file`"); + } + + if (!$db->hasTable(TABLE_PREFIX . 'admin_menu')) { + $db->query(file_get_contents(__DIR__ . '/10-admin_menu.sql')); + } +}; + +$down = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'hooks', 'ordering')) { + $db->dropColumn(TABLE_PREFIX . 'hooks', 'ordering'); + } + + if ($db->hasTable(TABLE_PREFIX . 'admin_menu')) { + $db->dropTable(TABLE_PREFIX . 'admin_menu'); + } +}; diff --git a/system/migrations/11.php b/system/migrations/11.php index 845f9e67f..bc26da0e3 100644 --- a/system/migrations/11.php +++ b/system/migrations/11.php @@ -1,19 +1,44 @@ query("RENAME TABLE - " . TABLE_PREFIX . "screenshots TO " . TABLE_PREFIX . "gallery, - " . TABLE_PREFIX . "movies TO " . TABLE_PREFIX . "videos;"); + $db->renameTable(TABLE_PREFIX . 'screenshots', TABLE_PREFIX . 'gallery'); + $db->renameTable(TABLE_PREFIX . 'movies', TABLE_PREFIX . 'videos'); // rename images dir - if(file_exists(BASE . 'images/screenshots') && !file_exists(BASE . GALLERY_DIR)) { + if (file_exists(BASE . 'images/screenshots') && !file_exists(BASE . GALLERY_DIR)) { rename(BASE . 'images/screenshots', BASE . GALLERY_DIR); } // convert old database screenshots images to gallery $query = $db->query('SELECT `id`, `image`, `thumb` FROM `' . TABLE_PREFIX . 'gallery`;'); - foreach($query->fetchAll() as $item) { + foreach ($query->fetchAll() as $item) { $db->update(TABLE_PREFIX . 'gallery', array( 'image' => str_replace('/screenshots/', '/gallery/', $item['image']), 'thumb' => str_replace('/screenshots/', '/gallery/', $item['thumb']), ), array('id' => $item['id'])); } +}; + +$down = function () use ($db) { + // rename database tables + $db->renameTable(TABLE_PREFIX . 'gallery', TABLE_PREFIX . 'screenshots'); + $db->renameTable(TABLE_PREFIX . 'videos', TABLE_PREFIX . 'movies'); + + // rename images dir + if (file_exists(BASE . GALLERY_DIR) && !file_exists(BASE . 'images/screenshots')) { + rename(BASE . GALLERY_DIR, BASE . 'images/screenshots'); + } + + // convert new database gallery images to screenshots + $query = $db->query('SELECT `id`, `image`, `thumb` FROM `' . TABLE_PREFIX . 'screenshots`;'); + foreach ($query->fetchAll() as $item) { + $db->update(TABLE_PREFIX . 'screenshots', [ + 'image' => str_replace('/gallery/', '/screenshots/', $item['image']), + 'thumb' => str_replace('/gallery/', '/screenshots/', $item['thumb']), + ], ['id' => $item['id']]); + } +}; diff --git a/system/migrations/12-items.sql b/system/migrations/12-items.sql new file mode 100644 index 000000000..458333e0c --- /dev/null +++ b/system/migrations/12-items.sql @@ -0,0 +1,9 @@ +CREATE TABLE `myaac_items` +( + `id` INT(11) NOT NULL, + `article` VARCHAR(5) NOT NULL DEFAULT '', + `name` VARCHAR(50) NOT NULL DEFAULT '', + `plural` VARCHAR(50) NOT NULL DEFAULT '', + `attributes` VARCHAR(500) NOT NULL DEFAULT '', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; diff --git a/system/migrations/12-weapons.sql b/system/migrations/12-weapons.sql new file mode 100644 index 000000000..9085732e3 --- /dev/null +++ b/system/migrations/12-weapons.sql @@ -0,0 +1,8 @@ +CREATE TABLE `myaac_weapons` +( + `id` INT(11) NOT NULL, + `level` INT(11) NOT NULL DEFAULT 0, + `maglevel` INT(11) NOT NULL DEFAULT 0, + `vocations` VARCHAR(100) NOT NULL DEFAULT '', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; diff --git a/system/migrations/12.php b/system/migrations/12.php index 9730ed8b2..00d6d6f02 100644 --- a/system/migrations/12.php +++ b/system/migrations/12.php @@ -1,51 +1,65 @@ hasColumn(TABLE_PREFIX . 'spells', 'item_id')) - $db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` ADD `item_id` INT(11) NOT NULL DEFAULT 0 AFTER `conjure_count`;"); - -// change unique index from spell to name -$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` DROP INDEX `spell`;"); -$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` ADD UNIQUE INDEX (`name`);"); - -// change comment of spells.type -$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` MODIFY `type` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '1 - instant, 2 - conjure, 3 - rune';"); - -// new items table -if(!$db->hasTable(TABLE_PREFIX . 'items')) -$db->query(" -CREATE TABLE `" . TABLE_PREFIX . "items` -( - `id` INT(11) NOT NULL, - `article` VARCHAR(5) NOT NULL DEFAULT '', - `name` VARCHAR(50) NOT NULL DEFAULT '', - `plural` VARCHAR(50) NOT NULL DEFAULT '', - `attributes` VARCHAR(500) NOT NULL DEFAULT '', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; -"); - -// new weapons table -if(!$db->hasTable(TABLE_PREFIX . 'weapons')) -$db->query(" -CREATE TABLE `" . TABLE_PREFIX . "weapons` -( - `id` INT(11) NOT NULL, - `level` INT(11) NOT NULL DEFAULT 0, - `maglevel` INT(11) NOT NULL DEFAULT 0, - `vocations` VARCHAR(100) NOT NULL DEFAULT '', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; -"); - -// modify vocations to support json data -$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` MODIFY `vocations` VARCHAR(100) NOT NULL DEFAULT '';"); -$query = $db->query('SELECT `id`, `vocations` FROM `' . TABLE_PREFIX . 'spells`'); -foreach($query->fetchAll() as $spell) { - $tmp = explode(',', $spell['vocations']); - foreach($tmp as &$v) { - $v = (int)$v; +use MyAAC\Models\Spell; + +$up = function () use ($db) { + // add new item_id field for runes + if (!$db->hasColumn(TABLE_PREFIX . 'spells', 'item_id')) { + $db->addColumn(TABLE_PREFIX . 'spells', 'item_id', 'INT(11) NOT NULL DEFAULT 0 AFTER `conjure_count`'); + } + + // change unique index from spell to name + $db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` DROP INDEX `spell`;"); + $db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` ADD UNIQUE INDEX (`name`);"); + + // change comment of spells.type + $db->modifyColumn(TABLE_PREFIX . 'spells', 'type', "TINYINT(1) NOT NULL DEFAULT 0 COMMENT '1 - instant, 2 - conjure, 3 - rune'"); + + // new items table + if (!$db->hasTable(TABLE_PREFIX . 'items')) { + $db->query(file_get_contents(__DIR__ . '/12-items.sql')); + } + + // new weapons table + if (!$db->hasTable(TABLE_PREFIX . 'weapons')) { + $db->query(file_get_contents(__DIR__ . '/12-weapons.sql')); + } + + // modify vocations to support json data + $db->modifyColumn(TABLE_PREFIX . 'spells', 'vocations', "VARCHAR(100) NOT NULL DEFAULT ''"); + + $spells = Spell::select('id', 'vocations')->get(); + foreach ($spells as $spell) { + $tmp = explode(',', $spell->vocations); + foreach ($tmp as &$v) { + $v = (int)$v; + } + + Spell::where('id', $spell->id)->update(['vocations' => json_encode($tmp)]); + } +}; + +$down = function () use ($db) { + // remove item_id field for runes + if ($db->hasColumn(TABLE_PREFIX . 'spells', 'item_id')) { + $db->dropColumn(TABLE_PREFIX . 'spells', 'item_id'); + } + + // change unique index from spell to name + $db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` DROP INDEX `name`;"); + $db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` ADD INDEX (`spell`);"); + + $db->dropTable(TABLE_PREFIX . 'items'); + $db->dropTable(TABLE_PREFIX . 'weapons'); + + $spells = Spell::select('id', 'vocations')->get(); + // modify vocations to use vocation separated by comma + foreach ($spells as $spell) { + $vocations = empty($spell->vocations) ? [] : json_decode($spell->vocations); + + Spell::where('id', $spell->id)->update(['vocations' => implode(',', $vocations)]); } - $db->update(TABLE_PREFIX . 'spells', array('vocations' => json_encode($tmp)), array('id' => $spell['id'])); -} -?> \ No newline at end of file +}; diff --git a/system/migrations/13.php b/system/migrations/13.php index 4eee77f3c..86da43adc 100644 --- a/system/migrations/13.php +++ b/system/migrations/13.php @@ -1,3 +1,16 @@ hasColumn(TABLE_PREFIX . 'spells', 'spell')) - $db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` DROP COLUMN `spell`;"); \ No newline at end of file +/** + * @var OTS_DB_MySQL $db + */ + +$up = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'spells', 'spell')) { + $db->dropColumn(TABLE_PREFIX . 'spells', 'spell'); + } +}; + +$down = function () use ($db) { + if (!$db->hasColumn(TABLE_PREFIX . 'spells', 'spell')) { + $db->addColumn(TABLE_PREFIX . 'spells', 'spell', "VARCHAR(255) NOT NULL DEFAULT ''"); + } +}; diff --git a/system/migrations/14.php b/system/migrations/14.php index acd13afb7..4c295c676 100644 --- a/system/migrations/14.php +++ b/system/migrations/14.php @@ -1,18 +1,39 @@ hasColumn(TABLE_PREFIX . 'monsters', 'file_path')) { - $db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` CHANGE `file_path` `loot` VARCHAR(5000);"); -} +$up = function () use ($db) { + // change monsters.file_path field to loot + if ($db->hasColumn(TABLE_PREFIX . 'monsters', 'file_path')) { + $db->changeColumn(TABLE_PREFIX . 'monsters', 'file_path', 'loot', 'VARCHAR(5000)'); + } -// update loot to empty string -$db->query("UPDATE `" . TABLE_PREFIX . "monsters` SET `loot` = '';"); + // update loot to empty string + $db->query("UPDATE `" . TABLE_PREFIX . "monsters` SET `loot` = '';"); -// drop monsters.gfx_name field -$db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `gfx_name`;"); + // drop monsters.gfx_name field + $db->dropColumn(TABLE_PREFIX . 'monsters', 'gfx_name'); -// rename hide_creature to hidden -if($db->hasColumn(TABLE_PREFIX . 'monsters', 'hide_creature')) { - $db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` CHANGE `hide_creature` `hidden` TINYINT(1) NOT NULL DEFAULT 0;"); -} -?> \ No newline at end of file + // rename hide_creature to hidden + if ($db->hasColumn(TABLE_PREFIX . 'monsters', 'hide_creature')) { + $db->changeColumn(TABLE_PREFIX . 'monsters', 'hide_creature', 'hidden', "TINYINT(1) NOT NULL DEFAULT 0"); + } +}; + +$down = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'monsters', 'loot')) { + $db->changeColumn(TABLE_PREFIX . 'monsters', 'loot', 'file_path', 'VARCHAR(5000)'); + } + + // update file_path to empty string + $db->query("UPDATE `" . TABLE_PREFIX . "monsters` SET `file_path` = '';"); + + // add monsters.gfx_name field + $db->addColumn(TABLE_PREFIX . 'monsters', 'gfx_name', 'varchar(255) NOT NULL AFTER `race`'); + + // rename hidden to hide_creature + if ($db->hasColumn(TABLE_PREFIX . 'monsters', 'hidden')) { + $db->changeColumn(TABLE_PREFIX . 'monsters', 'hidden', 'hide_creature', 'TINYINT(1) NOT NULL DEFAULT 0'); + } +}; diff --git a/system/migrations/15.php b/system/migrations/15.php index 971587ec1..eff04c421 100644 --- a/system/migrations/15.php +++ b/system/migrations/15.php @@ -1,10 +1,26 @@ hasColumn(TABLE_PREFIX . 'forum_boards', 'guild')) { - $db->query("ALTER TABLE `" . TABLE_PREFIX . "forum_boards` ADD `guild` TINYINT(1) NOT NULL DEFAULT 0 AFTER `closed`;"); -} -if(!$db->hasColumn(TABLE_PREFIX . 'forum_boards', 'access')) { - $db->query("ALTER TABLE `" . TABLE_PREFIX . "forum_boards` ADD `access` TINYINT(1) NOT NULL DEFAULT 0 AFTER `guild`;"); -} +$up = function () use ($db) { + if (!$db->hasColumn(TABLE_PREFIX . 'forum_boards', 'guild')) { + $db->addColumn(TABLE_PREFIX . 'forum_boards', 'guild', 'TINYINT(1) NOT NULL DEFAULT 0 AFTER `closed`'); + } + + if (!$db->hasColumn(TABLE_PREFIX . 'forum_boards', 'access')) { + $db->addColumn(TABLE_PREFIX . 'forum_boards', 'access', 'TINYINT(1) NOT NULL DEFAULT 0 AFTER `guild`'); + } +}; + +$down = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'forum_boards', 'guild')) { + $db->dropColumn(TABLE_PREFIX . 'forum_boards', 'guild'); + } + + if ($db->hasColumn(TABLE_PREFIX . 'forum_boards', 'access')) { + $db->dropColumn(TABLE_PREFIX . 'forum_boards', 'access'); + } +}; diff --git a/system/migrations/16.php b/system/migrations/16.php index ad0112a21..0be467d4c 100644 --- a/system/migrations/16.php +++ b/system/migrations/16.php @@ -1,5 +1,14 @@ query("ALTER TABLE `" . TABLE_PREFIX . "spells` MODIFY `vocations` VARCHAR(300) NOT NULL DEFAULT '';"); -?> \ No newline at end of file + +$up = function () use ($db) { + $db->modifyColumn(TABLE_PREFIX . 'spells', 'vocations', "VARCHAR(300) NOT NULL DEFAULT ''"); +}; + +$down = function () { + // nothing to do here +}; diff --git a/system/migrations/17-menu.sql b/system/migrations/17-menu.sql new file mode 100644 index 000000000..738e722b3 --- /dev/null +++ b/system/migrations/17-menu.sql @@ -0,0 +1,11 @@ +CREATE TABLE `myaac_menu` +( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `template` VARCHAR(255) NOT NULL, + `name` VARCHAR(255) NOT NULL, + `link` VARCHAR(255) NOT NULL, + `category` INT(11) NOT NULL DEFAULT 1, + `ordering` INT(11) NOT NULL DEFAULT 0, + `enabled` INT(1) NOT NULL DEFAULT 1, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; diff --git a/system/migrations/17.php b/system/migrations/17.php index 73e3828c6..497e3e3c8 100644 --- a/system/migrations/17.php +++ b/system/migrations/17.php @@ -1,23 +1,20 @@ hasTable('myaac_menu')) { - $db->query(" -CREATE TABLE `myaac_menu` -( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `template` VARCHAR(255) NOT NULL, - `name` VARCHAR(255) NOT NULL, - `link` VARCHAR(255) NOT NULL, - `category` INT(11) NOT NULL DEFAULT 1, - `ordering` INT(11) NOT NULL DEFAULT 0, - `enabled` INT(1) NOT NULL DEFAULT 1, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; -"); -} +$up = function () use ($db) { + if (!$db->hasTable(TABLE_PREFIX . 'menu')) { + $db->exec(file_get_contents(__DIR__ . '/17-menu.sql')); + } -Plugins::installMenus('kathrine', require TEMPLATES . 'kathrine/menus.php'); -Plugins::installMenus('tibiacom', require TEMPLATES . 'tibiacom/menus.php'); + Plugins::installMenus('kathrine', require TEMPLATES . 'kathrine/menus.php'); + Plugins::installMenus('tibiacom', require TEMPLATES . 'tibiacom/menus.php'); +}; + +$down = function () use ($db) { + $db->dropTable(TABLE_PREFIX . 'menu'); +}; diff --git a/system/migrations/18.php b/system/migrations/18.php index 7ec9675ab..7c251e7cf 100644 --- a/system/migrations/18.php +++ b/system/migrations/18.php @@ -1,6 +1,24 @@ query("ALTER TABLE `" . TABLE_PREFIX . "news` ADD `article_text` VARCHAR(300) NOT NULL DEFAULT '' AFTER `comments`;"); -$db->query("ALTER TABLE `" . TABLE_PREFIX . "news` ADD `article_image` VARCHAR(100) NOT NULL DEFAULT '' AFTER `article_text`;"); +$up = function () use ($db) { + if (!$db->hasColumn(TABLE_PREFIX . 'news', 'article_text')) { + $db->addColumn(TABLE_PREFIX . 'news', 'article_text', "VARCHAR(300) NOT NULL DEFAULT '' AFTER `comments`"); + } -?> \ No newline at end of file + if (!$db->hasColumn(TABLE_PREFIX . 'news', 'article_image')) { + $db->addColumn(TABLE_PREFIX . 'news', 'article_image', "VARCHAR(100) NOT NULL DEFAULT '' AFTER `article_text`"); + } +}; + +$down = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'news', 'article_text')) { + $db->dropColumn(TABLE_PREFIX . 'news', 'article_text'); + } + + if ($db->hasColumn(TABLE_PREFIX . 'news', 'article_image')) { + $db->dropColumn(TABLE_PREFIX . 'news', 'article_image'); + } +}; diff --git a/system/migrations/2.php b/system/migrations/2.php index 90d9a6105..d65c05862 100644 --- a/system/migrations/2.php +++ b/system/migrations/2.php @@ -1,5 +1,11 @@ query("ALTER TABLE `" . TABLE_PREFIX . "faq` MODIFY `answer` VARCHAR(1020) NOT NULL DEFAULT '';"); - $db->query("ALTER TABLE `" . TABLE_PREFIX . "movies` MODIFY `title` VARCHAR(100) NOT NULL DEFAULT '';"); - $db->query("ALTER TABLE `" . TABLE_PREFIX . "news` MODIFY `title` VARCHAR(100) NOT NULL DEFAULT '';"); - $db->query("ALTER TABLE `" . TABLE_PREFIX . "news` MODIFY `body` TEXT NOT NULL DEFAULT '';"); +/** + * @var OTS_DB_MySQL $db + */ + +$up = function () use ($db) { + $db->modifyColumn(TABLE_PREFIX . 'faq', 'answer', "VARCHAR(1020) NOT NULL DEFAULT ''"); + $db->modifyColumn(TABLE_PREFIX . 'movies', 'title', "VARCHAR(100) NOT NULL DEFAULT ''"); + $db->modifyColumn(TABLE_PREFIX . 'news', 'title', "VARCHAR(100) NOT NULL DEFAULT ''"); + $db->modifyColumn(TABLE_PREFIX . 'news', 'body', "TEXT NOT NULL"); +}; diff --git a/system/migrations/20.php b/system/migrations/20.php index 1255fa14a..ccc20a516 100644 --- a/system/migrations/20.php +++ b/system/migrations/20.php @@ -2,20 +2,33 @@ use MyAAC\Settings; -if (!$db->hasTable('players')) { - return; -} +function updateHighscoresIdsHidden(): void +{ + global $db; -$query = $db->query("SELECT `id` FROM `players` WHERE (`name` = " . $db->quote("Rook Sample") . " OR `name` = " . $db->quote("Sorcerer Sample") . " OR `name` = " . $db->quote("Druid Sample") . " OR `name` = " . $db->quote("Paladin Sample") . " OR `name` = " . $db->quote("Knight Sample") . " OR `name` = " . $db->quote("Account Manager") . ") ORDER BY `id`;"); + if (!$db->hasTable('players')) { + return; + } -$highscores_ignored_ids = array(); -if($query->rowCount() > 0) { - foreach($query->fetchAll() as $result) - $highscores_ignored_ids[] = $result['id']; -} -else { - $highscores_ignored_ids[] = 0; + $query = $db->query("SELECT `id` FROM `players` WHERE (`name` = " . $db->quote("Rook Sample") . " OR `name` = " . $db->quote("Sorcerer Sample") . " OR `name` = " . $db->quote("Druid Sample") . " OR `name` = " . $db->quote("Paladin Sample") . " OR `name` = " . $db->quote("Knight Sample") . " OR `name` = " . $db->quote("Account Manager") . ") ORDER BY `id`;"); + + $highscores_ignored_ids = array(); + if ($query->rowCount() > 0) { + foreach ($query->fetchAll() as $result) + $highscores_ignored_ids[] = $result['id']; + } else { + $highscores_ignored_ids[] = 0; + } + + $settings = Settings::getInstance(); + $settings->updateInDatabase('core', 'highscores_ids_hidden', implode(', ', $highscores_ignored_ids)); } -$settings = Settings::getInstance(); -$settings->updateInDatabase('core', 'highscores_ids_hidden', implode(', ', $highscores_ignored_ids)); +$up = function () { + updateHighscoresIdsHidden(); +}; + +$down = function () { + $settings = Settings::getInstance(); + $settings->updateInDatabase('core', 'highscores_ids_hidden', '0'); +}; diff --git a/system/migrations/21.php b/system/migrations/21.php index 51bb518a5..6282407c8 100644 --- a/system/migrations/21.php +++ b/system/migrations/21.php @@ -1,14 +1,23 @@ exec("ALTER TABLE `" . TABLE_PREFIX . "forum` ADD `post_html` TINYINT(1) NOT NULL DEFAULT 0 AFTER `post_smile`;"); +$up = function () use ($db) { + $db->addColumn(TABLE_PREFIX . 'forum', 'post_html', 'TINYINT(1) NOT NULL DEFAULT 0 AFTER `post_smile`'); -$query = $db->query("SELECT `id` FROM `" . TABLE_PREFIX . "forum_boards` WHERE `name` LIKE " . $db->quote('News') . " LIMIT 1;"); -if($query->rowCount() == 0) { - return; // don't make anything -} + $query = $db->query("SELECT `id` FROM `" . TABLE_PREFIX . "forum_boards` WHERE `name` LIKE " . $db->quote('News') . " LIMIT 1;"); + if ($query->rowCount() == 0) { + return; // don't make anything + } -$query = $query->fetch(); -$id = $query['id']; + $query = $query->fetch(); + $id = $query['id']; -// update all forum threads with is_html = 1 -$db->exec("UPDATE `" . TABLE_PREFIX . "forum` SET `post_html` = 1 WHERE `section` = " . $id . " AND `id` = `first_post`;"); \ No newline at end of file + // update all forum threads with is_html = 1 + $db->exec("UPDATE `" . TABLE_PREFIX . "forum` SET `post_html` = 1 WHERE `section` = " . $id . " AND `id` = `first_post`;"); +}; + +$down = function () use ($db) { + $db->dropColumn(TABLE_PREFIX . 'forum', 'post_html'); +}; diff --git a/system/migrations/22-z_polls.sql b/system/migrations/22-z_polls.sql new file mode 100644 index 000000000..7d5d39dff --- /dev/null +++ b/system/migrations/22-z_polls.sql @@ -0,0 +1,10 @@ +CREATE TABLE `z_polls` ( + `id` int(11) NOT NULL auto_increment, + `question` varchar(255) NOT NULL, + `description` varchar(255) NOT NULL, + `end` int(11) NOT NULL DEFAULT 0, + `start` int(11) NOT NULL DEFAULT 0, + `answers` int(11) NOT NULL DEFAULT 0, + `votes_all` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; diff --git a/system/migrations/22-z_polls_answers.sql b/system/migrations/22-z_polls_answers.sql new file mode 100644 index 000000000..f28940cf2 --- /dev/null +++ b/system/migrations/22-z_polls_answers.sql @@ -0,0 +1,6 @@ +CREATE TABLE `z_polls_answers` ( + `poll_id` int(11) NOT NULL, + `answer_id` int(11) NOT NULL, + `answer` varchar(255) NOT NULL, + `votes` int(11) NOT NULL DEFAULT 0 +) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; diff --git a/system/migrations/22.php b/system/migrations/22.php index eca1ddac3..c96210322 100644 --- a/system/migrations/22.php +++ b/system/migrations/22.php @@ -1,31 +1,35 @@ hasTable('z_polls')) - $db->query(' -CREATE TABLE `z_polls` ( - `id` int(11) NOT NULL auto_increment, - `question` varchar(255) NOT NULL, - `description` varchar(255) NOT NULL, - `end` int(11) NOT NULL DEFAULT 0, - `start` int(11) NOT NULL DEFAULT 0, - `answers` int(11) NOT NULL DEFAULT 0, - `votes_all` int(11) NOT NULL DEFAULT 0, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; -'); +$up = function () use ($db) { + if (!$db->hasTable('z_polls')) { + $db->exec(file_get_contents(__DIR__ . '/22-z_polls.sql')); + } -if(!$db->hasTable('z_polls_answers')) -$db->query(' - CREATE TABLE `z_polls_answers` ( - `poll_id` int(11) NOT NULL, - `answer_id` int(11) NOT NULL, - `answer` varchar(255) NOT NULL, - `votes` int(11) NOT NULL DEFAULT 0 -) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; -'); + if (!$db->hasTable('z_polls_answers')) { + $db->exec(file_get_contents(__DIR__ . '/22-z_polls_answers.sql')); + } -if(!$db->hasColumn('accounts', 'vote')) - $db->query('ALTER TABLE `accounts` ADD `vote` INT( 11 ) DEFAULT 0 NOT NULL ;'); -else { - $db->query('ALTER TABLE `accounts` MODIFY `vote` INT( 11 ) DEFAULT 0 NOT NULL ;'); -} \ No newline at end of file + if (!$db->hasColumn('accounts', 'vote')) { + $db->addColumn('accounts', 'vote', 'int(11) NOT NULL DEFAULT 0'); + } + else { + $db->modifyColumn('accounts', 'vote', 'int(11) NOT NULL DEFAULT 0'); + } +}; + +$down = function () use ($db) { + if ($db->hasTable('z_polls')) { + $db->dropTable('z_polls;'); + } + + if ($db->hasTable('z_polls_answers')) { + $db->dropTable('z_polls_answers'); + } + + if ($db->hasColumn('accounts', 'vote')) { + $db->dropColumn('accounts', 'vote'); + } +}; diff --git a/system/migrations/23.php b/system/migrations/23.php index ba4bbe0c6..6174a0867 100644 --- a/system/migrations/23.php +++ b/system/migrations/23.php @@ -1,7 +1,24 @@ hasColumn(TABLE_PREFIX . 'menu', 'blank')) - $db->query("ALTER TABLE `" . TABLE_PREFIX . "menu` ADD `blank` TINYINT(1) NOT NULL DEFAULT 0 AFTER `link`;"); +$up = function () use ($db) { + if (!$db->hasColumn(TABLE_PREFIX . 'menu', 'blank')) { + $db->addColumn(TABLE_PREFIX . 'menu', 'blank', 'TINYINT(1) NOT NULL DEFAULT 0 AFTER `link`'); + } -if(!$db->hasColumn(TABLE_PREFIX . 'menu', 'color')) - $db->query("ALTER TABLE `" . TABLE_PREFIX . "menu` ADD `color` CHAR(6) NOT NULL DEFAULT '' AFTER `blank`;"); \ No newline at end of file + if (!$db->hasColumn(TABLE_PREFIX . 'menu', 'color')) { + $db->addColumn(TABLE_PREFIX . 'menu', 'color', "CHAR(6) NOT NULL DEFAULT '' AFTER `blank`"); + } +}; + +$down = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'menu', 'blank')) { + $db->dropColumn(TABLE_PREFIX . 'menu', 'blank'); + } + + if ($db->hasColumn(TABLE_PREFIX . 'menu', 'color')) { + $db->dropColumn(TABLE_PREFIX . 'menu', 'color'); + } +}; diff --git a/system/migrations/24-items.sql b/system/migrations/24-items.sql new file mode 100644 index 000000000..458333e0c --- /dev/null +++ b/system/migrations/24-items.sql @@ -0,0 +1,9 @@ +CREATE TABLE `myaac_items` +( + `id` INT(11) NOT NULL, + `article` VARCHAR(5) NOT NULL DEFAULT '', + `name` VARCHAR(50) NOT NULL DEFAULT '', + `plural` VARCHAR(50) NOT NULL DEFAULT '', + `attributes` VARCHAR(500) NOT NULL DEFAULT '', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; diff --git a/system/migrations/24.php b/system/migrations/24.php index b7e93819e..3fa44ae19 100644 --- a/system/migrations/24.php +++ b/system/migrations/24.php @@ -1,3 +1,12 @@ exec('DROP TABLE IF EXISTS `' . TABLE_PREFIX . 'items`;'); \ No newline at end of file +$up = function () use ($db) { + $db->dropTable(TABLE_PREFIX . 'items'); +}; + +$down = function () use ($db) { + $db->exec(file_get_contents(__DIR__ . '/24-items.sql')); +}; diff --git a/system/migrations/25.php b/system/migrations/25.php index 9e87c504e..6a4b3ad20 100644 --- a/system/migrations/25.php +++ b/system/migrations/25.php @@ -1,3 +1,12 @@ exec('ALTER TABLE `' . TABLE_PREFIX . 'monsters` MODIFY `loot` text NOT NULL;'); \ No newline at end of file +$up = function () use ($db) { + $db->modifyColumn(TABLE_PREFIX . 'monsters', 'loot', 'text NOT NULL'); +}; + +$down = function () { + // nothing to do +}; diff --git a/system/migrations/26.php b/system/migrations/26.php index 9804b7748..ad5657546 100644 --- a/system/migrations/26.php +++ b/system/migrations/26.php @@ -1,17 +1,32 @@ hasColumn(TABLE_PREFIX . 'spells', 'spell')) { - $db->exec('ALTER TABLE `' . TABLE_PREFIX . "spells` MODIFY `spell` VARCHAR(255) NOT NULL DEFAULT '';"); -} +$up = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'spells', 'spell')) { + $db->modifyColumn(TABLE_PREFIX . 'spells', 'spell', "VARCHAR(255) NOT NULL DEFAULT ''"); + } -if($db->hasColumn(TABLE_PREFIX . 'spells', 'words')) { - $db->exec('ALTER TABLE `' . TABLE_PREFIX . "spells` MODIFY `words` VARCHAR(255) NOT NULL DEFAULT '';"); -} + if ($db->hasColumn(TABLE_PREFIX . 'spells', 'words')) { + $db->modifyColumn(TABLE_PREFIX . 'spells', 'words', "VARCHAR(255) NOT NULL DEFAULT ''"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'spells', 'conjure_id')) { - $db->exec('ALTER TABLE `' . TABLE_PREFIX . 'spells` ADD `conjure_id` INT(11) NOT NULL DEFAULT 0 AFTER `soul`;'); -} + if (!$db->hasColumn(TABLE_PREFIX . 'spells', 'conjure_id')) { + $db->addColumn(TABLE_PREFIX . 'spells', 'conjure_id', 'INT(11) NOT NULL DEFAULT 0 AFTER `soul`'); + } -if(!$db->hasColumn(TABLE_PREFIX . 'spells', 'reagent')) { - $db->exec('ALTER TABLE `' . TABLE_PREFIX . 'spells` ADD `reagent` INT(11) NOT NULL DEFAULT 0 AFTER `conjure_count`;'); -} + if (!$db->hasColumn(TABLE_PREFIX . 'spells', 'reagent')) { + $db->addColumn(TABLE_PREFIX . 'spells', 'reagent', 'INT(11) NOT NULL DEFAULT 0 AFTER `conjure_count`'); + } +}; + +$down = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'spells', 'conjure_id')) { + $db->dropColumn(TABLE_PREFIX . 'spells', 'conjure_id'); + } + + if ($db->hasColumn(TABLE_PREFIX . 'spells', 'reagent')) { + $db->dropColumn(TABLE_PREFIX . 'spells', 'reagent'); + } +}; diff --git a/system/migrations/27-commands.html b/system/migrations/27-commands.html new file mode 100644 index 000000000..accb1c625 --- /dev/null +++ b/system/migrations/27-commands.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + +
WordsDescription
!exampleThis is just an example
!buyhouseBuy house you are looking at
!aolBuy AoL
diff --git a/system/migrations/27-downloads.html b/system/migrations/27-downloads.html new file mode 100644 index 000000000..ebf401fcc --- /dev/null +++ b/system/migrations/27-downloads.html @@ -0,0 +1,6 @@ +

 

+

 

+
We're using official Tibia Client {{ config.client / 100 }}
+

Download Tibia Client {{ config.client / 100 }} for Windows HERE.

+

IP Changer:

+ HERE
diff --git a/system/migrations/27.php b/system/migrations/27.php index 42040092d..81d4fb815 100644 --- a/system/migrations/27.php +++ b/system/migrations/27.php @@ -1,47 +1,48 @@  

-

 

-
We're using official Tibia Client {{ config.client / 100 }}
-

Download Tibia Client {{ config.client / 100 }} for Windows HERE.

-

IP Changer:

-HERE
-HTML; +use MyAAC\Models\Pages; -$query = $db->query("SELECT `id` FROM `" . TABLE_PREFIX . "pages` WHERE `name` LIKE " . $db->quote('downloads') . " LIMIT 1;"); -if($query->rowCount() === 0) { - $db->exec("INSERT INTO `myaac_pages` (`id`, `name`, `title`, `body`, `date`, `player_id`, `php`, `access`, `hide`) VALUES - (null, 'downloads', 'Downloads', {$db->quote($downloadsPage)}, 0, 1, 0, 0, 0);"); -} +$up = function () use ($db) { + $downloadsModel = Pages::where('name', 'downloads')->first(); + if (!$downloadsModel) { + $db->insert(TABLE_PREFIX . 'pages', [ + 'name' => 'downloads', + 'title' => 'Downloads', + 'body' => file_get_contents(__DIR__ . '/27-downloads.html'), + 'date' => time(), + 'player_id' => 1, + 'php' => 0, + 'access' => 0, + 'hidden' => 0, + ]); + } -$commandsPage = << - - -Words -Description - - - - -!example -This is just an example - - -!buyhouse -Buy house you are looking at - - -!aol -Buy AoL - - - -HTML; + $commandsModel = Pages::where('name', 'commands')->first(); + if (!$commandsModel) { + $db->insert(TABLE_PREFIX . 'pages', [ + 'name' => 'commands', + 'title' => 'Commands', + 'body' => file_get_contents(__DIR__ . '/27-commands.html'), + 'date' => time(), + 'player_id' => 1, + 'php' => 0, + 'access' => 0, + 'hidden' => 0, + ]); + } +}; -$query = $db->query("SELECT `id` FROM `" . TABLE_PREFIX . "pages` WHERE `name` LIKE " . $db->quote('commands') . " LIMIT 1;"); -if($query->rowCount() === 0) { - $db->exec("INSERT INTO `myaac_pages` (`id`, `name`, `title`, `body`, `date`, `player_id`, `php`, `access`, `hide`) VALUES -(null, 'commands', 'Commands', {$db->quote($commandsPage)}, 0, 1, 0, 0, 0);"); -} +$down = function () { + $downloadsModel = Pages::where('name', 'downloads')->first(); + if ($downloadsModel) { + $downloadsModel->delete(); + } + + $commandsModel = Pages::where('name', 'commands')->first(); + if ($commandsModel) { + $commandsModel->delete(); + } +}; diff --git a/system/migrations/28-hooks.sql b/system/migrations/28-hooks.sql new file mode 100644 index 000000000..ff1a228d0 --- /dev/null +++ b/system/migrations/28-hooks.sql @@ -0,0 +1,10 @@ +CREATE TABLE `myaac_hooks` +( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(30) NOT NULL DEFAULT '', + `type` INT(2) NOT NULL DEFAULT 0, + `file` VARCHAR(100) NOT NULL, + `ordering` INT(11) NOT NULL DEFAULT 0, + `enabled` INT(1) NOT NULL DEFAULT 1, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; diff --git a/system/migrations/28.php b/system/migrations/28.php index d06487c88..9df8dedcb 100644 --- a/system/migrations/28.php +++ b/system/migrations/28.php @@ -1,10 +1,25 @@ exec('DROP TABLE IF EXISTS `' . TABLE_PREFIX . 'hooks`;'); +$up = function () use ($db) { + $db->dropTable(TABLE_PREFIX . 'hooks'); + + $cache = Cache::getInstance(); + if($cache->enabled()) { + $cache->delete('hooks'); + } +}; + +$down = function () use ($db) { + $db->exec(file_get_contents(__DIR__ . '/28-hooks.sql')); + + $cache = Cache::getInstance(); + if($cache->enabled()) { + $cache->delete('hooks'); + } +}; -$cache = Cache::getInstance(); -if($cache->enabled()) { - $cache->delete('hooks'); -} diff --git a/system/migrations/29.php b/system/migrations/29.php index 79e3d81d5..e9c1ec7f3 100644 --- a/system/migrations/29.php +++ b/system/migrations/29.php @@ -1,5 +1,16 @@ hasColumn(TABLE_PREFIX . 'pages', 'enable_tinymce')) { - $db->exec('ALTER TABLE `' . TABLE_PREFIX . 'pages` ADD `enable_tinymce` TINYINT(1) NOT NULL DEFAULT 1 COMMENT \'1 - enabled, 0 - disabled\' AFTER `php`;'); -} +$up = function () use ($db) { + if (!$db->hasColumn(TABLE_PREFIX . 'pages', 'enable_tinymce')) { + $db->addColumn(TABLE_PREFIX . 'pages', 'enable_tinymce', "TINYINT(1) NOT NULL DEFAULT 1 COMMENT '1 - enabled, 0 - disabled' AFTER `php`"); + } +}; + +$down = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'pages', 'enable_tinymce')) { + $db->dropColumn(TABLE_PREFIX . 'pages', 'enable_tinymce'); + } +}; diff --git a/system/migrations/3.php b/system/migrations/3.php index 76c0acc8d..f79dcbe73 100644 --- a/system/migrations/3.php +++ b/system/migrations/3.php @@ -1,3 +1,15 @@ query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` ADD `ipv6` BINARY(16) NOT NULL DEFAULT 0;"); -?> \ No newline at end of file +/** + * @var OTS_DB_MySQL $db + */ + +$up = function () use ($db) { + if (!$db->hasColumn(TABLE_PREFIX . 'account_actions', 'ipv6')) { + $db->addColumn(TABLE_PREFIX . 'account_actions', 'ipv6', "BINARY(16) NOT NULL DEFAULT 0"); + } +}; + +$down = function () { + // we don't want data loss + //$db->dropColumn(TABLE_PREFIX . 'account_actions', 'ipv6'); +}; diff --git a/system/migrations/30-rules.txt b/system/migrations/30-rules.txt new file mode 100644 index 000000000..2b226230c --- /dev/null +++ b/system/migrations/30-rules.txt @@ -0,0 +1,25 @@ +1. Names +a) Names which contain insulting (e.g. "Bastard"), racist (e.g. "Nigger"), extremely right-wing (e.g. "Hitler"), sexist (e.g. "Bitch") or offensive (e.g. "Copkiller") language. +b) Names containing parts of sentences (e.g. "Mike returns"), nonsensical combinations of letters (e.g. "Fgfshdsfg") or invalid formattings (e.g. "Thegreatknight"). +c) Names that obviously do not describe a person (e.g. "Christmastree", "Matrix"), names of real life celebrities (e.g. "Britney Spears"), names that refer to real countries (e.g. "Swedish Druid"), names which were created to fake other players' identities (e.g. "Arieswer" instead of "Arieswar") or official positions (e.g. "System Admin"). + +2. Cheating +a) Exploiting obvious errors of the game ("bugs"), for instance to duplicate items. If you find an error you must report it to CipSoft immediately. +b) Intentional abuse of weaknesses in the gameplay, for example arranging objects or players in a way that other players cannot move them. +c) Using tools to automatically perform or repeat certain actions without any interaction by the player ("macros"). +d) Manipulating the client program or using additional software to play the game. +e) Trying to steal other players\' account data ("hacking"). +f) Playing on more than one account at the same time ("multi-clienting"). +g) Offering account data to other players or accepting other players' account data ("account-trading/sharing"). + +3. Gamemasters +a) Threatening a gamemaster because of his or her actions or position as a gamemaster. +b) Pretending to be a gamemaster or to have influence on the decisions of a gamemaster. +c) Intentionally giving wrong or misleading information to a gamemaster concerning his or her investigations or making false reports about rule violations. + +4. Player Killing +a) Excessive killing of characters who are not marked with a "skull" on worlds which are not PvP-enforced. Please note that killing marked characters is not a reason for a banishment. + +A violation of the Tibia Rules may lead to temporary banishment of characters and accounts. In severe cases removal or modification of character skills, attributes and belongings, as well as the permanent removal of accounts without any compensation may be considered. The sanction is based on the seriousness of the rule violation and the previous record of the player. It is determined by the gamemaster imposing the banishment. + +These rules may be changed at any time. All changes will be announced on the official website. diff --git a/system/migrations/30.php b/system/migrations/30.php index 3d9195976..2e38e468f 100644 --- a/system/migrations/30.php +++ b/system/migrations/30.php @@ -1,31 +1,27 @@ query("SELECT `id` FROM `" . TABLE_PREFIX . "pages` WHERE `name` LIKE " . $db->quote('rules_on_the_page') . " LIMIT 1;"); -if($query->rowCount() === 0) { - $db->exec("INSERT INTO `myaac_pages` (`id`, `name`, `title`, `body`, `date`, `player_id`, `php`, `enable_tinymce`, `access`, `hide`) VALUES - (null, 'rules_on_the_page', 'Rules', '1. Names -a) Names which contain insulting (e.g. \"Bastard\"), racist (e.g. \"Nigger\"), extremely right-wing (e.g. \"Hitler\"), sexist (e.g. \"Bitch\") or offensive (e.g. \"Copkiller\") language. -b) Names containing parts of sentences (e.g. \"Mike returns\"), nonsensical combinations of letters (e.g. \"Fgfshdsfg\") or invalid formattings (e.g. \"Thegreatknight\"). -c) Names that obviously do not describe a person (e.g. \"Christmastree\", \"Matrix\"), names of real life celebrities (e.g. \"Britney Spears\"), names that refer to real countries (e.g. \"Swedish Druid\"), names which were created to fake other players\' identities (e.g. \"Arieswer\" instead of \"Arieswar\") or official positions (e.g. \"System Admin\"). +use MyAAC\Models\Pages; -2. Cheating -a) Exploiting obvious errors of the game (\"bugs\"), for instance to duplicate items. If you find an error you must report it to CipSoft immediately. -b) Intentional abuse of weaknesses in the gameplay, for example arranging objects or players in a way that other players cannot move them. -c) Using tools to automatically perform or repeat certain actions without any interaction by the player (\"macros\"). -d) Manipulating the client program or using additional software to play the game. -e) Trying to steal other players\' account data (\"hacking\"). -f) Playing on more than one account at the same time (\"multi-clienting\"). -g) Offering account data to other players or accepting other players\' account data (\"account-trading/sharing\"). +$up = function () { + $rulesOnPage = Pages::where('name', 'rules_on_the_page')->first(); + if (!$rulesOnPage) { + Pages::create([ + 'name' => 'rules_on_the_page', + 'title' => 'Rules', + 'body' => file_get_contents(__DIR__ . '/30-rules.txt'), + 'date' => time(), + 'player_id' => 1, + 'php' => 0, + 'enable_tinymce' => 0, + 'access' => 0, + 'hidden' => 0, + ]); + } +}; -3. Gamemasters -a) Threatening a gamemaster because of his or her actions or position as a gamemaster. -b) Pretending to be a gamemaster or to have influence on the decisions of a gamemaster. -c) Intentionally giving wrong or misleading information to a gamemaster concerning his or her investigations or making false reports about rule violations. - -4. Player Killing -a) Excessive killing of characters who are not marked with a \"skull\" on worlds which are not PvP-enforced. Please note that killing marked characters is not a reason for a banishment. - -A violation of the Tibia Rules may lead to temporary banishment of characters and accounts. In severe cases removal or modification of character skills, attributes and belongings, as well as the permanent removal of accounts without any compensation may be considered. The sanction is based on the seriousness of the rule violation and the previous record of the player. It is determined by the gamemaster imposing the banishment. - -These rules may be changed at any time. All changes will be announced on the official website.', 0, 1, 0, 0, 0, 0);"); -} +$down = function () { + $rulesOnPage = Pages::where('name', 'rules_on_the_page')->first(); + if ($rulesOnPage) { + Pages::where('name', 'rules_on_the_page')->delete(); + } +}; diff --git a/system/migrations/31.php b/system/migrations/31.php index 8dadb8176..edbf70207 100644 --- a/system/migrations/31.php +++ b/system/migrations/31.php @@ -1,57 +1,121 @@ hasColumn(TABLE_PREFIX . 'monsters', 'elements')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `elements` TEXT NOT NULL AFTER `immunities`;"); -} +$up = function () use ($db) { + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'elements')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'elements', "TEXT NOT NULL AFTER `immunities`"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'pushable')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `pushable` TINYINT(1) NOT NULL DEFAULT '0' AFTER `convinceable`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'pushable')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'pushable', "TINYINT(1) NOT NULL DEFAULT '0' AFTER `convinceable`"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushitems')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canpushitems` TINYINT(1) NOT NULL DEFAULT '0' AFTER `pushable`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushitems')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'canpushitems', "TINYINT(1) NOT NULL DEFAULT '0' AFTER `pushable`"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushcreatures')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canpushcreatures` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canpushitems`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushcreatures')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'canpushcreatures', "TINYINT(1) NOT NULL DEFAULT '0' AFTER `canpushitems`"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonenergy')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonenergy` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canpushitems`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonenergy')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'canwalkonenergy', "TINYINT(1) NOT NULL DEFAULT '0' AFTER `canpushitems`"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonpoison')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonpoison` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonenergy`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonpoison')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'canwalkonpoison', "TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonenergy`"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonfire')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonfire` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonpoison`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonfire')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'canwalkonfire', "TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonpoison`"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'runonhealth')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `runonhealth` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonfire`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'runonhealth')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'runonhealth', "TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonfire`"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'hostile')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `hostile` TINYINT(1) NOT NULL DEFAULT '0' AFTER `runonhealth`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'hostile')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'hostile', "TINYINT(1) NOT NULL DEFAULT '0' AFTER `runonhealth`"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'attackable')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `attackable` TINYINT(1) NOT NULL DEFAULT '0' AFTER `hostile`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'attackable')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'attackable', "TINYINT(1) NOT NULL DEFAULT '0' AFTER `hostile`"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'rewardboss')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `rewardboss` TINYINT(1) NOT NULL DEFAULT '0' AFTER `attackable`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'rewardboss')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'rewardboss', "TINYINT(1) NOT NULL DEFAULT '0' AFTER `attackable`"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'defense')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `defense` INT(11) NOT NULL DEFAULT '0' AFTER `rewardboss`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'defense')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'defense', "INT(11) NOT NULL DEFAULT '0' AFTER `rewardboss`"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'armor')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `armor` INT(11) NOT NULL DEFAULT '0' AFTER `defense`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'armor')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'armor', "INT(11) NOT NULL DEFAULT '0' AFTER `defense`"); + } + + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'summons')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'summons', "TEXT NOT NULL AFTER `loot`"); + } +}; + +$down = function () use ($db) { + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'elements')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'elements'); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'pushable')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'pushable'); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushitems')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'canpushitems'); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushcreatures')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'canpushcreatures'); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonenergy')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'canwalkonenergy'); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonpoison')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'canwalkonpoison'); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonfire')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'canwalkonfire'); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'runonhealth')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'runonhealth'); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'hostile')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'hostile'); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'attackable')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'attackable'); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'rewardboss')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'rewardboss'); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'defense')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'defense'); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'armor')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'armor'); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'summons')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'summons'); + } +}; -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'summons')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `summons` TEXT NOT NULL AFTER `loot`;"); -} diff --git a/system/migrations/32.php b/system/migrations/32.php index ca1e4859f..63f7b7578 100644 --- a/system/migrations/32.php +++ b/system/migrations/32.php @@ -1,4 +1,14 @@ exec('ALTER TABLE `' . TABLE_PREFIX . "visitors` MODIFY `page` VARCHAR(2048) NOT NULL;"); +$up = function () use ($db) { + $db->modifyColumn(TABLE_PREFIX . 'visitors', 'page', 'VARCHAR(2048) NOT NULL'); +}; + +$down = function () { + // nothing to be done, as we have just extended the size of a column +}; diff --git a/system/migrations/33.php b/system/migrations/33.php index 12fe4c2c0..97c39fcc9 100644 --- a/system/migrations/33.php +++ b/system/migrations/33.php @@ -1,6 +1,16 @@ exec('ALTER TABLE `' . TABLE_PREFIX . "visitors` MODIFY `ip` VARCHAR(45) NOT NULL;"); +$up = function () use ($db) { + $db->modifyColumn(TABLE_PREFIX . 'visitors', 'ip', 'VARCHAR(15) NOT NULL'); +}; + +$down = function () { + // nothing to be done, as we have just extended the size of a column +}; diff --git a/system/migrations/34.php b/system/migrations/34.php index 6f4e6b4ab..0e51c7c32 100644 --- a/system/migrations/34.php +++ b/system/migrations/34.php @@ -1,4 +1,18 @@ exec('ALTER TABLE `' . TABLE_PREFIX . "visitors` ADD `user_agent` VARCHAR(255) NOT NULL DEFAULT '';"); +$up = function () use ($db) { + if (!$db->hasColumn(TABLE_PREFIX . 'visitors', 'user_agent')) { + $db->addColumn(TABLE_PREFIX . 'visitors', 'user_agent', "VARCHAR(255) NOT NULL DEFAULT ''"); + } +}; + +$down = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'visitors', 'user_agent')) { + $db->dropColumn(TABLE_PREFIX . 'visitors', 'user_agent'); + } +}; diff --git a/system/migrations/35.php b/system/migrations/35.php index 8016807d6..1baf68a75 100644 --- a/system/migrations/35.php +++ b/system/migrations/35.php @@ -1,3 +1,17 @@ exec('ALTER TABLE `' . TABLE_PREFIX . "monsters` ADD `look` VARCHAR(255) NOT NULL DEFAULT '' AFTER `health`;"); \ No newline at end of file +$up = function () use ($db) { + if (!$db->hasColumn(TABLE_PREFIX . 'monsters', 'look')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'look', "VARCHAR(255) NOT NULL DEFAULT '' AFTER `health`"); + } +}; + +$down = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'monsters', 'look')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'look'); + } +}; diff --git a/system/migrations/36-settings.sql b/system/migrations/36-settings.sql new file mode 100644 index 000000000..eded157bb --- /dev/null +++ b/system/migrations/36-settings.sql @@ -0,0 +1,9 @@ +CREATE TABLE `myaac_settings` +( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NOT NULL DEFAULT '', + `key` VARCHAR(255) NOT NULL DEFAULT '', + `value` TEXT NOT NULL, + PRIMARY KEY (`id`), + KEY `key` (`key`) +) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; diff --git a/system/migrations/36.php b/system/migrations/36.php index d88e9d287..1f27c51fd 100644 --- a/system/migrations/36.php +++ b/system/migrations/36.php @@ -1,14 +1,18 @@ hasTable(TABLE_PREFIX . 'settings')) { - $db->exec("CREATE TABLE `" . TABLE_PREFIX . "settings` - ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(255) NOT NULL DEFAULT '', - `key` VARCHAR(255) NOT NULL DEFAULT '', - `value` TEXT NOT NULL, - PRIMARY KEY (`id`), - KEY `key` (`key`) - ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;"); -} +$up = function () use ($db) { + // add settings table + if (!$db->hasTable(TABLE_PREFIX . 'settings')) { + $db->exec(file_get_contents(__DIR__ . '/36-settings.sql')); + } +}; + +$down = function () { + // will break the aac + //if ($db->hasTable(TABLE_PREFIX . 'settings')) { + // $db->dropTable(TABLE_PREFIX . 'settings'); + //} +}; diff --git a/system/migrations/37.php b/system/migrations/37.php index dd12f35a6..110d15c2c 100644 --- a/system/migrations/37.php +++ b/system/migrations/37.php @@ -5,4 +5,10 @@ use MyAAC\Models\Pages; -Pages::query()->where('access', 1)->update(['access' => 0]); +$up = function () { + Pages::query()->where('access', 1)->update(['access' => 0]); +}; + +$down = function () { + Pages::query()->where('access', 0)->update(['access' => 1]); +}; diff --git a/system/migrations/38.php b/system/migrations/38.php index b2d066a7d..c8f6326c2 100644 --- a/system/migrations/38.php +++ b/system/migrations/38.php @@ -1,5 +1,16 @@ hasColumn('players', 'hide')) { - $db->exec("ALTER TABLE `players` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -} +$definition = 'TINYINT(1) NOT NULL DEFAULT 0'; -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "changelog` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "faq` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "forum_boards` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "news` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "news_categories` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "pages` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "gallery` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "spells` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); +$up = function () use ($db, $definition) { + if (!$db->hasColumn('players', 'hide')) { + $db->changeColumn('players', 'hidden', 'hide', $definition); + } + + $db->changeColumn(TABLE_PREFIX . 'changelog', 'hidden', 'hide', $definition); + $db->changeColumn(TABLE_PREFIX . 'faq', 'hidden', 'hide', $definition); + $db->changeColumn(TABLE_PREFIX . 'forum_boards', 'hidden', 'hide', $definition); + $db->changeColumn(TABLE_PREFIX . 'monsters', 'hidden', 'hide', $definition); + $db->changeColumn(TABLE_PREFIX . 'news', 'hidden', 'hide', $definition); + $db->changeColumn(TABLE_PREFIX . 'news_categories', 'hidden', 'hide', $definition); + $db->changeColumn(TABLE_PREFIX . 'pages', 'hidden', 'hide', $definition); + $db->changeColumn(TABLE_PREFIX . 'gallery', 'hidden', 'hide', $definition); + $db->changeColumn(TABLE_PREFIX . 'spells', 'hidden', 'hide', $definition); +}; + +$down = function () use ($db, $definition) { + if (!$db->hasColumn('players', 'hidden')) { + $db->changeColumn('players', 'hide', 'hidden', $definition); + } + + $db->changeColumn(TABLE_PREFIX . 'changelog', 'hide', 'hidden', $definition); + $db->changeColumn(TABLE_PREFIX . 'faq', 'hide', 'hidden', $definition); + $db->changeColumn(TABLE_PREFIX . 'forum_boards', 'hide', 'hidden', $definition); + $db->changeColumn(TABLE_PREFIX . 'monsters', 'hide', 'hidden', $definition); + $db->changeColumn(TABLE_PREFIX . 'news', 'hide', 'hidden', $definition); + $db->changeColumn(TABLE_PREFIX . 'news_categories', 'hide', 'hidden', $definition); + $db->changeColumn(TABLE_PREFIX . 'pages', 'hide', 'hidden', $definition); + $db->changeColumn(TABLE_PREFIX . 'gallery', 'hide', 'hidden', $definition); + $db->changeColumn(TABLE_PREFIX . 'spells', 'hide', 'hidden', $definition); +}; diff --git a/system/migrations/4.php b/system/migrations/4.php index db17feb12..93746eef4 100644 --- a/system/migrations/4.php +++ b/system/migrations/4.php @@ -1,3 +1,16 @@ hasColumn(TABLE_PREFIX . 'monsters', 'id')) - $db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `id` int(11) NOT NULL AUTO_INCREMENT primary key FIRST;"); \ No newline at end of file +/** + * @var OTS_DB_MySQL $db + */ + +$up = function () use ($db) { + if (!$db->hasColumn(TABLE_PREFIX . 'monsters', 'id')) { + $db->addColumn(TABLE_PREFIX . 'monsters', 'id', "int(11) NOT NULL AUTO_INCREMENT primary key FIRST"); + } +}; + +$down = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'monsters', 'id')) { + $db->dropColumn(TABLE_PREFIX . 'monsters', 'id'); + } +}; diff --git a/system/migrations/40.php b/system/migrations/40.php index 7a7eb3108..ef492a112 100644 --- a/system/migrations/40.php +++ b/system/migrations/40.php @@ -5,8 +5,19 @@ use MyAAC\Models\Menu; -Menu::where('link', 'lastkills')->update(['link' => 'last-kills']); -Menu::where('link', 'serverInfo')->update(['link' => 'server-info']); -Menu::where('link', 'experienceStages')->update(['link' => 'exp-stages']); -Menu::where('link', 'experienceTable')->update(['link' => 'exp-table']); -Menu::where('link', 'creatures')->update(['link' => 'monsters']); +$up = function() { + Menu::where('link', 'lastkills')->update(['link' => 'last-kills']); + Menu::where('link', 'serverInfo')->update(['link' => 'server-info']); + Menu::where('link', 'experienceStages')->update(['link' => 'exp-stages']); + Menu::where('link', 'experienceTable')->update(['link' => 'exp-table']); + Menu::where('link', 'creatures')->update(['link' => 'monsters']); +}; + +$down = function() { + Menu::where('link', 'last-kills')->update(['link' => 'lastkills']); + Menu::where('link', 'server-info')->update(['link' => 'serverInfo']); + Menu::where('link', 'exp-stages')->update(['link' => 'experienceStages']); + Menu::where('link', 'exp-table')->update(['link' => 'experienceTable']); + Menu::where('link', 'monsters')->update(['link' => 'creatures']); +}; + diff --git a/system/migrations/5.php b/system/migrations/5.php index bef48d619..d269a3485 100644 --- a/system/migrations/5.php +++ b/system/migrations/5.php @@ -1,4 +1,16 @@ hasColumn(TABLE_PREFIX . 'spells', 'cities')) - $db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` DROP COLUMN cities;"); -?> \ No newline at end of file +/** + * @var OTS_DB_MySQL $db + */ + +$up = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'spells', 'cities')) { + $db->dropColumn(TABLE_PREFIX . 'spells', 'cities'); + } +}; + +$up = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'spells', 'cities')) { + $db->addColumn(TABLE_PREFIX . 'spells', 'cities', 'VARCHAR(32) NOT NULL'); + } +}; diff --git a/system/migrations/6.php b/system/migrations/6.php index e287d55ab..b99671d34 100644 --- a/system/migrations/6.php +++ b/system/migrations/6.php @@ -1,3 +1,16 @@ hasColumn(TABLE_PREFIX . 'hooks', 'enabled')) - $db->query("ALTER TABLE `" . TABLE_PREFIX . "hooks` ADD `enabled` INT(1) NOT NULL DEFAULT 1;"); \ No newline at end of file +/** + * @var OTS_DB_MySQL $db + */ + +$up = function () use ($db) { + if (!$db->hasColumn(TABLE_PREFIX . 'hooks', 'enabled')) { + $db->addColumn(TABLE_PREFIX . 'hooks', 'enabled', 'INT(1) NOT NULL DEFAULT 1'); + } +}; + +$down = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'hooks', 'enabled')) { + $db->dropColumn(TABLE_PREFIX . 'hooks', 'enabled'); + } +}; diff --git a/system/migrations/7.php b/system/migrations/7.php index a34f5a22d..a96ed7c9f 100644 --- a/system/migrations/7.php +++ b/system/migrations/7.php @@ -1,4 +1,16 @@ hasColumn(TABLE_PREFIX . 'screenshots', 'name')) - $db->query("ALTER TABLE `" . TABLE_PREFIX . "screenshots` DROP `name`;"); -?> \ No newline at end of file +/** + * @var OTS_DB_MySQL $db + */ + +$up = function () use ($db) { + if ($db->hasColumn(TABLE_PREFIX . 'screenshots', 'name')) { + $db->dropColumn(TABLE_PREFIX . 'screenshots', 'name'); + } +}; + +$up = function () use ($db) { + if (!$db->hasColumn(TABLE_PREFIX . 'screenshots', 'name')) { + $db->addColumn(TABLE_PREFIX . 'screenshots', 'name', 'VARCHAR(30) NOT NULL'); + } +}; diff --git a/system/migrations/8.php b/system/migrations/8.php index 4785e23b4..54e9db9df 100644 --- a/system/migrations/8.php +++ b/system/migrations/8.php @@ -1,17 +1,31 @@ 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 () use ($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)); - } \ No newline at end of file + } + } +}; + +$down = function () use ($db) { + if ($db->hasTable(TABLE_PREFIX . 'forum_boards')) { + $db->renameTable(TABLE_PREFIX . 'forum_boards', TABLE_PREFIX . 'forum_sections'); + } +}; diff --git a/system/migrations/9.php b/system/migrations/9.php index d4869c10e..c0db4971b 100644 --- a/system/migrations/9.php +++ b/system/migrations/9.php @@ -1,9 +1,18 @@ query("ALTER TABLE `" . TABLE_PREFIX . "bugtracker` MODIFY `type` INT(11) NOT NULL DEFAULT 0;"); - $db->query("ALTER TABLE `" . TABLE_PREFIX . "bugtracker` MODIFY `status` INT(11) NOT NULL DEFAULT 0;"); - $db->query("ALTER TABLE `" . TABLE_PREFIX . "bugtracker` MODIFY `id` INT(11) NOT NULL DEFAULT 0;"); - $db->query("ALTER TABLE `" . TABLE_PREFIX . "bugtracker` MODIFY `subject` VARCHAR(255) NOT NULL DEFAULT '';"); - $db->query("ALTER TABLE `" . TABLE_PREFIX . "bugtracker` MODIFY `reply` INT(11) NOT NULL DEFAULT 0;"); - $db->query("ALTER TABLE `" . TABLE_PREFIX . "bugtracker` MODIFY `who` INT(11) NOT NULL DEFAULT 0;"); - $db->query("ALTER TABLE `" . TABLE_PREFIX . "bugtracker` MODIFY `tag` INT(11) NOT NULL DEFAULT 0;"); -?> \ No newline at end of file +/** + * @var OTS_DB_MySQL $db + */ + +$up = function () use ($db) { + $db->modifyColumn(TABLE_PREFIX . 'bugtracker', 'type', "INT(11) NOT NULL DEFAULT 0"); + $db->modifyColumn(TABLE_PREFIX . 'bugtracker', 'status', "INT(11) NOT NULL DEFAULT 0"); + $db->modifyColumn(TABLE_PREFIX . 'bugtracker', 'id', "INT(11) NOT NULL DEFAULT 0"); + $db->modifyColumn(TABLE_PREFIX . 'bugtracker', 'subject', "VARCHAR(255) NOT NULL DEFAULT ''"); + $db->modifyColumn(TABLE_PREFIX . 'bugtracker', 'reply', "INT(11) NOT NULL DEFAULT 0"); + $db->modifyColumn(TABLE_PREFIX . 'bugtracker', 'who', "INT(11) NOT NULL DEFAULT 0"); + $db->modifyColumn(TABLE_PREFIX . 'bugtracker', 'tag', "INT(11) NOT NULL DEFAULT 0"); +}; + +$down = function () { + // nothing to do here +}; diff --git a/system/settings.php b/system/settings.php index 3f8fe21b3..89028cf75 100644 --- a/system/settings.php +++ b/system/settings.php @@ -392,6 +392,13 @@ 'default' => false, 'is_config' => true, ], + 'database_auto_migrate' => [ + 'name' => 'Database Auto Migrate', + 'desc' => 'Migrate database to latest version in myaac, automatically.', + 'type' => 'boolean', + 'default' => true, + 'is_config' => true, + ], [ 'type' => 'category', 'title' => 'Mailing', diff --git a/system/src/Commands/CacheClearCommand.php b/system/src/Commands/CacheClearCommand.php index bdab1f211..ff4d5d4a9 100644 --- a/system/src/Commands/CacheClearCommand.php +++ b/system/src/Commands/CacheClearCommand.php @@ -16,6 +16,8 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { + require SYSTEM . 'init.php'; + $io = new SymfonyStyle($input, $output); if (!clearCache()) { diff --git a/system/src/Commands/Command.php b/system/src/Commands/Command.php index 76f3810e6..caa2c0d3d 100644 --- a/system/src/Commands/Command.php +++ b/system/src/Commands/Command.php @@ -2,12 +2,8 @@ namespace MyAAC\Commands; -use MyAAC\Hooks; use Symfony\Component\Console\Command\Command as SymfonyCommand; class Command extends SymfonyCommand { - public function __construct() { - parent::__construct(); - } } diff --git a/system/src/Commands/CronjobCommand.php b/system/src/Commands/CronjobCommand.php index f314b73b8..b5eb475a2 100644 --- a/system/src/Commands/CronjobCommand.php +++ b/system/src/Commands/CronjobCommand.php @@ -16,10 +16,11 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { + require SYSTEM . 'init.php'; + // Create a new scheduler $scheduler = new Scheduler(); - global $hooks; $hooks->trigger(HOOK_CRONJOB, ['scheduler' => $scheduler]); // Let the scheduler execute jobs which are due. diff --git a/system/src/Commands/CronjobInstallCommand.php b/system/src/Commands/CronjobInstallCommand.php index adcf8b20a..d6b9ee603 100644 --- a/system/src/Commands/CronjobInstallCommand.php +++ b/system/src/Commands/CronjobInstallCommand.php @@ -17,6 +17,8 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { + require SYSTEM . 'init.php'; + $io = new SymfonyStyle($input, $output); if (MYAAC_OS !== 'LINUX') { diff --git a/system/src/Commands/MailSendCommand.php b/system/src/Commands/MailSendCommand.php index d0db7b690..ff1450e67 100644 --- a/system/src/Commands/MailSendCommand.php +++ b/system/src/Commands/MailSendCommand.php @@ -21,8 +21,15 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { + require SYSTEM . 'init.php'; + $io = new SymfonyStyle($input, $output); + if (!setting('core.mail_enabled')) { + $io->error('Mailing is not enabled on this server'); + return Command::FAILURE; + } + $email_account_name = $input->getArgument('recipient'); $subject = $input->getOption('subject'); if (!$subject) { diff --git a/system/src/Commands/MigrateCommand.php b/system/src/Commands/MigrateCommand.php new file mode 100644 index 000000000..a8a21016b --- /dev/null +++ b/system/src/Commands/MigrateCommand.php @@ -0,0 +1,28 @@ +setName('migrate') + ->setDescription('This command updates the AAC to latest migration'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + require SYSTEM . 'init.php'; + + $io = new SymfonyStyle($input, $output); + require SYSTEM . 'migrate.php'; + + $io->success('Migrated to latest version (' . DATABASE_VERSION . ')'); + return Command::SUCCESS; + } +} diff --git a/system/src/Commands/MigrateRunCommand.php b/system/src/Commands/MigrateRunCommand.php index ee0265b3d..edfa108dc 100644 --- a/system/src/Commands/MigrateRunCommand.php +++ b/system/src/Commands/MigrateRunCommand.php @@ -21,6 +21,8 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { + require SYSTEM . 'init.php'; + $io = new SymfonyStyle($input, $output); $ids = $input->getArgument('id'); diff --git a/system/src/Commands/MigrateToCommand.php b/system/src/Commands/MigrateToCommand.php new file mode 100644 index 000000000..b82012ed0 --- /dev/null +++ b/system/src/Commands/MigrateToCommand.php @@ -0,0 +1,108 @@ +setName('migrate:to') + ->setDescription('This command migrates to specific version of database') + ->addArgument('version', + InputArgument::REQUIRED, + 'Version number' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + + $versionDest = $input->getArgument('version'); + + if (!$versionDest || $versionDest > DATABASE_VERSION || $versionDest < 1) { + $io->error('Please enter a valid version number'); + return Command::FAILURE; + } + + $this->initEnv(); + + $currentVersion = Config::where('name', 'database_version')->first()->value; + if ($currentVersion > $versionDest) { + // downgrade + for ($i = $currentVersion; $i > $versionDest; $i--) { + echo $i . ' '; + $this->executeMigration($i, false); + } + } + else if ($currentVersion < $versionDest) { + // upgrade + for ($i = $currentVersion + 1; $i <= $versionDest; $i++) { + echo $i . ' '; + $this->executeMigration($i, true); + } + } + else { + $io->success('Nothing to be done'); + return Command::SUCCESS; + } + + $upgrade = ($currentVersion < $versionDest ? 'Upgrade' : 'Downgrade'); + $io->success("Migration ({$upgrade}) to version {$versionDest} has been completed"); + + return Command::SUCCESS; + } + + private function executeMigration($id, $_up): void + { + global $db; + + $db->revalidateCache(); + + require SYSTEM . 'migrations/' . $id . '.php'; + if ($_up) { + if (isset($up)) { + $up(); + } + } + else { + if (isset($down)) { + $down(); + } + } + + updateDatabaseConfig('database_version', ($_up ? $id : $id - 1)); + } + + private function initEnv() + { + global $config; + if (!isset($config['installed']) || !$config['installed']) { + throw new \RuntimeException('MyAAC has not been installed yet or there was error during installation. Please install again.'); + } + + if(empty($config['server_path'])) { + throw new \RuntimeException('Server Path has been not set. Go to config.php and set it.'); + } + + // take care of trailing slash at the end + if($config['server_path'][strlen($config['server_path']) - 1] !== '/') + $config['server_path'] .= '/'; + + $config['lua'] = load_config_lua($config['server_path'] . 'config.lua'); + + // POT + require_once SYSTEM . 'libs/pot/OTS.php'; + $ots = POT::getInstance(); + $eloquentConnection = null; + + require_once SYSTEM . 'database.php'; + } +} diff --git a/system/src/Commands/PluginInstallCommand.php b/system/src/Commands/PluginInstallCommand.php index 6330e08af..a37c08593 100644 --- a/system/src/Commands/PluginInstallCommand.php +++ b/system/src/Commands/PluginInstallCommand.php @@ -19,6 +19,8 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { + require SYSTEM . 'init.php'; + $io = new SymfonyStyle($input, $output); $pathToFile = $input->getArgument('pathToPluginZip'); diff --git a/system/src/Commands/PluginInstallInstallCommand.php b/system/src/Commands/PluginInstallInstallCommand.php index 5f1a1cd68..fe1b4f14c 100644 --- a/system/src/Commands/PluginInstallInstallCommand.php +++ b/system/src/Commands/PluginInstallInstallCommand.php @@ -19,6 +19,8 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { + require SYSTEM . 'init.php'; + $io = new SymfonyStyle($input, $output); $pluginName = $input->getArgument('plugin'); diff --git a/system/src/Commands/SettingsResetCommand.php b/system/src/Commands/SettingsResetCommand.php index a495edf43..78748b005 100644 --- a/system/src/Commands/SettingsResetCommand.php +++ b/system/src/Commands/SettingsResetCommand.php @@ -14,23 +14,43 @@ class SettingsResetCommand extends Command protected function configure(): void { $this->setName('settings:reset') - ->setDescription('Removes all settings in database'); + ->setDescription('Removes settings in database') + ->addArgument('name', + InputArgument::OPTIONAL, + 'Name of the plugin' + ); } protected function execute(InputInterface $input, OutputInterface $output): int { + require SYSTEM . 'init.php'; + $io = new SymfonyStyle($input, $output); - if (!$io->confirm('Are you sure you want to reset all settings in database?', false)) { + $name = $input->getArgument('name'); + + $all = !$name ? 'all' : $name; + if (!$io->confirm("Are you sure you want to reset {$all} settings in database?", false)) { return Command::FAILURE; } - SettingsModel::truncate(); + if (!$name) { + SettingsModel::truncate(); + } + else { + $settingsModel = SettingsModel::where('name', $name)->first(); + if (!$settingsModel) { + $io->warning('No settings for this plugin saved in database'); + return Command::SUCCESS; + } + + SettingsModel::where('name', $name)->delete(); + } $settings = Settings::getInstance(); $settings->clearCache(); - $io->success('Setting cleared successfully'); + $io->success('Settings cleared successfully'); return Command::SUCCESS; } } diff --git a/system/src/Commands/SettingsSetCommand.php b/system/src/Commands/SettingsSetCommand.php index 1159689a7..4ad332277 100644 --- a/system/src/Commands/SettingsSetCommand.php +++ b/system/src/Commands/SettingsSetCommand.php @@ -27,6 +27,8 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { + require SYSTEM . 'init.php'; + $io = new SymfonyStyle($input, $output); $key = $input->getArgument('key'); diff --git a/system/src/Models/Forum.php b/system/src/Models/Forum.php new file mode 100644 index 000000000..20fe4dcdb --- /dev/null +++ b/system/src/Models/Forum.php @@ -0,0 +1,30 @@ + 'integer', + 'last_post' => 'integer', + 'section' => 'integer', + 'replies' => 'integer', + 'views' => 'integer', + 'author_aid' => 'integer', + 'author_guid' => 'integer', + 'post_smile' => 'boolean', + 'post_html' => 'boolean', + 'post_date' => 'integer', + 'last_edit_aid' => 'integer', + 'edit_date' => 'integer', + 'sticked' => 'boolean', + 'closed' => 'boolean' + ]; +} diff --git a/system/src/Plugins.php b/system/src/Plugins.php index 00515139d..243ced24f 100644 --- a/system/src/Plugins.php +++ b/system/src/Plugins.php @@ -770,6 +770,8 @@ public static function getError() { */ public static function installMenus($templateName, $menus, $clearOld = false) { + global $db; + if ($clearOld) { Menu::where('template', $templateName)->delete(); } @@ -804,10 +806,14 @@ public static function installMenus($templateName, $menus, $clearOld = false) 'link' => $link, 'category' => $category, 'ordering' => $i++, - 'blank' => $blank, - 'color' => $color, ]; + // support for color and blank attributes + if($db->hasColumn(TABLE_PREFIX . 'menu', 'blank') && $db->hasColumn(TABLE_PREFIX . 'menu', 'color')) { + $insert_array['blank'] = $blank; + $insert_array['color'] = $color; + } + Menu::create($insert_array); } }