From 28683d66ee3558377cad54a9af79f928ceb72e32 Mon Sep 17 00:00:00 2001 From: slawkens1 Date: Sun, 14 Jan 2018 09:29:41 +0100 Subject: [PATCH] * update from master branch * update config.highscores_ids_hidden on install when there are samples already in database --- install/steps/7-finish.php | 33 +++-------------- system/migrations/20.php | 75 +++++++++++++++++++++----------------- 2 files changed, 48 insertions(+), 60 deletions(-) diff --git a/install/steps/7-finish.php b/install/steps/7-finish.php index 88e6ca39..54a48879 100644 --- a/install/steps/7-finish.php +++ b/install/steps/7-finish.php @@ -122,50 +122,34 @@ else { $insert_into_players = "INSERT INTO `players` (`id`, `name`, `group_id`, `account_id`, `level`, `vocation`, `health`, `healthmax`, `experience`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `maglevel`, `mana`, `manamax`, `manaspent`, `soul`, `town_id`, `posx`, `posy`, `posz`, `conditions`, `cap`, `sex`, `lastlogin`, `lastip`, `save`, `lastlogout`, `balance`, `$deleted`, `created`, `hidden`, `comment`) VALUES "; $success = true; - $highscores_ignored_ids = array(); $query = $db->query('SELECT `id` FROM `players` WHERE `name` = ' . $db->quote('Rook Sample')); if($query->rowCount() == 0) { if(!query($insert_into_players . "(null, 'Rook Sample', 1, " . getSession('account') . ", 1, 0, 150, 150, 4200, 118, 114, 38, 57, 130, 0, 0, 0, 0, 100, 1, 1000, 1000, 7, '', 400, 1, 1255179613, 2453925456, 1, 1255179614, 0, 0, UNIX_TIMESTAMP(), 1, '');")) $success = false; - else { - $highscores_ignored_ids[] = $db->lastInsertId(); - } } $query = $db->query('SELECT `id` FROM `players` WHERE `name` = ' . $db->quote('Sorcerer Sample')); if($query->rowCount() == 0) { if(!query($insert_into_players . "(null, 'Sorcerer Sample', 1, " . getSession('account') . ", 8, 1, 185, 185, 4200, 118, 114, 38, 57, 130, 0, 35, 35, 0, 100, 1, 1000, 1000, 7, '', 470, 1, 1255179571, 2453925456, 1, 1255179612, 0, 0, UNIX_TIMESTAMP(), 1, '');")) $success = false; - else { - $highscores_ignored_ids[] = $db->lastInsertId(); - } } $query = $db->query('SELECT `id` FROM `players` WHERE `name` = ' . $db->quote('Druid Sample')); if($query->rowCount() == 0) { if(!query($insert_into_players . "(null, 'Druid Sample', 1, " . getSession('account') . ", 8, 2, 185, 185, 4200, 118, 114, 38, 57, 130, 0, 35, 35, 0, 100, 1, 1000, 1000, 7, '', 470, 1, 1255179655, 2453925456, 1, 1255179658, 0, 0, UNIX_TIMESTAMP(), 1, '');")) $success = false; - else { - $highscores_ignored_ids[] = $db->lastInsertId(); - } } $query = $db->query('SELECT `id` FROM `players` WHERE `name` = ' . $db->quote('Paladin Sample')); if($query->rowCount() == 0) { if(!query($insert_into_players . "(null, 'Paladin Sample', 1, " . getSession('account') . ", 8, 3, 185, 185, 4200, 118, 114, 38, 57, 129, 0, 35, 35, 0, 100, 1, 1000, 1000, 7, '', 470, 1, 1255179854, 2453925456, 1, 1255179858, 0, 0, UNIX_TIMESTAMP(), 1, '');")) $success = false; - else { - $highscores_ignored_ids[] = $db->lastInsertId(); - } } $query = $db->query('SELECT `id` FROM `players` WHERE `name` = ' . $db->quote('Knight Sample')); if($query->rowCount() == 0) { if(!query($insert_into_players . "(null, 'Knight Sample', 1, " . getSession('account') . ", 8, 4, 185, 185, 4200, 118, 114, 38, 57, 131, 0, 35, 35, 0, 100, 1, 1000, 1000, 7, '', 470, 1, 1255179620, 2453925456, 1, 1255179654, 0, 0, UNIX_TIMESTAMP(), 1, '');")) $success = false; - else { - $highscores_ignored_ids[] = $db->lastInsertId(); - } } if($success) { @@ -191,20 +175,15 @@ else { } else { error(Spells::getLastError()); - } - $content = PHP_EOL; - $content .= '$config[\'highscores_ids_hidden\'] = array(' . implode(', ', $highscores_ignored_ids) . ');'; - $content .= PHP_EOL; - - $file = fopen(BASE . 'config.local.php', 'a+'); - if($file) { - fwrite($file, $content); - } - else { + // update config.highscores_ids_hidden + require_once(SYSTEM . 'migrations/20.php'); + $database_migration_20 = true; + $content = ''; + if(!databaseMigration20($content)) { $locale['step_database_error_file'] = str_replace('$FILE$', '' . BASE . 'config.local.php', $locale['step_database_error_file']); warning($locale['step_database_error_file'] . '
- '); + '); } $locale['step_finish_desc'] = str_replace('$ADMIN_PANEL$', generateLink(ADMIN_URL, $locale['step_finish_admin_panel'], true), $locale['step_finish_desc']); diff --git a/system/migrations/20.php b/system/migrations/20.php index 2d625748..0533b540 100644 --- a/system/migrations/20.php +++ b/system/migrations/20.php @@ -1,39 +1,48 @@ 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; + } + + $php_on_end = substr($content_of_file, -2, 2) == '?>'; + $content = PHP_EOL; + if($php_on_end) { + $content .= ''; + } + + file_put_contents($config_file, $content, FILE_APPEND); + return true; } - -$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") . ") 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; -} - -$php_on_end = substr($content_of_file, -2, 2) == '?>'; -$content = PHP_EOL; -if($php_on_end) { - $content .= ''; -} - -file_put_contents($config_file, $content, FILE_APPEND); ?> \ No newline at end of file