Skip to content

Commit

Permalink
Add new command to export a specific PIREP for debugging (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio authored Jan 15, 2020
1 parent 7d07008 commit de80462
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions app/Console/Commands/PirepExport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Console\Commands;

use App\Contracts\Command;
use Illuminate\Support\Facades\DB;
use Symfony\Component\Yaml\Yaml;

class PirepExport extends Command
{
protected $signature = 'phpvms:pirep-export {id}';
protected $description = 'PIREP table export';

/**
* Run dev related commands
*/
public function handle()
{
$pirep_id = $this->argument('id');
if (empty($pirep_id)) {
$this->error('No PIREP ID specified');
exit();
}

// List the tables to export and the column name for the pirep id
$tables = [
'pireps' => 'id',
'acars' => 'pirep_id',
'pirep_comments' => 'pirep_id',
'pirep_fares' => 'pirep_id',
'pirep_field_values' => 'pirep_id',
'expenses' => 'ref_model_id',
'journal_transactions' => 'ref_model_id',
];

$export_tables = [];
foreach ($tables as $table => $key) {
$export_tables[$table] = [];

$rows = DB::table($table)
->where($key, '=', $pirep_id)
->get();

foreach ($rows as $row) {
$export_tables[$table][] = (array) $row;
}
}

$yaml = Yaml::dump($export_tables, 4, 2);
echo $yaml;
}
}

0 comments on commit de80462

Please sign in to comment.