Skip to content
Permalink
Browse files

add .pid files to gitignore

use composer autoloader to all Classes
move console commands from core/ to Commands and add namespaces to autoload them
make `esc` bootstrapper much clean
move all requires from RunEsc command to esc bootstrapper
  • Loading branch information...
reaby committed Jun 28, 2019
1 parent f0cc3d6 commit e54e9b2af24183da2656eebe1477934d1957506f
@@ -7,4 +7,5 @@ logs/
cache/

config/*
!config/default
!config/default
*.pid
@@ -12,6 +12,10 @@
"symfony/process" : "^4.2",
"symfony/event-dispatcher" : "^4.2",
"composer/ca-bundle" : "^1.1"

},
"autoload": {
"psr-4": {
"esc\\": "core/"
}
}
}
@@ -33,7 +33,7 @@ class Template
*/
public function __construct(string $index, string $template)
{
$this->index = $index;
$this->index = $index;
$this->template = $template;
}
@@ -60,7 +60,9 @@ public static function showAll(string $index, array $values = null)
*/
public static function hideAll(string $index)
{
Server::sendDisplayManialinkPage('', sprintf('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><manialink id="%s" version="3"></manialink>', $index));
Server::sendDisplayManialinkPage('',
sprintf('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><manialink id="%s" version="3"></manialink>',
$index));
}
/**
@@ -70,16 +72,18 @@ public static function hideAll(string $index)
*/
public static function hide(Player $player, string $index)
{
Server::sendDisplayManialinkPage($player->Login, sprintf('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><manialink id="%s" version="3"></manialink>', $index));
Server::sendDisplayManialinkPage($player->Login,
sprintf('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><manialink id="%s" version="3"></manialink>',
$index));
}
/**
* Render and send a template to a player.
*
* @param \esc\Models\Player $player
* @param string $index
* @param null $values
* @param bool $multicall
* @param Player $player
* @param string $index
* @param null $values
* @param bool $multicall
*/
public static function show(Player $player, string $index, $values = null, bool $multicall = false)
{
@@ -94,7 +98,7 @@ public static function show(Player $player, string $index, $values = null, bool
}
$data['localPlayer'] = $player;
$xml = TemplateController::getTemplate($index, $data);
$xml = TemplateController::getTemplate($index, $data);
if ($xml != '') {
if ($multicall) {
@@ -1,5 +1,7 @@
<?php
namespace esc\Commands;
use esc\Classes\Log;
use Illuminate\Database\Capsule\Manager as Capsule;
use Symfony\Component\Console\Command\Command;
@@ -43,11 +45,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln("Updating player scores.");
$playerIds = $evoSC->table('stats')->where('Locals', '>', 0)->pluck('Player')->toArray();
$players = $evoSC->table('players')->whereIn('id', $playerIds)->get();
$bar = new ProgressBar($output, $players->count());
$limit = 200;
$players = $evoSC->table('players')->whereIn('id', $playerIds)->get();
$bar = new ProgressBar($output, $players->count());
$limit = 200;
$players->each(function ($player) use ($evoSC, $bar, $limit) {
$score = $evoSC->table('local-records')->where('Player', $player->id)->where('Rank', '<', $limit)->selectRaw($limit . ' - Rank as rank_diff')->get()->sum('rank_diff');
$score = $evoSC->table('local-records')->where('Player', $player->id)->where('Rank', '<',
$limit)->selectRaw($limit . ' - Rank as rank_diff')->get()->sum('rank_diff');
$evoSC->table('stats')->where('Player', $player->id)->update([
'Score' => $score,
@@ -62,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln("Fixing local ranks.");
$evoSC->table('stats')->update(['Rank' => 9999]);
$ranked = $evoSC->table('stats')->orderByDesc('Score')->where('Score', '>', 0)->get();
$bar = new ProgressBar($output, $ranked->count());
$bar = new ProgressBar($output, $ranked->count());
$ranked->each(function ($stat, $key) use ($evoSC, $bar) {
$evoSC->table('stats')->where('Player', $stat->Player)->update(['Rank' => $key + 1]);
$bar->advance();
@@ -1,7 +1,10 @@
<?php
namespace esc\Commands;
use Illuminate\Database\Capsule\Manager as Capsule;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -11,17 +14,23 @@ class ImportUaseco extends Command
protected function configure()
{
$this->setName('import:uaseco')
->setDescription('Import data from uaseco database, params: host, database, user, password [, table_prefix]')
->addArgument('host', InputArgument::REQUIRED, 'Host')
->addArgument('db', InputArgument::REQUIRED, 'Database')
->addArgument('user', InputArgument::REQUIRED, 'User')
->addArgument('password', InputArgument::REQUIRED, 'Password')
->addArgument('table_prefix', InputArgument::OPTIONAL, 'Prefix');
->setDescription('Import data from uaseco database, params: host, database, user, password [, table_prefix]')
->addArgument('host', InputArgument::REQUIRED, 'Host')
->addArgument('db', InputArgument::REQUIRED, 'Database')
->addArgument('user', InputArgument::REQUIRED, 'User')
->addArgument('password', InputArgument::REQUIRED, 'Password')
->addArgument('table_prefix', InputArgument::OPTIONAL, 'Prefix');
}
/**
* @param $output
* @param $count
*
* @return ProgressBar
*/
private function getBar($output, $count)
{
$bar = new \Symfony\Component\Console\Helper\ProgressBar($output, $count);
$bar = new ProgressBar($output, $count);
$bar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%');
$bar->start();
@@ -79,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
//Import players & stats
$output->writeln('Importing players & stats');
$uasecoPlayers = $uaseco->table('players')->get();
$bar = $this->getBar($output, $uasecoPlayers->count());
$bar = $this->getBar($output, $uasecoPlayers->count());
foreach ($uasecoPlayers as $player) {
$ply = $esc->table('players')->whereLogin($player->Login)->first();
@@ -120,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
//Import authors
$output->writeln('Importing map authors');
$authors = $uaseco->table('authors')->get();
$bar = $this->getBar($output, $authors->count());
$bar = $this->getBar($output, $authors->count());
foreach ($authors as $author) {
if ($esc->table('players')->where('Login', $author->Login)->get()->isEmpty()) {
$esc->table('players')->insert([
@@ -139,10 +148,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
//Import maps
$output->writeln('Importing maps');
$maps = $uaseco->table('maps')->get();
$bar = $this->getBar($output, $maps->count());
$bar = $this->getBar($output, $maps->count());
foreach ($maps as $map) {
$authorLogin = $uaseco->table('authors')->where('AuthorId', $map->AuthorId)->first()->Login;
$author = $esc->table('players')->whereLogin($authorLogin)->first();
$author = $esc->table('players')->whereLogin($authorLogin)->first();
if ($esc->table('maps')->where('uid', $map->Uid)->exists()) {
//TODO: Handle multiple map versions
@@ -165,14 +174,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
//Import map ratings
$output->writeln('Importing map-ratings');
$ratings = $uaseco->table('ratings')->get();
$bar = $this->getBar($output, $ratings->count());
$bar = $this->getBar($output, $ratings->count());
foreach ($ratings as $rating) {
$mxKarma = [0, 20, 40, 50, 60, 80, 100][$rating->Score + 3];
$mxKarma = [0, 20, 40, 50, 60, 80, 100][$rating->Score + 3];
$playerLogin = $uaseco->table('players')->where('PlayerId', $rating->PlayerId)->first()->Login;
$player = $esc->table('players')->whereLogin($playerLogin)->first();
$player = $esc->table('players')->whereLogin($playerLogin)->first();
$mapUid = $uaseco->table('maps')->where('MapId', $rating->MapId)->first()->Uid;
$map = $esc->table('maps')->where('UId', $mapUid)->first();
$map = $esc->table('maps')->where('UId', $mapUid)->first();
$esc->table('mx-karma')->insert([
'Player' => $player->id,
@@ -190,11 +199,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$playerIdMap = collect();
$output->writeln('Importing local records: Preparing UASECO player mapping...');
$uasecoMap = $uaseco->table('players')->select(['PlayerId', 'Login'])->get()->pluck('Login', 'PlayerId');
$uasecoMap = $uaseco->table('players')->select(['PlayerId', 'Login'])->get()->pluck('Login', 'PlayerId');
$playerTable = $uaseco->table('records')->select('PlayerId')->distinct()->get()->pluck('PlayerId');
$bar = $this->getBar($output, $playerTable->count());
$bar = $this->getBar($output, $playerTable->count());
$playerTable->map(function ($uasecoPlayerId) use ($esc, $uasecoMap, $bar, &$playerIdMap) {
$playerLogin = $uasecoMap->get($uasecoPlayerId);
$playerLogin = $uasecoMap->get($uasecoPlayerId);
$evoscPlayerId = $esc->table('players')->where('Login', $playerLogin)->select('id')->first()->id;
$playerIdMap->put($uasecoPlayerId, $evoscPlayerId);
$bar->advance();
@@ -204,12 +213,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('Importing local records: Starting import...');
$uasecoMapMap = $uaseco->table('maps')->select(['MapId', 'Uid'])->get()->pluck('Uid', 'MapId');
$bar = $this->getBar($output, $uaseco->table('records')->count());
$bar = $this->getBar($output, $uaseco->table('records')->count());
$uasecoMapMap->each(function ($uid, $uasecoMapId) use ($uaseco, $esc, $playerIdMap, $bar) {
$map = $esc->table('maps')->where('uid', $uid)->first();
$map = $esc->table('maps')->where('uid', $uid)->first();
$mapId = $map->id;
$evoscRecords = $esc->table('local-records')->where('Map', $mapId)->get()->keyBy('Player');
$evoscRecords = $esc->table('local-records')->where('Map', $mapId)->get()->keyBy('Player');
$uasecoRecords = $uaseco->table('records')->where('MapId', $uasecoMapId)->get();
$uasecoRecords->each(function ($record) use ($playerIdMap, $evoscRecords, $esc, $mapId, $bar) {
@@ -249,9 +258,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
//Fix local records ranks
$output->writeln('Fixing local records ranks');
$maps = $esc->table('maps')->get();
$bar = $this->getBar($output, $esc->table('local-records')->count());
$bar = $this->getBar($output, $esc->table('local-records')->count());
foreach ($maps as $map) {
$i = 1;
$i = 1;
$locals = $esc->table('local-records')->whereMap($map->id)->orderBy('Score')->get();
foreach ($locals as $local) {
$esc->table('local-records')->whereId($local->id)->update(['Rank' => $i]);
@@ -0,0 +1,69 @@
<?php
namespace esc\Commands;
use Illuminate\Support\Str;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class MakeMigration extends Command
{
protected function configure()
{
$this->setName('make:migration')
->setDescription('Create migration, placed in /Migrations')
->addArgument('migration_name', InputArgument::REQUIRED, 'The migration name');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('migration_name');
if (preg_match_all('/([A-Z][a-z]+)/', $name, $matches)) {
$filename = 'Migrations/' . time() . '_' . Str::slug(implode(' ', $matches[0])) . '.php';
$template = str_replace('{className}', $name, '<?php
namespace esc\Migrations;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
class {className} extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(Builder $schemaBuilder)
{
$schemaBuilder->create(\'table-name\', function (Blueprint $table) {
$table->increments(\'id\');
$table->string(\'column1\');
$table->integer(\'column2\')->nullable();
$table->boolean(\'column3\')->default(false);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(Builder $schemaBuilder)
{
$schemaBuilder->dropIfExists(\'table-name\');
}
}');
file_put_contents($filename, $template);
} else {
$output->writeln('Error: Invalid name entered, please use camel case (example: CreatePlayersTable)');
}
}
}
@@ -1,5 +1,7 @@
<?php
namespace esc\Commands;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Collection;
use Symfony\Component\Console\Command\Command;
@@ -11,7 +13,7 @@ class Migrate extends Command
{
protected function configure()
{
$this->setName('migrate')->addOption('--setup')->setDescription('Run all database migrations. Run after pulling updates');
$this->setName('migrate')->setDescription('Run all database migrations. Run after pulling updates');
}
protected function execute(InputInterface $input, OutputInterface $output)
@@ -20,9 +22,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
global $_isVeryVerbose;
global $_isDebug;
$_isVerbose = $output->isVerbose();
$_isVerbose = $output->isVerbose();
$_isVeryVerbose = $output->isVeryVerbose();
$_isDebug = $output->isDebug();
$_isDebug = $output->isDebug();
$output->writeln('Executing migrations...');
@@ -59,21 +61,27 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$previousBatch = $connection->table('migrations')
->get(['batch'])
->sortByDesc('batch')
->first();
->get(['batch'])
->sortByDesc('batch')
->first();
if ($previousBatch) {
$batch = $previousBatch->batch + 1;
} else {
$batch = 1;
}
$migrations = $this->getMigrations();
$migrationsTable = $connection->table('migrations');
$migrations = $this->getMigrations();
$migrationsTable = $connection->table('migrations');
$executedMigrations = $migrationsTable->get(['file']);
$migrations->each(function ($migration) use ($executedMigrations, $batch, $schemaBuilder, $migrationsTable, $output) {
$migrations->each(function ($migration) use (
$executedMigrations,
$batch,
$schemaBuilder,
$migrationsTable,
$output
) {
if ($executedMigrations->where('file', $migration->file)->isNotEmpty()) {
//Skip already executed migrations
return;
@@ -104,7 +112,7 @@ private function getMigrations(): Collection
return preg_match('/extends Migration/', $content);
})->map(function ($migration) {
$col = collect();
$col = collect();
$col->path = "Migrations/$migration";
$col->file = $migration;
@@ -125,7 +133,7 @@ private function getMigrations(): Collection
return preg_match('/extends Migration/', $content);
})->map(function ($migration) use ($moduleDir) {
$col = collect();
$col = collect();
$col->path = "core/Modules/$moduleDir/Migrations/$migration";
$col->file = $migration;

0 comments on commit e54e9b2

Please sign in to comment.
You can’t perform that action at this time.