Block aircraft with Simbrief (#1213)
* Block Aircraft with SimBrief Changes aim to have the ability to block an aircraft's usage if it is used to generate a SimBrief OFP. Unused/Expired briefings will be deleted by cron like before but will now be checked by HourlyCron, so admins can define more precise restrictions for them (and the blockage period of their aircraft) Owner of the SimBrief OFP will be able to start a flight with acars using that particular aircraft, but pilots will get an Aircraft Not Available error (similar to Aircraft State check) To prevent SimBrief OFP packs being marked as expired/unused, during pirep prefile, pirep_id will be saved to SimBrief model along with flight_id. And when a flight is finished (pirep file), flight_id will be removed from SimBrief model as before. Only pirep_id will remain and aircraft will be available for another OFP generation. * Update PirepController In case a pirep is being saved/submitted with manual entry (but the va is using simbrief effectively) same logic should be applied during save/submit button selection. Save will act like a pirep prefile , Submit will be pirep file. * Manual Pirep Checks Manual pireps, prefiled from a generated simbrief should be checked too. Also pirep.show blade's submit button should provide the same simbrief checks. * Update PirepService.php * Change settings and move sb cron to hourly * StyleFix (SimBriefService) * Another StyleFix (SimBriefService) * Update SimBriefController Removed null check of pirep_id for aircraft list generation to prevent live flights' aircraft being listed for another ofp generation. ( Active acars flights will have both flight_id and pirep_id at simbrief table) * Update PirepService.php Co-authored-by: Nabeel S <nabeelio@users.noreply.github.com>
This commit is contained in:
parent
ad86e996d7
commit
17447c6903
@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Cron\Nightly;
|
namespace App\Cron\Hourly;
|
||||||
|
|
||||||
use App\Contracts\Listener;
|
use App\Contracts\Listener;
|
||||||
use App\Events\CronNightly;
|
use App\Events\CronHourly;
|
||||||
use App\Services\SimBriefService;
|
use App\Services\SimBriefService;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
@ -22,9 +22,9 @@ class ClearExpiredSimbrief extends Listener
|
|||||||
/**
|
/**
|
||||||
* @param \App\Events\CronNightly $event
|
* @param \App\Events\CronNightly $event
|
||||||
*/
|
*/
|
||||||
public function handle(CronNightly $event): void
|
public function handle(CronHourly $event): void
|
||||||
{
|
{
|
||||||
Log::info('Nightly: Removing expired Simbrief entries');
|
Log::info('Hourly: Removing expired Simbrief entries');
|
||||||
$this->simbriefSvc->removeExpiredEntries();
|
$this->simbriefSvc->removeExpiredEntries();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class RemoveSettingSimbriefExpireDays extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
DB::table('settings')
|
||||||
|
->where(['key' => 'simbrief.expire_days'])
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
}
|
@ -207,13 +207,13 @@
|
|||||||
options: ''
|
options: ''
|
||||||
type: boolean
|
type: boolean
|
||||||
description: 'Only allow briefs to be created for bidded flights'
|
description: 'Only allow briefs to be created for bidded flights'
|
||||||
- key: simbrief.expire_days
|
- key: simbrief.expire_hours
|
||||||
name: 'Simbrief Expire Time'
|
name: 'Simbrief Expire Time'
|
||||||
group: simbrief
|
group: simbrief
|
||||||
value: 5
|
value: 6
|
||||||
options: ''
|
options: ''
|
||||||
type: number
|
type: number
|
||||||
description: 'Days after how long to remove unused briefs'
|
description: 'Hours after how long to remove unused briefs'
|
||||||
- key: simbrief.noncharter_pax_weight
|
- key: simbrief.noncharter_pax_weight
|
||||||
name: 'Non-Charter Passenger Weight'
|
name: 'Non-Charter Passenger Weight'
|
||||||
group: simbrief
|
group: simbrief
|
||||||
@ -256,6 +256,13 @@
|
|||||||
options: ''
|
options: ''
|
||||||
type: boolean
|
type: boolean
|
||||||
description: 'Use privatized user name as SimBrief OFP captain name'
|
description: 'Use privatized user name as SimBrief OFP captain name'
|
||||||
|
- key: simbrief.block_aircraft
|
||||||
|
name: 'Restrict Aircraft'
|
||||||
|
group: simbrief
|
||||||
|
value: false
|
||||||
|
options: ''
|
||||||
|
type: boolean
|
||||||
|
description: 'When enabled, an aircraft can only be used for one active SimBrief OFP and Flight/Pirep'
|
||||||
- key: pireps.duplicate_check_time
|
- key: pireps.duplicate_check_time
|
||||||
name: 'PIREP duplicate time check'
|
name: 'PIREP duplicate time check'
|
||||||
group: pireps
|
group: pireps
|
||||||
|
@ -399,9 +399,15 @@ class PirepController extends Controller
|
|||||||
if ($brief !== null) {
|
if ($brief !== null) {
|
||||||
/** @var SimBriefService $sbSvc */
|
/** @var SimBriefService $sbSvc */
|
||||||
$sbSvc = app(SimBriefService::class);
|
$sbSvc = app(SimBriefService::class);
|
||||||
|
// Keep the flight_id with SimBrief depending on the button selected
|
||||||
|
// Save = Keep the flight_id , Submit = Remove the flight_id
|
||||||
|
if ($attrs['submit'] === 'save') {
|
||||||
|
$sbSvc->attachSimbriefToPirep($pirep, $brief, true);
|
||||||
|
} elseif ($attrs['submit'] === 'submit') {
|
||||||
$sbSvc->attachSimbriefToPirep($pirep, $brief);
|
$sbSvc->attachSimbriefToPirep($pirep, $brief);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Depending on the button they selected, set an initial state
|
// Depending on the button they selected, set an initial state
|
||||||
// Can be saved as a draft or just submitted
|
// Can be saved as a draft or just submitted
|
||||||
|
@ -100,6 +100,13 @@ class SimBriefController
|
|||||||
$aircrafts = $aircrafts->where('airport_id', $flight->dpt_airport_id);
|
$aircrafts = $aircrafts->where('airport_id', $flight->dpt_airport_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (setting('simbrief.block_aircraft')) {
|
||||||
|
// Build a list of aircraft_id's being used for active sb packs
|
||||||
|
$sb_aircraft = SimBrief::whereNotNull('flight_id')->pluck('aircraft_id');
|
||||||
|
// Filter aircraft list to non used/blocked ones
|
||||||
|
$aircrafts = $aircrafts->whereNotIn('id', $sb_aircraft);
|
||||||
|
}
|
||||||
|
|
||||||
return view('flights.simbrief_aircraft', [
|
return view('flights.simbrief_aircraft', [
|
||||||
'flight' => $flight,
|
'flight' => $flight,
|
||||||
'aircrafts' => $aircrafts,
|
'aircrafts' => $aircrafts,
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Cron\Hourly\ClearExpiredSimbrief;
|
||||||
use App\Cron\Hourly\DeletePireps;
|
use App\Cron\Hourly\DeletePireps;
|
||||||
use App\Cron\Hourly\RemoveExpiredBids;
|
use App\Cron\Hourly\RemoveExpiredBids;
|
||||||
use App\Cron\Hourly\RemoveExpiredLiveFlights;
|
use App\Cron\Hourly\RemoveExpiredLiveFlights;
|
||||||
use App\Cron\Nightly\ApplyExpenses;
|
use App\Cron\Nightly\ApplyExpenses;
|
||||||
use App\Cron\Nightly\ClearExpiredSimbrief;
|
|
||||||
use App\Cron\Nightly\NewVersionCheck;
|
use App\Cron\Nightly\NewVersionCheck;
|
||||||
use App\Cron\Nightly\PilotLeave;
|
use App\Cron\Nightly\PilotLeave;
|
||||||
use App\Cron\Nightly\RecalculateBalances;
|
use App\Cron\Nightly\RecalculateBalances;
|
||||||
@ -31,7 +31,6 @@ class CronServiceProvider extends ServiceProvider
|
|||||||
SetActiveFlights::class,
|
SetActiveFlights::class,
|
||||||
RecalculateStats::class,
|
RecalculateStats::class,
|
||||||
NewVersionCheck::class,
|
NewVersionCheck::class,
|
||||||
ClearExpiredSimbrief::class,
|
|
||||||
],
|
],
|
||||||
|
|
||||||
CronWeekly::class => [
|
CronWeekly::class => [
|
||||||
@ -45,6 +44,7 @@ class CronServiceProvider extends ServiceProvider
|
|||||||
DeletePireps::class,
|
DeletePireps::class,
|
||||||
RemoveExpiredBids::class,
|
RemoveExpiredBids::class,
|
||||||
RemoveExpiredLiveFlights::class,
|
RemoveExpiredLiveFlights::class,
|
||||||
|
ClearExpiredSimbrief::class,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -148,6 +148,18 @@ class PirepService extends Service
|
|||||||
throw new AircraftNotAvailable($pirep->aircraft);
|
throw new AircraftNotAvailable($pirep->aircraft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See if this aircraft is being used by another user's active simbrief ofp
|
||||||
|
if (setting('simbrief.block_aircraft', false)) {
|
||||||
|
$sb_aircraft = SimBrief::select('aircraft_id')
|
||||||
|
->where('aircraft_id', $pirep->aircraft_id)
|
||||||
|
->where('user_id', '!=', $pirep->user_id)
|
||||||
|
->whereNotNull('flight_id')
|
||||||
|
->count();
|
||||||
|
if ($sb_aircraft > 0) {
|
||||||
|
throw new AircraftNotAvailable($pirep->aircraft);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// See if this aircraft is at the departure airport
|
// See if this aircraft is at the departure airport
|
||||||
/* @noinspection NotOptimalIfConditionsInspection */
|
/* @noinspection NotOptimalIfConditionsInspection */
|
||||||
if (setting('pireps.only_aircraft_at_dpt_airport') && $aircraft->airport_id !== $pirep->dpt_airport_id) {
|
if (setting('pireps.only_aircraft_at_dpt_airport') && $aircraft->airport_id !== $pirep->dpt_airport_id) {
|
||||||
@ -164,9 +176,20 @@ class PirepService extends Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event(new PirepPrefiled($pirep));
|
|
||||||
|
|
||||||
$pirep->save();
|
$pirep->save();
|
||||||
|
$pirep->refresh();
|
||||||
|
|
||||||
|
// Check if there is a simbrief_id, update it to have the pirep_id
|
||||||
|
// Keep the flight_id until the end of flight (pirep file)
|
||||||
|
if (array_key_exists('simbrief_id', $attrs)) {
|
||||||
|
/** @var SimBrief $simbrief */
|
||||||
|
$simbrief = SimBrief::find($attrs['simbrief_id']);
|
||||||
|
if ($simbrief) {
|
||||||
|
$this->simBriefSvc->attachSimbriefToPirep($pirep, $simbrief, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event(new PirepPrefiled($pirep));
|
||||||
|
|
||||||
return $pirep;
|
return $pirep;
|
||||||
}
|
}
|
||||||
@ -427,6 +450,19 @@ class PirepService extends Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if there is a simbrief_id, change it to be set to the PIREP
|
||||||
|
// at the end of the flight when it's been submitted finally.
|
||||||
|
// Prefile, Save (as draft) and File already have this but the Submit button
|
||||||
|
// visible at pireps.show blade uses this function so Simbrief also needs to
|
||||||
|
// checked here too (to remove the flight_id and release the aircraft)
|
||||||
|
if (!empty($pirep->simbrief)) {
|
||||||
|
/** @var SimBrief $simbrief */
|
||||||
|
$simbrief = SimBrief::find($pirep->simbrief->id);
|
||||||
|
if ($simbrief) {
|
||||||
|
$this->simBriefSvc->attachSimbriefToPirep($pirep, $simbrief);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Log::info('New PIREP filed', [$pirep]);
|
Log::info('New PIREP filed', [$pirep]);
|
||||||
event(new PirepFiled($pirep));
|
event(new PirepFiled($pirep));
|
||||||
|
|
||||||
|
@ -132,21 +132,23 @@ class SimBriefService extends Service
|
|||||||
*
|
*
|
||||||
* 1. Read from the XML the basic PIREP info (dep, arr), and then associate the PIREP
|
* 1. Read from the XML the basic PIREP info (dep, arr), and then associate the PIREP
|
||||||
* to the flight ID
|
* to the flight ID
|
||||||
* 2. Remove the flight ID from the SimBrief field and assign the pirep_id to the row
|
* 2. Remove the flight ID from the SimBrief model and assign the pirep ID to the row
|
||||||
|
* at the end of the flight. Keep flight ID until the flight ends (pirep file).
|
||||||
* 3. Update the planned flight route in the acars table
|
* 3. Update the planned flight route in the acars table
|
||||||
* 4. Add additional flight fields (ones which match ACARS)
|
* 4. Add additional flight fields (ones which match ACARS)
|
||||||
*
|
*
|
||||||
* @param $pirep
|
* @param $pirep
|
||||||
* @param SimBrief $simBrief The briefing to create the PIREP from
|
* @param SimBrief $simBrief The briefing to create the PIREP from
|
||||||
|
* @param bool $keep_flight True keeps the flight_id, default is false
|
||||||
*
|
*
|
||||||
* @return \App\Models\Pirep
|
* @return \App\Models\Pirep
|
||||||
*/
|
*/
|
||||||
public function attachSimbriefToPirep($pirep, SimBrief $simBrief): Pirep
|
public function attachSimbriefToPirep($pirep, SimBrief $simBrief, $keep_flight = false): Pirep
|
||||||
{
|
{
|
||||||
$this->addRouteToPirep($pirep, $simBrief);
|
$this->addRouteToPirep($pirep, $simBrief);
|
||||||
|
|
||||||
$simBrief->pirep_id = $pirep->id;
|
$simBrief->pirep_id = $pirep->id;
|
||||||
$simBrief->flight_id = null;
|
$simBrief->flight_id = !empty($keep_flight) ? $pirep->flight_id : null;
|
||||||
$simBrief->save();
|
$simBrief->save();
|
||||||
|
|
||||||
return $pirep;
|
return $pirep;
|
||||||
@ -185,14 +187,14 @@ class SimBriefService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove any expired entries from the SimBrief table. Expired means there's
|
* Remove any expired entries from the SimBrief table.
|
||||||
* a flight_id attached to it, but no pirep_id (meaning it was never used for
|
* Expired means there's a flight_id attached to it, but no pirep_id
|
||||||
* an actual flight)
|
* (meaning it was never used for an actual flight)
|
||||||
*/
|
*/
|
||||||
public function removeExpiredEntries(): void
|
public function removeExpiredEntries(): void
|
||||||
{
|
{
|
||||||
$expire_days = setting('simbrief.expire_days', 5);
|
$expire_hours = setting('simbrief.expire_hours', 6);
|
||||||
$expire_time = Carbon::now('UTC')->subDays($expire_days);
|
$expire_time = Carbon::now('UTC')->subHours($expire_hours);
|
||||||
|
|
||||||
$briefs = SimBrief::where([
|
$briefs = SimBrief::where([
|
||||||
['pirep_id', null],
|
['pirep_id', null],
|
||||||
@ -202,7 +204,7 @@ class SimBriefService extends Service
|
|||||||
foreach ($briefs as $brief) {
|
foreach ($briefs as $brief) {
|
||||||
$brief->delete();
|
$brief->delete();
|
||||||
|
|
||||||
// TODO: Delete any assets
|
// TODO: Delete any assets (Which assets ?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user