Add flights to the importer, added a few missing columns with output
This commit is contained in:
@@ -2,23 +2,22 @@
|
|||||||
|
|
||||||
namespace App\Console\Services;
|
namespace App\Console\Services;
|
||||||
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use PDO;
|
use PDO;
|
||||||
use Hashids\Hashids;
|
|
||||||
use Doctrine\DBAL\Driver\PDOException;
|
use Doctrine\DBAL\Driver\PDOException;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
|
|
||||||
use App\Models\Aircraft;
|
use App\Models\Aircraft;
|
||||||
use App\Models\Airline;
|
use App\Models\Airline;
|
||||||
use App\Models\Airport;
|
use App\Models\Airport;
|
||||||
|
use App\Models\Flight;
|
||||||
use App\Models\Rank;
|
use App\Models\Rank;
|
||||||
use App\Models\Subfleet;
|
use App\Models\Subfleet;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Enums\UserState;
|
use App\Models\Enums\UserState;
|
||||||
use App\Facades\Utils;
|
use App\Facades\Utils;
|
||||||
use Illuminate\Support\Facades\Mail;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Importer
|
* Class Importer
|
||||||
@@ -53,7 +52,7 @@ class Importer
|
|||||||
* CONSTANTS
|
* CONSTANTS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const BATCH_READ_ROWS = 500;
|
const BATCH_READ_ROWS = 300;
|
||||||
const SUBFLEET_NAME = 'Imported Aircraft';
|
const SUBFLEET_NAME = 'Imported Aircraft';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -390,8 +389,8 @@ class Importer
|
|||||||
foreach ($this->readRows('airports') as $row)
|
foreach ($this->readRows('airports') as $row)
|
||||||
{
|
{
|
||||||
$attrs = [
|
$attrs = [
|
||||||
'id' => $row->icao,
|
'id' => trim($row->icao),
|
||||||
'icao' => $row->icao,
|
'icao' => trim($row->icao),
|
||||||
'name' => $row->name,
|
'name' => $row->name,
|
||||||
'country' => $row->country,
|
'country' => $row->country,
|
||||||
'lat' => $row->lat,
|
'lat' => $row->lat,
|
||||||
@@ -412,15 +411,41 @@ class Importer
|
|||||||
*/
|
*/
|
||||||
protected function importFlights()
|
protected function importFlights()
|
||||||
{
|
{
|
||||||
/*$this->comment('--- FLIGHT SCHEDULE IMPORT ---');
|
$this->comment('--- FLIGHT SCHEDULE IMPORT ---');
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
foreach ($this->readRows('schedules') as $row)
|
foreach ($this->readRows('schedules') as $row)
|
||||||
{
|
{
|
||||||
|
$airline_id = $this->getMapping('airlines', $row->code);
|
||||||
|
|
||||||
|
$attrs = [
|
||||||
|
'dpt_airport_id' => $row->depicao,
|
||||||
|
'arr_airport_id' => $row->arricao,
|
||||||
|
'route' => $row->route ?: '',
|
||||||
|
'distance' => round($row->distance ?: 0, 2),
|
||||||
|
'level' => $row->flightlevel ?: 0,
|
||||||
|
'dpt_time' => $row->deptime ?: '',
|
||||||
|
'arr_time' => $row->arrtime ?: '',
|
||||||
|
'flight_time' => $row->flighttime ?: '',
|
||||||
|
'notes' => $row->notes ?: '',
|
||||||
|
'active' => $row->enabled ?: true,
|
||||||
|
];
|
||||||
|
|
||||||
|
$flight = Flight::firstOrCreate(
|
||||||
|
['airline_id' => $airline_id, 'flight_number' => $row->flightnum],
|
||||||
|
$attrs
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->addMapping('flights', $row->id, $flight->id);
|
||||||
|
|
||||||
|
// TODO: deserialize route_details into ACARS table
|
||||||
|
|
||||||
|
if($flight->wasRecentlyCreated) {
|
||||||
|
++$count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info('Imported ' . $count . ' flights');*/
|
$this->info('Imported ' . $count . ' flights');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -473,6 +498,8 @@ class Importer
|
|||||||
$attrs
|
$attrs
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->addMapping('users', $row->pilotid, $user->id);
|
||||||
|
|
||||||
if ($user->wasRecentlyCreated) {
|
if ($user->wasRecentlyCreated) {
|
||||||
++$count;
|
++$count;
|
||||||
}
|
}
|
||||||
@@ -498,6 +525,8 @@ class Importer
|
|||||||
{
|
{
|
||||||
// TODO: This state might differ between simpilot and classic version
|
// TODO: This state might differ between simpilot and classic version
|
||||||
|
|
||||||
|
$state = (int) $state;
|
||||||
|
|
||||||
// Declare array of classic states
|
// Declare array of classic states
|
||||||
$phpvms_classic_states = [
|
$phpvms_classic_states = [
|
||||||
'ACTIVE' => 0,
|
'ACTIVE' => 0,
|
||||||
@@ -516,6 +545,8 @@ class Importer
|
|||||||
return UserState::SUSPENDED;
|
return UserState::SUSPENDED;
|
||||||
} elseif ($state === $phpvms_classic_states['ON_LEAVE']) {
|
} elseif ($state === $phpvms_classic_states['ON_LEAVE']) {
|
||||||
return UserState::ON_LEAVE;
|
return UserState::ON_LEAVE;
|
||||||
|
} else {
|
||||||
|
$this->error('Unknown status: '. $state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ class CreateFlightTables extends Migration
|
|||||||
$table->string('alt_airport_id', 5)->nullable();
|
$table->string('alt_airport_id', 5)->nullable();
|
||||||
$table->string('dpt_time', 10)->nullable();
|
$table->string('dpt_time', 10)->nullable();
|
||||||
$table->string('arr_time', 10)->nullable();
|
$table->string('arr_time', 10)->nullable();
|
||||||
|
$table->unsignedInteger('level')->default(0);
|
||||||
|
$table->unsignedDecimal('distance', 19)->default(0.0);
|
||||||
$table->unsignedDecimal('flight_time', 19)->nullable();
|
$table->unsignedDecimal('flight_time', 19)->nullable();
|
||||||
$table->text('route')->nullable();
|
$table->text('route')->nullable();
|
||||||
$table->text('notes')->nullable();
|
$table->text('notes')->nullable();
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ class Flight extends BaseModel
|
|||||||
'route',
|
'route',
|
||||||
'dpt_time',
|
'dpt_time',
|
||||||
'arr_time',
|
'arr_time',
|
||||||
|
'level',
|
||||||
|
'distance',
|
||||||
'notes',
|
'notes',
|
||||||
'has_bid',
|
'has_bid',
|
||||||
'active',
|
'active',
|
||||||
@@ -31,12 +33,8 @@ class Flight extends BaseModel
|
|||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'flight_number' => 'integer',
|
'flight_number' => 'integer',
|
||||||
'route_code' => 'string',
|
'level' => 'integer',
|
||||||
'route_leg' => 'string',
|
'distance' => 'float',
|
||||||
'route' => 'string',
|
|
||||||
'dpt_time' => 'string',
|
|
||||||
'arr_time' => 'string',
|
|
||||||
'notes' => 'string',
|
|
||||||
'has_bid' => 'boolean',
|
'has_bid' => 'boolean',
|
||||||
'active' => 'boolean',
|
'active' => 'boolean',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -55,16 +55,26 @@ SAME ROW
|
|||||||
|
|
||||||
<!-- Dpt Time Field -->
|
<!-- Dpt Time Field -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-3">
|
||||||
{!! Form::label('dpt_time', 'Departure Time:') !!}
|
{!! Form::label('dpt_time', 'Departure Time:') !!}
|
||||||
{!! Form::text('dpt_time', null, ['class' => 'form-control']) !!}
|
{!! Form::text('dpt_time', null, ['class' => 'form-control']) !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Arr Time Field -->
|
<!-- Arr Time Field -->
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-3">
|
||||||
{!! Form::label('arr_time', 'Arrival Time:') !!}
|
{!! Form::label('arr_time', 'Arrival Time:') !!}
|
||||||
{!! Form::text('arr_time', null, ['class' => 'form-control']) !!}
|
{!! Form::text('arr_time', null, ['class' => 'form-control']) !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group col-sm-3">
|
||||||
|
{!! Form::label('distance', 'Distance:') !!}
|
||||||
|
{!! Form::text('distance', null, ['class' => 'form-control']) !!}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group col-sm-3">
|
||||||
|
{!! Form::label('level', 'Flight Level:') !!}
|
||||||
|
{!! Form::text('level', null, ['class' => 'form-control']) !!}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
@@ -25,26 +25,27 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-5">
|
||||||
<div class="row">
|
<span class="title">DEP </span>
|
||||||
<div class="col-sm-6">
|
{!! $flight->dpt_airport->icao !!}@if($flight->dpt_time), {!! $flight->dpt_time !!}@endif
|
||||||
<span class="title">DEP </span>
|
<br />
|
||||||
{!! $flight->dpt_airport->icao !!}
|
<span class="title">ARR </span>
|
||||||
|
{!! $flight->arr_airport->icao !!}@if($flight->arr_time), {!! $flight->arr_time !!}@endif
|
||||||
<span class="title">ARR </span>
|
<br />
|
||||||
{!! $flight->arr_airport->icao !!}
|
@if($flight->distance)
|
||||||
</div>
|
<span class="title">DISTANCE </span>
|
||||||
<div class="col-sm-6 text-right">
|
{!! $flight->distance !!} {!! setting('general.distance_unit') !!}
|
||||||
|
@endif
|
||||||
<span class="description">{!! $flight->dpt_time !!}</span>
|
<br />
|
||||||
<span class="description">{!! $flight->arr_time !!}</span>
|
@if($flight->level)
|
||||||
</div>
|
<span class="title">LEVEL </span>
|
||||||
</div>
|
{!! $flight->level !!} {!! setting('general.altitude_unit') !!}
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-7">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<span class="description">ROUTE </span>
|
<span class="title">ROUTE </span>
|
||||||
{!! $flight->route !!}
|
{!! $flight->route !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user