Cleanup of some console commands
This commit is contained in:
parent
a5c5518a12
commit
5ec99167e8
51
app/Console/BaseCommand.php
Normal file
51
app/Console/BaseCommand.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
|
class BaseCommand extends Command
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Streaming file read
|
||||||
|
* @param $filename
|
||||||
|
* @return \Generator
|
||||||
|
*/
|
||||||
|
public 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $cmd
|
||||||
|
*/
|
||||||
|
public function runCommand($cmd)
|
||||||
|
{
|
||||||
|
if (is_array($cmd))
|
||||||
|
$cmd = join(' ', $cmd);
|
||||||
|
|
||||||
|
$this->info('Running "' . $cmd . '"');
|
||||||
|
|
||||||
|
$process = new Process($cmd);
|
||||||
|
$process->run(function ($type, $buffer) {
|
||||||
|
if (Process::ERR === $type) {
|
||||||
|
echo $buffer;
|
||||||
|
} else {
|
||||||
|
echo $buffer;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -2,14 +2,13 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
|
||||||
|
use App\Console\BaseCommand;
|
||||||
use App\Facades\Utils;
|
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 $signature = 'phpvms:replay {files} {--manual} {--write-all} {--no-submit}';
|
||||||
protected $description = 'Replay an ACARS file';
|
protected $description = 'Replay an ACARS file';
|
||||||
|
@ -2,13 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use App\Console\BaseCommand;
|
||||||
|
|
||||||
use Symfony\Component\Process\Process;
|
class CreateDatabase extends BaseCommand
|
||||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
|
||||||
|
|
||||||
|
|
||||||
class CreateDatabase extends Command
|
|
||||||
{
|
{
|
||||||
protected $signature = 'database:create {--reset} {--conn=?}';
|
protected $signature = 'database:create {--reset} {--conn=?}';
|
||||||
protected $description = 'Create a database';
|
protected $description = 'Create a database';
|
||||||
@ -20,21 +16,6 @@ class CreateDatabase extends Command
|
|||||||
$this->os = new \Tivie\OS\Detector();
|
$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
|
* create the mysql database
|
||||||
* @param $dbkey
|
* @param $dbkey
|
||||||
|
69
app/Console/Commands/DevCommands.php
Normal file
69
app/Console/Commands/DevCommands.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use DB;
|
||||||
|
|
||||||
|
use App\Console\BaseCommand;
|
||||||
|
use App\Models\Acars;
|
||||||
|
use App\Models\Pirep;
|
||||||
|
|
||||||
|
class DevCommands extends BaseCommand
|
||||||
|
{
|
||||||
|
protected $signature = 'phpvms:dev {cmd}';
|
||||||
|
protected $description = 'Developer commands';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run dev related commands
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$command = trim($this->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');
|
||||||
|
}
|
||||||
|
}
|
@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use App\Console\BaseCommand;
|
||||||
|
|
||||||
|
class Install extends BaseCommand
|
||||||
class Install extends Command
|
|
||||||
{
|
{
|
||||||
protected $signature = 'phpvms:install
|
protected $signature = 'phpvms:install
|
||||||
{--update}
|
{--update}
|
||||||
|
@ -2,39 +2,16 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use App\Console\BaseCommand;
|
||||||
use League\Geotools\Coordinate\Coordinate;
|
|
||||||
|
|
||||||
use App\Models\Navdata;
|
use App\Models\Navdata;
|
||||||
use App\Models\Enums\NavaidType;
|
use App\Models\Enums\NavaidType;
|
||||||
|
|
||||||
|
|
||||||
class NavdataCommand extends Command
|
class NavdataCommand extends BaseCommand
|
||||||
{
|
{
|
||||||
protected $signature = 'phpvms:navdata';
|
protected $signature = 'phpvms:navdata';
|
||||||
protected $description = '';
|
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
|
* Read and parse in the navaid file
|
||||||
* @throws \League\Geotools\Exception\InvalidArgumentException
|
* @throws \League\Geotools\Exception\InvalidArgumentException
|
||||||
|
@ -13,8 +13,11 @@ class Kernel extends ConsoleKernel
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $commands = [
|
protected $commands = [
|
||||||
|
Commands\AcarsReplay::class,
|
||||||
Commands\CreateDatabase::class,
|
Commands\CreateDatabase::class,
|
||||||
|
Commands\DevCommands::class,
|
||||||
Commands\Install::class,
|
Commands\Install::class,
|
||||||
|
Commands\NavdataCommand::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user