Extra logging for cron and add flight visible field

This commit is contained in:
Nabeel Shahzad 2018-07-12 22:23:45 -05:00
parent f640381978
commit 4ca58ed754
6 changed files with 26 additions and 10 deletions

View File

@ -42,6 +42,7 @@ class PilotLeave extends Listener
->whereDate('updated_at', '<', $date);
foreach($users as $user) {
Log::info('Setting user '.$user->ident.' to ON LEAVE status');
$this->userSvc->setStatusOnLeave($user);
}
}

View File

@ -7,6 +7,8 @@ use App\Interfaces\Listener;
use App\Models\Enums\Days;
use App\Models\Flight;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Log;
/**
* Figure out what flights need to be active for today
@ -39,11 +41,19 @@ class SetActiveFlights extends Listener
*/
foreach($flights as $flight) {
if (!$flight->active) {
continue;
}
// dates aren't set, so just save if there were any changes above
// and move onto the next one
if ($flight->start_date === null || $flight->end_date === null) {
if ($flight->days > 0) {
$flight->active = Days::isToday($flight->days);
$visible = Days::isToday($flight->days);
if($flight->visible !== $visible) {
Log::info('Marking flight '.$flight->ident.' to '.($visible ? 'visible' : 'invisible'));
$flight->visible = $visible;
}
}
$flight->save();
@ -55,13 +65,17 @@ class SetActiveFlights extends Listener
// Start/end date is set, so make sure today is valid for it to be alive
// and then make sure if days of the week are specified, check that too
if ($today->gte($flight->start_date) && $today->lte($flight->end_date)) {
if ($flight->days > 0) {
$flight->active = Days::isToday($flight->days);
if ($flight->days === null || $flight->days > 0) {
$visible = Days::isToday($flight->days);
if($flight->visible !== $visible) {
Log::info('Toggling flight '.$flight->ident.' to '.($visible?'visible':'invisible'));
$flight->visible = true;
}
} else {
$flight->active = true;
$flight->visible = true;
}
} else {
$flight->active = false;
$flight->visible = false;
}
$flight->save();

View File

@ -16,12 +16,12 @@ class CreateAirportsTable extends Migration
$table->string('country', 64)->nullable();
$table->string('timezone', 64)->nullable();
$table->boolean('hub')->default(false);
$table->float('lat', 7, 4)->nullable()->default(0.0);
$table->float('lon', 7, 4)->nullable()->default(0.0);
$table->unsignedDecimal('ground_handling_cost')->nullable()->default(0);
$table->unsignedDecimal('fuel_100ll_cost')->nullable()->default(0);
$table->unsignedDecimal('fuel_jeta_cost')->nullable()->default(0);
$table->unsignedDecimal('fuel_mogas_cost')->nullable()->default(0);
$table->float('lat', 7, 4)->nullable()->default(0.0);
$table->float('lon', 7, 4)->nullable()->default(0.0);
$table->index('icao');
$table->index('iata');

View File

@ -36,7 +36,7 @@ class CreateFlightTables extends Migration
$table->date('end_date')->nullable();
$table->boolean('has_bid')->default(false);
$table->boolean('active')->default(true);
$table->boolean('flight_active')->default(true); // used by the cron
$table->boolean('visible')->default(true); // used by the cron
$table->timestamps();
$table->primary('id');

View File

@ -118,7 +118,6 @@ class AircraftController extends Controller
if (empty($aircraft)) {
Flash::error('Aircraft not found');
return redirect(route('admin.aircraft.index'));
}

View File

@ -64,6 +64,7 @@ class Flight extends Model
'end_date',
'has_bid',
'active',
'visible',
];
protected $casts = [
@ -75,8 +76,9 @@ class Flight extends Model
'start_date' => 'date',
'end_date' => 'date',
'has_bid' => 'boolean',
'route_leg' => 'integer',
'active' => 'boolean',
'route_leg' => 'integer'
'visible' => 'boolean',
];
public static $rules = [