diff --git a/app/Console/BaseCommand.php b/app/Console/BaseCommand.php new file mode 100644 index 00000000..2cbea30b --- /dev/null +++ b/app/Console/BaseCommand.php @@ -0,0 +1,51 @@ +info('Running "' . $cmd . '"'); + + $process = new Process($cmd); + $process->run(function ($type, $buffer) { + if (Process::ERR === $type) { + echo $buffer; + } else { + echo $buffer; + } + }); + } +} diff --git a/app/Console/Commands/AcarsReplay.php b/app/Console/Commands/AcarsReplay.php index 3b8537e1..04632f13 100644 --- a/app/Console/Commands/AcarsReplay.php +++ b/app/Console/Commands/AcarsReplay.php @@ -2,14 +2,13 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Collection; use GuzzleHttp\Client; +use App\Console\BaseCommand; use App\Facades\Utils; -use Symfony\Component\Console\Input\InputOption; -class AcarsReplay extends Command +class AcarsReplay extends BaseCommand { protected $signature = 'phpvms:replay {files} {--manual} {--write-all} {--no-submit}'; protected $description = 'Replay an ACARS file'; diff --git a/app/Console/Commands/CreateDatabase.php b/app/Console/Commands/CreateDatabase.php index 8afbba2a..7c051f1a 100644 --- a/app/Console/Commands/CreateDatabase.php +++ b/app/Console/Commands/CreateDatabase.php @@ -2,13 +2,9 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; +use App\Console\BaseCommand; -use Symfony\Component\Process\Process; -use Symfony\Component\Process\Exception\ProcessFailedException; - - -class CreateDatabase extends Command +class CreateDatabase extends BaseCommand { protected $signature = 'database:create {--reset} {--conn=?}'; protected $description = 'Create a database'; @@ -20,21 +16,6 @@ class CreateDatabase extends Command $this->os = new \Tivie\OS\Detector(); } - protected function runCommand($cmd) - { - $cmd = join(' ', $cmd); - - $this->info('Running "' . $cmd . '"'); - - $proc = new Process($cmd); - $proc->run(); - if (!$proc->isSuccessful()) { - throw new ProcessFailedException($proc); - } - - echo $proc->getOutput(); - } - /** * create the mysql database * @param $dbkey diff --git a/app/Console/Commands/DevCommands.php b/app/Console/Commands/DevCommands.php new file mode 100644 index 00000000..a51d630c --- /dev/null +++ b/app/Console/Commands/DevCommands.php @@ -0,0 +1,69 @@ +argument('cmd')); + + if (!$command) { + $this->error('No command specified!'); + exit(); + } + + $commands = [ + 'clear-acars' => 'clearAcars', + 'compile-assets' => 'compileAssets', + ]; + + if(!array_key_exists($command, $commands)) { + $this->error('Command not found!'); + exit(); + } + + $this->{$commands[$command]}(); + } + + /** + * Delete all the data from the ACARS and PIREP tables + */ + protected function clearAcars() + { + if(config('database.default') === 'mysql') { + DB::statement('SET foreign_key_checks=0'); + } + + Acars::truncate(); + Pirep::truncate(); + + if (config('database.default') === 'mysql') { + DB::statement('SET foreign_key_checks=1'); + } + + $this->info('ACARS and PIREPs cleared!'); + } + + /** + * Compile all the CSS/JS assets into their respective files + * Calling the webpack compiler + */ + protected function compileAssets() + { + $this->runCommand('npm update'); + $this->runCommand('npm run dev'); + } +} diff --git a/app/Console/Commands/Install.php b/app/Console/Commands/Install.php index cb6b3457..414053d4 100644 --- a/app/Console/Commands/Install.php +++ b/app/Console/Commands/Install.php @@ -2,10 +2,9 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; +use App\Console\BaseCommand; - -class Install extends Command +class Install extends BaseCommand { protected $signature = 'phpvms:install {--update} diff --git a/app/Console/Commands/NavdataCommand.php b/app/Console/Commands/NavdataCommand.php index 1da0b8f5..23c61365 100644 --- a/app/Console/Commands/NavdataCommand.php +++ b/app/Console/Commands/NavdataCommand.php @@ -2,39 +2,16 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; -use League\Geotools\Coordinate\Coordinate; - +use App\Console\BaseCommand; use App\Models\Navdata; use App\Models\Enums\NavaidType; -class NavdataCommand extends Command +class NavdataCommand extends BaseCommand { protected $signature = 'phpvms:navdata'; protected $description = ''; - /** - * Streaming file read - * @param $filename - * @return \Generator - */ - protected function readFile($filename) - { - $fp = fopen($filename, 'rb'); - - while (($line = fgets($fp)) !== false) { - $line = rtrim($line, "\r\n"); - if($line[0] === ';') { - continue; - } - - yield $line; - } - - fclose($fp); - } - /** * Read and parse in the navaid file * @throws \League\Geotools\Exception\InvalidArgumentException diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 90dc7203..8da57da8 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -13,8 +13,11 @@ class Kernel extends ConsoleKernel * @var array */ protected $commands = [ + Commands\AcarsReplay::class, Commands\CreateDatabase::class, + Commands\DevCommands::class, Commands\Install::class, + Commands\NavdataCommand::class, ]; /**