Compare commits

..

1 Commits

Author SHA1 Message Date
Nabeel Shahzad
e2bcd72e39 Flight history #807 2020-09-08 09:29:46 -04:00
237 changed files with 6967 additions and 33875 deletions

View File

@@ -1,10 +1,6 @@
#
root = true
[*]
end_of_line = lf
insert_final_newline = true
[*.js]
indent_style = space
indent_size = 2
@@ -27,4 +23,4 @@ indent_style = tab
# Matches the exact files either package.json or .travis.yml
[{package.json, .travis.yml}]
indent_style = space
indent_size = 2
indent_size = 2

View File

@@ -92,9 +92,8 @@ class CreateDatabase extends Command
}
if ($this->option('reset') === true) {
if (file_exists($dbPath)) {
unlink(config($dbkey.'database'));
}
$cmd = ['rm', '-rf', config($dbkey.'database')];
$this->runCommand($cmd);
}
if (!file_exists($dbPath)) {

View File

@@ -3,7 +3,7 @@
namespace App\Console\Commands;
use App\Contracts\Command;
use Illuminate\Support\Facades\DB;
use DB;
use Symfony\Component\Yaml\Yaml;
/**
@@ -25,20 +25,6 @@ class YamlExport extends Command
exit();
}
// A "preset" for exporting the base set of data
if ($tables[0] === 'base') {
$tables = [
'airlines',
'aircraft',
'subfleets',
'subfleet_fare',
'subfleet_rank',
'bids',
'fares',
'flights',
];
}
$export_tables = [];
foreach ($tables as $table) {
$export_tables[$table] = [];

View File

@@ -36,10 +36,7 @@ abstract class Award
* You don't really need to mess with anything below here
*/
/** @var \App\Models\Award|null */
protected $award;
/** @var \App\Models\User|null */
protected $user;
public function __construct(AwardModel $award = null, User $user = null)

View File

@@ -3,9 +3,9 @@
namespace App\Contracts;
use App\Models\Airline;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use Log;
use Validator;
/**
* Common functionality used across all of the importers
@@ -51,9 +51,9 @@ class ImportExport
*
* @param $code
*
* @return Airline
* @return \Illuminate\Database\Eloquent\Model
*/
public function getAirline($code): Airline
public function getAirline($code)
{
$airline = Airline::firstOrCreate([
'icao' => $code,

View File

@@ -2,13 +2,9 @@
namespace App\Contracts;
use App\Models\Module;
use App\Support\Database;
use Exception;
use Illuminate\Support\Facades\DB;
use DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
/**
* Class Migration
@@ -29,29 +25,6 @@ abstract class Migration extends \Illuminate\Database\Migrations\Migration
{
}
/**
* Add a module and enable it
*
* @param array $attrs
*/
public function addModule(array $attrs)
{
$module = array_merge([
'enabled' => true,
'created_at' => DB::raw('NOW()'),
'updated_at' => DB::raw('NOW()'),
], $attrs);
try {
DB::table('modules')->insert($module);
} catch (Exception $e) {
// setting already exists, just ignore it
if ($e->getCode() === 23000) {
return;
}
}
}
/**
* Seed a YAML file into the database
*
@@ -62,7 +35,7 @@ abstract class Migration extends \Illuminate\Database\Migrations\Migration
try {
$path = base_path($file);
Database::seed_from_yaml_file($path, false);
} catch (Exception $e) {
} catch (\Exception $e) {
Log::error('Unable to load '.$file.' file');
Log::error($e);
}
@@ -79,7 +52,7 @@ abstract class Migration extends \Illuminate\Database\Migrations\Migration
foreach ($rows as $row) {
try {
DB::table($table)->insert($row);
} catch (Exception $e) {
} catch (\Exception $e) {
// setting already exists, just ignore it
if ($e->getCode() === 23000) {
continue;
@@ -87,22 +60,4 @@ abstract class Migration extends \Illuminate\Database\Migrations\Migration
}
}
}
/**
* Add an award from the migrations (for example, if you're adding an award module)
*
* @param array $award See \App\Models\Awardv
*
* @throws \Illuminate\Validation\ValidationException
*/
public function addAward(array $award)
{
$validator = Validator::make($award, \App\Models\Award::$rules);
if ($validator->fails()) {
throw new ValidationException($validator);
}
$awardModel = new \App\Models\Award($award);
$awardModel->save();
}
}

View File

@@ -1,49 +0,0 @@
<?php
namespace App\Contracts\Modules;
/**
* Base class for module service providers
* Add-on module service providers must extend this class. Docs on Service Providers:
* https://laravel.com/docs/7.x/providers
*
* For a sample service provider, view the sample module one:
* https://github.com/nabeelio/phpvms-module/blob/master/Providers/SampleServiceProvider.php
*/
abstract class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
/**
* A boot method is required, even if it doesn't do anything.
* https://laravel.com/docs/7.x/providers#the-boot-method
*
* This is normally where you'd register the routes or other startup tasks for your module
*/
public function boot(): void
{
}
/**
* This is required to register the links in either the public or admin toolbar
* For example, adding a frontend link:
*
* $this->moduleSvc->addFrontendLink('Sample', '/sample', '', $logged_in=true);
*
* Or an admin link:
*
* $this->moduleSvc->addAdminLink('Sample', '/admin/sample');
*/
public function registerLinks(): void
{
}
/**
* Deferred providers:
* https://laravel.com/docs/7.x/providers#deferred-providers
*
* @return array
*/
public function provides(): array
{
return [];
}
}

View File

@@ -6,7 +6,8 @@ use Illuminate\Validation\Validator;
use Prettus\Repository\Eloquent\BaseRepository;
/**
* @mixin \Prettus\Repository\Eloquent\BaseRepository
* @mixin Model
* @mixin BaseRepository
*/
abstract class Repository extends BaseRepository
{

View File

@@ -3,15 +3,12 @@
use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Modules\Awards\Awards\PilotFlightAwards;
class CreateAwardsTable extends Migration
{
/**
* Run the migrations.
*
* @throws \Illuminate\Validation\ValidationException
*
* @return void
*/
public function up()
@@ -26,6 +23,7 @@ class CreateAwardsTable extends Migration
// EG, the airports has an internal expense for gate costs
$table->string('ref_model')->nullable();
$table->text('ref_model_params')->nullable();
//$table->string('ref_model_id', 36)->nullable();
$table->timestamps();
@@ -40,18 +38,6 @@ class CreateAwardsTable extends Migration
$table->index(['user_id', 'award_id']);
});
/**
* Add a default, sample award
*/
$award = [
'name' => 'Pilot 50 flights',
'description' => 'When a pilot has 50 flights, give this award',
'ref_model' => PilotFlightAwards::class,
'ref_model_params' => 50,
];
$this->addAward($award);
}
/**

View File

@@ -1,39 +0,0 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateModulesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('modules', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->boolean('enabled')->default(1);
$table->timestamps();
});
$this->addModule(['name' => 'Awards']);
$this->addModule(['name' => 'Sample']);
$this->addModule(['name' => 'VMSAcars']);
$this->addModule(['name' => 'Vacentral']);
$this->addModule(['name' => 'TestModule']);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('modules');
}
}

View File

@@ -1,52 +0,0 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class ModifyPirepFares extends Migration
{
/**
* Modify the PIREP fares table so that we can save all of the fares for that particular PIREP
* Basically copy all of those fields over, and then use this table directly, instead of the
* relationship to the fares table
*
* @return void
*/
public function up()
{
/*
* Add the columns we need from the fares table so then this is now "fixed" in time
*/
Schema::table('pirep_fares', function (Blueprint $table) {
$table->unsignedInteger('fare_id')->change()->nullable()->default(0);
$table->string('code', 50);
$table->string('name', 50);
// count is already there
$table->unsignedDecimal('price')->nullable()->default(0.00);
$table->unsignedDecimal('cost')->nullable()->default(0.00);
$table->unsignedInteger('capacity')->nullable()->default(0);
});
/**
* Now iterate through the existing table and copy/update everything
* Some fares might already have been removed deleted so just insert some null/errored
* values for those
*/
$parent_fares = [];
$fares = DB::table('pirep_fares')->get();
foreach ($fares as $fare) {
if (empty($parent_fares[$fare->fare_id])) {
$parent_fares[$fare->fare_id] = DB::table('fares')->where('id', $fare->fare_id)->first();
}
}
}
public function down()
{
}
}

View File

@@ -1,21 +1,15 @@
<?php
use App\Services\Installer\MigrationService;
use App\Services\Installer\SeederService;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/** @var MigrationService */
private $migrationSvc;
/** @var SeederService */
private $seederSvc;
private $seederService;
public function __construct()
{
$this->migrationSvc = app(MigrationService::class);
$this->seederSvc = app(SeederService::class);
$this->seederService = app(SeederService::class);
}
/**
@@ -25,12 +19,6 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
// Make sure any migrations that need to be run are run/cleared out
if ($this->migrationSvc->migrationsAvailable()) {
$this->migrationSvc->runAllMigrations();
}
// Then sync all of the seeds
$this->seederSvc->syncAllSeeds();
$this->seederService->syncAllSeeds();
}
}

View File

@@ -1,2 +1 @@
local.yml
vmsacars.yml

View File

@@ -1,10 +1,30 @@
#airlines:
# - id: 1
# icao: VMS
# iata: VM
# name: phpvms airlines
# country: us
# active: 1
# created_at: now
# updated_at: now
roles:
id_column: name
data:
- name: fleet-only
display_name: Edit Fleet
awards:
- id: 1
name: Pilot 50 flights
description: When a pilot has 50 flights, give this award
image_url:
ref_model: Modules\Awards\Awards\PilotFlightAwards
ref_model_params: 50
created_at: now
updated_at: now
news:
- id: 1
user_id: 1
@@ -116,91 +136,34 @@ airports:
ground_handling_cost: 50
#
aircraft:
-
id: 1
- id: 1
subfleet_id: 1
icao: null
iata: null
airport_id: KJFK
landing_time: '2020-10-23 07:50:16'
name: 'Boeing 747-438'
name: Boeing 747-438
registration: 001Z
hex_code: null
mtow: '0.00'
zfw: '0.00'
flight_time: 540
flight_time: 360
status: A
state: 0
created_at: null
updated_at: '2020-10-23 07:50:16'
-
id: 2
- id: 2
subfleet_id: 2
icao: null
iata: null
airport_id: LGRP
landing_time: null
name: 'Boeing 777-200'
name: Boeing 777-200
registration: C202
hex_code: null
mtow: '0.00'
zfw: '0.00'
flight_time: 260
status: A
state: 0
created_at: null
updated_at: null
-
id: 3
- id: 3
subfleet_id: 1
icao: null
iata: null
airport_id: KAUS
landing_time: '2020-10-24 08:50:13'
name: 'Boeing 747-412'
name: Boeing 747-412
registration: S2333
hex_code: null
mtow: '0.00'
zfw: '0.00'
flight_time: 180
status: A
state: 0
created_at: null
updated_at: '2020-10-24 08:50:13'
-
id: 4
subfleet_id: 1
icao: null
iata: null
airport_id: KAUS
landing_time: null
name: 'Boeing 747-436 RETIRED'
registration: null
hex_code: null
mtow: '0.00'
zfw: '0.00'
flight_time: 45
status: R
state: 0
created_at: null
updated_at: null
-
id: 5
subfleet_id: 4
icao: A320
iata: '320'
airport_id: EGLL
landing_time: null
name: 'Airbus A320'
registration: N786DL
hex_code: b47165dd
mtow: '78800.00'
zfw: '62500.00'
flight_time: 0
status: A
state: 0
created_at: '2020-10-22 13:38:50'
updated_at: '2020-10-22 13:38:50'
- id: 4
subfleet_id: 1
airport_id: KAUS
name: Boeing 747-436 RETIRED
registration:
flight_time: 45
status: R
expenses:
- name: Per-Flight (no muliplier)
@@ -257,192 +220,68 @@ expenses:
updated_at: now
fares:
-
id: 1
code: 'Y'
- id: 1
code: Y
name: Economy
price: '100.00'
cost: '0.00'
price: 100
capacity: 200
type: 0
notes: null
active: 1
created_at: null
updated_at: null
-
id: 2
- id: 2
code: B
name: Business
price: '500.00'
cost: '0.00'
price: 500
capacity: 10
type: 0
notes: null
active: 1
created_at: null
updated_at: null
-
id: 3
- id: 3
code: F
name: First-Class
price: '800.00'
cost: '0.00'
price: 800
capacity: 5
type: 0
notes: null
active: 1
created_at: null
updated_at: null
subfleets:
-
id: 1
- id: 1
airline_id: 1
name: 747-43X RB211-524G
type: 744-3X-RB211
name: '747-43X RB211-524G'
cost_block_hour: '1000.00'
cost_delay_minute: '0.00'
fuel_type: null
ground_handling_multiplier: '200.00'
cargo_capacity: null
fuel_capacity: null
gross_weight: null
created_at: null
updated_at: null
-
id: 2
cost_block_hour: 1000
ground_handling_multiplier: 200
- id: 2
airline_id: 1
name: 777-222ER GE90-76B
type: 772-22ER-GE90-76B
name: '777-222ER GE90-76B'
cost_block_hour: '500.00'
cost_delay_minute: '0.00'
fuel_type: null
ground_handling_multiplier: '150.00'
cargo_capacity: null
fuel_capacity: null
gross_weight: null
created_at: null
updated_at: null
-
id: 3
cost_block_hour: 500
ground_handling_multiplier: 150
- id: 3
airline_id: 1
name: 777-367 ER GE90-115B
type: 772-36ER-GE90-115B
name: '777-367 ER GE90-115B'
cost_block_hour: '100.00'
cost_delay_minute: '0.00'
fuel_type: null
ground_handling_multiplier: '150.00'
cargo_capacity: null
fuel_capacity: null
gross_weight: null
created_at: null
updated_at: null
-
id: 4
airline_id: 1
type: A320
name: A320
cost_block_hour: '2300.00'
cost_delay_minute: null
fuel_type: 1
ground_handling_multiplier: '100.00'
cargo_capacity: null
fuel_capacity: null
gross_weight: null
created_at: '2020-10-22 13:36:49'
updated_at: '2020-10-22 13:36:49'
cost_block_hour: 100
ground_handling_multiplier: 150
# add a few mods to aircraft and fares
subfleet_fare:
-
subfleet_id: 1
# Fare classes on the 747
- subfleet_id: 1
fare_id: 1
price: '200'
cost: null
capacity: '400'
created_at: null
updated_at: null
-
subfleet_id: 1
price: 200
capacity: 400
- subfleet_id: 1
fare_id: 2
price: 120%
cost: null
capacity: null
created_at: null
updated_at: null
-
subfleet_id: 1
- subfleet_id: 1
fare_id: 3
price: '1000'
cost: null
price: 1000
capacity: 110%
created_at: null
updated_at: null
-
subfleet_id: 2
# Fare classes on the 777
- subfleet_id: 2
fare_id: 1
price: null
cost: null
capacity: null
created_at: null
updated_at: null
-
subfleet_id: 2
- subfleet_id: 2
fare_id: 3
price: null
cost: null
capacity: '10'
created_at: null
updated_at: null
-
subfleet_id: 4
fare_id: 1
price: null
cost: null
capacity: '123'
created_at: null
updated_at: null
-
subfleet_id: 4
fare_id: 2
price: null
cost: null
capacity: '8'
created_at: null
updated_at: null
-
subfleet_id: 4
fare_id: 3
price: null
cost: null
capacity: '2'
created_at: null
updated_at: null
capacity: 10
subfleet_rank:
-
rank_id: 1
- rank_id: 1
subfleet_id: 1
acars_pay: null
manual_pay: null
-
rank_id: 1
subfleet_id: 4
acars_pay: null
manual_pay: null
-
rank_id: 2
subfleet_id: 4
acars_pay: null
manual_pay: null
-
rank_id: 3
subfleet_id: 4
acars_pay: null
manual_pay: null
-
rank_id: 4
subfleet_id: 4
acars_pay: null
manual_pay: null
flights:
- id: flightid_1
@@ -520,35 +359,6 @@ flights:
route: 'MLY5 KEMBO UG442 SIA UG633 OTEKO UR640 NALRO GUBEL3'
created_at: NOW
updated_at: NOW
-
id: q8mvZ5vdExoy0mQG
airline_id: 1
flight_number: 3003
route_code: null
route_leg: null
dpt_airport_id: KSEA
arr_airport_id: KPAE
alt_airport_id: null
dpt_time: '8:00'
arr_time: '8:45'
level: null
distance: '27.51'
flight_time: 45
flight_type: J
load_factor: null
load_factor_variance: null
route: null
pilot_pay: null
notes: null
scheduled: 0
days: null
start_date: null
end_date: null
has_bid: 1
active: 1
visible: 1
created_at: now
updated_at: now
flight_fields:
- name: Departure Terminal
@@ -579,24 +389,12 @@ flight_subfleet:
flight_id: flightid_4
bids:
-
id: 100
- id: 100
user_id: 1
flight_id: flightid_1
created_at: now
updated_at: now
-
id: 101
- id: 101
user_id: 1
flight_id: flightid_3
created_at: now
updated_at: now
-
id: 102
user_id: 1
flight_id: q8mvZ5vdExoy0mQG
created_at: now
updated_at: now
pireps:
- id: pirepid_1

View File

@@ -92,10 +92,3 @@ user_field_values:
user_field_id: 2
user_id: 1
value: 'Nobody did'
user_awards:
- id: 1
user_id: 1
award_id: 1
created_at: now
updated_at: now

View File

@@ -1,10 +0,0 @@
- name: 'Awards'
enabled: 1
- name: 'Sample'
enabled: 1
- name: 'VMSAcars'
enabled: 1
- name: 'Vacentral'
enabled: 1
- name: 'TestModule'
enabled: 1

View File

@@ -51,6 +51,3 @@
- name: maintenance
display_name: Maintenance
description: Run maintenance tasks
- name: modules
display_name: Modules
description: Add/Edit Modules

View File

@@ -130,20 +130,6 @@
options: ''
type: int
description: 'Initial zoom level on the map'
- key: airports.default_ground_handling_cost
name: 'Default Ground Handling Cost'
group: airports
value: 250
options:
type: int
description: If an airport's Ground Handling Cost Cost isn't added, set this value by default
- key: airports.default_jet_a_fuel_cost
name: 'Default Jet A Fuel Cost'
group: airports
value: 0.7
options:
type: text
description: If an airport's Jet A Fuel Cost isn't added, set this value by default
- key: bids.disable_flight_on_bid
name: 'Disable flight on bid'
group: bids

View File

@@ -1,41 +0,0 @@
<?php
namespace App\Exceptions;
class ModuleExistsException extends AbstractHttpException
{
private $module_name;
public function __construct($module_name)
{
$this->module_name = $module_name;
parent::__construct(
409,
'Module '.$module_name.' Already Exists!'
);
}
/**
* Return the RFC 7807 error type (without the URL root)
*/
public function getErrorType(): string
{
return 'module-already-exists';
}
/**
* Get the detailed error string
*/
public function getErrorDetails(): string
{
return $this->getMessage();
}
/**
* Return an array with the error details, merged with the RFC7807 response
*/
public function getErrorMetadata(): array
{
return [];
}
}

View File

@@ -1,38 +0,0 @@
<?php
namespace App\Exceptions;
class ModuleInstallationError extends AbstractHttpException
{
public function __construct()
{
parent::__construct(
500,
'Installation of Module Failed!'
);
}
/**
* Return the RFC 7807 error type (without the URL root)
*/
public function getErrorType(): string
{
return 'module-installation-error';
}
/**
* Get the detailed error string
*/
public function getErrorDetails(): string
{
return $this->getMessage();
}
/**
* Return an array with the error details, merged with the RFC7807 response
*/
public function getErrorMetadata(): array
{
return [];
}
}

View File

@@ -1,38 +0,0 @@
<?php
namespace App\Exceptions;
class ModuleInvalidFileType extends AbstractHttpException
{
public function __construct()
{
parent::__construct(
415,
'The Module File Type is Invalid!'
);
}
/**
* Return the RFC 7807 error type (without the URL root)
*/
public function getErrorType(): string
{
return 'module-file-type-invalid';
}
/**
* Get the detailed error string
*/
public function getErrorDetails(): string
{
return $this->getMessage();
}
/**
* Return an array with the error details, merged with the RFC7807 response
*/
public function getErrorMetadata(): array
{
return [];
}
}

View File

@@ -12,7 +12,6 @@ use App\Repositories\FareRepository;
use App\Services\ExportService;
use App\Services\ImportService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Laracasts\Flash\Flash;
use Prettus\Repository\Criteria\RequestCriteria;
@@ -163,8 +162,6 @@ class FareController extends Controller
return redirect(route('admin.fares.index'));
}
Log::info('Deleting fare "'.$fare->name.'", id='.$fare->id);
$this->fareRepo->delete($id);
Flash::success('Fare deleted successfully.');

View File

@@ -1,122 +0,0 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Contracts\Controller;
use App\Services\ModuleService;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Illuminate\View\View;
class ModulesController extends Controller
{
private $moduleSvc;
public function __construct(ModuleService $moduleSvc)
{
$this->moduleSvc = $moduleSvc;
}
/**
* Display a listing of the Module.
*
* @return mixed
*/
public function index()
{
$modules = $this->moduleSvc->getAllModules();
$new_modules = $this->moduleSvc->scan();
return view('admin.modules.index', [
'modules' => $modules,
'new_modules' => $new_modules,
]);
}
/**
* Show the form for creating a new Module.
*
* @return Application|Factory|View
*/
public function create()
{
return view('admin.modules.create');
}
/**
* Store a newly Uploaded Module in the Storage.
*
* @param Request $request
*
* @return Application|RedirectResponse|Redirector
*/
public function store(Request $request)
{
$this->moduleSvc->installModule($request->file('module_file'));
return $this->index();
}
/**
* Show the form for editing the specified Module.
*
* @param $id
*
* @return Application|Factory|View
*/
public function edit($id)
{
$module = $this->moduleSvc->getModule($id);
return view('admin.modules.edit', [
'module' => $module,
]);
}
/**
* Update the specified Module in storage.
*
* @param $id
* @param Request $request
*
* @return Application|RedirectResponse|Redirector
*/
public function update($id, Request $request)
{
$this->moduleSvc->updateModule($id, $request->has('enabled'));
flash()->success('Module Status Changed!');
return redirect(route('admin.modules.index'));
}
/**
* Enabling Module Present in the Modules Folder
*
* @param Request $request
*
* @return Application|RedirectResponse|Redirector
*/
public function enable(Request $request)
{
$this->moduleSvc->addModule($request->input('name'));
return redirect(route('admin.modules.index'));
}
/**
* Verify and Remove the specified Module from storage.
*
* @param mixed $id
* @param Request $request
*
* @return mixed
*/
public function destroy($id, Request $request)
{
$delete = $this->moduleSvc->deleteModule($id, $request->all());
if ($delete == true) {
flash()->success('Module Deleted Successfully!');
return redirect(route('admin.modules.index'));
}
flash()->error('Verification Failed!');
return redirect(route('admin.modules.edit', $id));
}
}

View File

@@ -8,7 +8,6 @@ use App\Http\Requests\UpdateUserRequest;
use App\Models\Rank;
use App\Models\Role;
use App\Models\User;
use App\Models\UserAward;
use App\Repositories\AirlineRepository;
use App\Repositories\AirportRepository;
use App\Repositories\PirepRepository;
@@ -21,7 +20,6 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
use Laracasts\Flash\Flash;
use League\ISO3166\ISO3166;
use Prettus\Repository\Exceptions\RepositoryException;
class UserController extends Controller
@@ -71,7 +69,7 @@ class UserController extends Controller
return view('admin.users.index', [
'users' => $users,
'country' => new ISO3166(),
'country' => new \League\ISO3166\ISO3166(),
]);
}
@@ -84,18 +82,13 @@ class UserController extends Controller
{
$airlines = $this->airlineRepo->selectBoxList();
$airports = $this->airportRepo->selectBoxList(false);
$countries = collect((new ISO3166())->all())
->mapWithKeys(function ($item, $key) {
return [strtolower($item['alpha2']) => $item['name']];
});
return view('admin.users.create', [
'user' => null,
'pireps' => null,
'airlines' => $airlines,
'timezones' => Timezonelist::toArray(),
'country' => new ISO3166(),
'countries' => $countries,
'country' => new \League\ISO3166\ISO3166(),
'airports' => $airports,
'ranks' => Rank::all()->pluck('name', 'id'),
'roles' => Role::all()->pluck('name', 'id'),
@@ -129,7 +122,31 @@ class UserController extends Controller
*/
public function show($id)
{
return $this->edit($id);
$user = $this->userRepo->findWithoutFail($id);
if (empty($user)) {
Flash::error('User not found');
return redirect(route('admin.users.index'));
}
$pireps = $this->pirepRepo
->whereOrder(['user_id' => $id], 'created_at', 'desc')
->paginate();
$airlines = $this->airlineRepo->selectBoxList();
$airports = $this->airportRepo->selectBoxList(false);
return view('admin.users.show', [
'user' => $user,
'pireps' => $pireps,
'airlines' => $airlines,
'timezones' => Timezonelist::toArray(),
'country' => new \League\ISO3166\ISO3166(),
'airports' => $airports,
'ranks' => Rank::all()->pluck('name', 'id'),
'roles' => Role::all()->pluck('name', 'id'),
]);
}
/**
@@ -137,14 +154,12 @@ class UserController extends Controller
*
* @param int $id
*
* @throws RepositoryException
*
* @return mixed
*/
public function edit($id)
{
$user = $this->userRepo
->with(['awards', 'fields', 'rank'])
->with(['fields', 'rank'])
->findWithoutFail($id);
if (empty($user)) {
@@ -156,7 +171,7 @@ class UserController extends Controller
->whereOrder(['user_id' => $id], 'created_at', 'desc')
->paginate();
$countries = collect((new ISO3166())->all())
$countries = collect((new \League\ISO3166\ISO3166())->all())
->mapWithKeys(function ($item, $key) {
return [strtolower($item['alpha2']) => $item['name']];
});
@@ -167,7 +182,6 @@ class UserController extends Controller
return view('admin.users.edit', [
'user' => $user,
'pireps' => $pireps,
'country' => new ISO3166(),
'countries' => $countries,
'timezones' => Timezonelist::toArray(),
'airports' => $airports,
@@ -266,28 +280,6 @@ class UserController extends Controller
return redirect(route('admin.users.index'));
}
/**
* Remove the award from a user
*
* @param \Illuminate\Http\Request $request
* @param mixed $id
* @param mixed $award_id
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy_user_award($id, $award_id, Request $request)
{
$userAward = UserAward::where(['user_id' => $id, 'award_id' => $award_id]);
if (empty($userAward)) {
Flash::error('The user award could not be found');
return redirect()->back();
}
$userAward->delete();
return redirect()->back();
}
/**
* Regenerate the user's API key
*

View File

@@ -9,7 +9,6 @@ use App\Http\Resources\Navdata as NavdataResource;
use App\Models\SimBrief;
use App\Repositories\Criteria\WhereCriteria;
use App\Repositories\FlightRepository;
use App\Services\FareService;
use App\Services\FlightService;
use Exception;
use Illuminate\Http\Request;
@@ -19,26 +18,19 @@ use Prettus\Repository\Exceptions\RepositoryException;
class FlightController extends Controller
{
/** @var \App\Services\FareService */
private $fareSvc;
/** @var \App\Repositories\FlightRepository */
private $flightRepo;
/** @var \App\Services\FlightService */
private $flightSvc;
/**
* @param FareService $fareSvc
* FlightController constructor.
*
* @param FlightRepository $flightRepo
* @param FlightService $flightSvc
*/
public function __construct(
FareService $fareSvc,
FlightRepository $flightRepo,
FlightService $flightSvc
) {
$this->fareSvc = $fareSvc;
$this->flightRepo = $flightRepo;
$this->flightSvc = $flightSvc;
}
@@ -62,13 +54,9 @@ class FlightController extends Controller
*/
public function get($id)
{
/** @var \App\Models\User $user */
$user = Auth::user();
/** @var \App\Models\Flight $flight */
$flight = $this->flightRepo->with([
'airline',
'fares',
'subfleets',
'subfleets.aircraft',
'subfleets.fares',
@@ -78,8 +66,7 @@ class FlightController extends Controller
},
])->find($id);
$flight = $this->flightSvc->filterSubfleets($user, $flight);
$flight = $this->fareSvc->getReconciledFaresForFlight($flight);
$this->flightSvc->filterSubfleets(Auth::user(), $flight);
return new FlightResource($flight);
}
@@ -122,7 +109,6 @@ class FlightController extends Controller
$flights = $this->flightRepo
->with([
'airline',
'fares',
'subfleets',
'subfleets.aircraft',
'subfleets.fares',
@@ -138,8 +124,7 @@ class FlightController extends Controller
// TODO: Remove any flights here that a user doesn't have permissions to
foreach ($flights as $flight) {
$this->flightSvc->filterSubfleets($user, $flight);
$this->fareSvc->getReconciledFaresForFlight($flight);
$this->flightSvc->filterSubfleets(Auth::user(), $flight);
}
return FlightResource::collection($flights);

View File

@@ -61,8 +61,7 @@ class UserController extends Controller
*/
protected function getUserId(Request $request)
{
$id = $request->get('id');
if ($id === null || $id === 'me') {
if ($request->get('id') === null) {
return Auth::user()->id;
}
@@ -90,7 +89,10 @@ class UserController extends Controller
*/
public function get($id)
{
$user = $this->userSvc->getUser($id);
$user = $this->userRepo
->with(['airline', 'bids', 'rank'])
->find($id);
return new UserResource($user);
}
@@ -106,7 +108,7 @@ class UserController extends Controller
*/
public function bids(Request $request)
{
$user = $this->userSvc->getUser($this->getUserId($request));
$user = $this->userRepo->find($this->getUserId($request));
// Add a bid
if ($request->isMethod('PUT') || $request->isMethod('POST')) {

View File

@@ -181,9 +181,8 @@ class PirepController extends Controller
$where = [['user_id', $user->id]];
$where[] = ['state', '<>', PirepState::CANCELLED];
$with = ['airline', 'aircraft', 'dpt_airport', 'arr_airport', 'fares', 'comments'];
$this->pirepRepo->with($with)
$this->pirepRepo->with(['airline', 'aircraft', 'dpt_airport', 'arr_airport'])
->pushCriteria(new WhereCriteria($request, $where));
$pireps = $this->pirepRepo->orderBy('created_at', 'desc')->paginate();

View File

@@ -61,14 +61,27 @@ class ProfileController extends Controller
}
/**
* Redirect to show() since only a single page gets shown and the template controls
* the other items that are/aren't shown
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
return $this->show(Auth::user()->id);
/** @var User $user */
$user = Auth::user();
if (setting('pilots.home_hubs_only')) {
$airports = $this->airportRepo->findWhere(['hub' => true]);
} else {
$airports = $this->airportRepo->all();
}
$userFields = $this->userRepo->getUserFields($user);
return view('profile.index', [
'acars' => $this->acarsEnabled(),
'user' => $user,
'airports' => $airports,
'userFields' => $userFields,
]);
}
/**
@@ -78,8 +91,7 @@ class ProfileController extends Controller
*/
public function show($id)
{
/** @var \App\Models\User $user */
$user = User::with(['awards', 'fields', 'fields.field'])
$user = User::with(['fields', 'fields.field'])
->where('id', $id)
->first();

View File

@@ -11,7 +11,7 @@ class PrefileRequest extends FormRequest
return [
'airline_id' => 'required|exists:airlines,id',
'aircraft_id' => 'required|exists:aircraft,id',
'flight_id' => 'sometimes|nullable|exists:flights,id',
'flight_id' => 'sometimes|exists:flights,id',
'flight_number' => 'required',
'dpt_airport_id' => 'required',
'arr_airport_id' => 'required',

View File

@@ -15,9 +15,9 @@ class Fare extends Resource
'id' => $this->id,
'code' => $this->code,
'name' => $this->name,
'capacity' => $this->capacity,
'cost' => $this->cost,
'price' => $this->price,
'cost' => $this->cost,
'capacity' => $this->capacity,
'type' => $this->type,
'notes' => $this->notes,
'active' => $this->active,

View File

@@ -31,7 +31,6 @@ class User extends Resource
$res['airline'] = Airline::make($this->whenLoaded('airline'));
$res['bids'] = UserBid::collection($this->whenLoaded('bids'));
$res['rank'] = Rank::make($this->whenLoaded('rank'));
$res['subfleets'] = Subfleet::make($this->whenLoaded('subfleets'));
return $res;
}

View File

@@ -1,71 +0,0 @@
<?php
namespace App\Listeners;
use App\Contracts\Listener;
use App\Events\PirepAccepted;
use App\Events\UserStateChanged;
use App\Events\UserStatsChanged;
use App\Models\Award;
/**
* Look for and run any of the award classes. Don't modify this.
* See the documentation on creating awards:
*
* @url http://docs.phpvms.net/customizing/awards
*/
class AwardHandler extends Listener
{
/** The events and the callback */
public static $callbacks = [
PirepAccepted::class => 'onPirepAccept',
UserStatsChanged::class => 'onUserStatsChanged',
UserStateChanged::class => 'onUserStateChanged',
];
/**
* Called when a PIREP is accepted
*
* @param \App\Events\PirepAccepted $event
*/
public function onPirepAccept(PirepAccepted $event)
{
$this->checkForAwards($event->pirep->user);
}
/**
* When the user's state has changed
*
* @param \App\Events\UserStateChanged $event
*/
public function onUserStateChanged(UserStateChanged $event): void
{
$this->checkForAwards($event->user);
}
/**
* Called when any of the user's states have changed
*
* @param UserStatsChanged $event
*/
public function onUserStatsChanged(UserStatsChanged $event): void
{
$this->checkForAwards($event->user);
}
/**
* Check for any awards to be run and test them against the user
*
* @param \App\Models\User $user
*/
public function checkForAwards($user)
{
$awards = Award::all();
foreach ($awards as $award) {
$klass = $award->getReference($award, $user);
if ($klass) {
$klass->handle();
}
}
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Listeners;
use App\Contracts\Listener;
use App\Events\UserStatsChanged;
use App\Models\Award;
/**
* Look for and run any of the award classes. Don't modify this.
* See the documentation on creating awards:
*
* @url http://docs.phpvms.net/customizing/awards
*/
class AwardListener extends Listener
{
/**
* Call all of the awards
*
* @param UserStatsChanged $event
*/
public function handle(UserStatsChanged $event): void
{
$awards = Award::all();
foreach ($awards as $award) {
$klass = $award->getReference($award, $event->user);
if ($klass) {
$klass->handle();
}
}
}
}

View File

@@ -25,10 +25,6 @@ use Illuminate\Support\Collection;
* @property int distance
* @property int flight_time
* @property string route
* @property string dpt_time
* @property string arr_time
* @property string flight_type
* @property string notes
* @property int level
* @property float load_factor
* @property float load_factor_variance

View File

@@ -1,32 +0,0 @@
<?php
namespace App\Models;
use App\Contracts\Model;
use Carbon\Carbon;
/**
* @property string name
* @property bool enabled
* @property Carbon created_at
* @property Carbon updated_at
*/
class Module extends Model
{
public $table = 'modules';
public $fillable = [
'name',
'enabled',
'created_at',
'updated_at',
];
protected $casts = [
'enabled' => 'boolean',
];
public static $rules = [
'name' => 'required',
];
}

View File

@@ -4,14 +4,6 @@ namespace App\Models;
use App\Contracts\Model;
/**
* @property int code
* @property string name
* @property float cost
* @property float price
* @property int capacity
* @property int count
*/
class PirepFare extends Model
{
public $table = 'pirep_fares';
@@ -19,25 +11,26 @@ class PirepFare extends Model
protected $fillable = [
'pirep_id',
'code',
'name',
'fare_id',
'count',
'price',
'cost',
'capacity',
];
protected $casts = [
'count' => 'integer',
'price' => 'float',
'cost' => 'float',
'capacity' => 'integer',
'count' => 'integer',
];
public static $rules = [
'count' => 'required',
];
/**
* Relationships
*/
public function fare()
{
return $this->belongsTo(Fare::class, 'fare_id');
}
public function pirep()
{
return $this->belongsTo(Pirep::class, 'pirep_id');

View File

@@ -36,7 +36,6 @@ use Laratrust\Traits\LaratrustUserTrait;
* @property int state
* @property bool opt_in
* @property string last_pirep_id
* @property Pirep last_pirep
* @property UserFieldValue[] fields
*
* @mixin \Illuminate\Database\Eloquent\Builder
@@ -209,12 +208,9 @@ class User extends Authenticatable
return $this->belongsTo(Airline::class, 'airline_id');
}
/**
* @return \App\Models\Award[]|mixed
*/
public function awards()
{
return $this->belongsToMany(Award::class, 'user_awards');
return $this->hasMany(UserAward::class, 'user_id');
}
/**

View File

@@ -5,7 +5,7 @@ namespace App\Providers;
use App\Events\Expenses;
use App\Events\PirepFiled;
use App\Events\UserStatsChanged;
use App\Listeners\AwardHandler;
use App\Listeners\AwardListener;
use App\Listeners\BidEventHandler;
use App\Listeners\ExpenseListener;
use App\Listeners\FinanceEventHandler;
@@ -33,7 +33,7 @@ class EventServiceProvider extends ServiceProvider
],
UserStatsChanged::class => [
AwardListener::class,
],
UpdateAvailable::class => [],
@@ -44,6 +44,5 @@ class EventServiceProvider extends ServiceProvider
BidEventHandler::class,
FinanceEventHandler::class,
EventHandler::class,
AwardHandler::class,
];
}

View File

@@ -27,74 +27,6 @@ class RouteServiceProvider extends ServiceProvider
$this->mapWebRoutes();
$this->mapAdminRoutes();
$this->mapApiRoutes();
$this->mapImporterRoutes();
$this->mapInstallerRoutes();
$this->mapUpdaterRoutes();
}
private function mapImporterRoutes()
{
Route::group([
'as' => 'importer.',
'prefix' => 'importer',
'middleware' => ['web'],
'namespace' => 'App\Http\Controllers\System',
], function () {
Route::get('/', 'ImporterController@index')->name('index');
Route::post('/config', 'ImporterController@config')->name('config');
Route::post('/dbtest', 'ImporterController@dbtest')->name('dbtest');
// Run the actual importer process. Additional middleware
Route::post('/run', 'ImporterController@run')->middleware('api')->name('run');
Route::post('/complete', 'ImporterController@complete')->name('complete');
});
}
private function mapInstallerRoutes()
{
Route::group([
'as' => 'installer.',
'prefix' => 'install',
'middleware' => ['web'],
'namespace' => 'App\Http\Controllers\System',
], function () {
Route::get('/', 'InstallerController@index')->name('index');
Route::post('/dbtest', 'InstallerController@dbtest')->name('dbtest');
Route::get('/step1', 'InstallerController@step1')->name('step1');
Route::post('/step1', 'InstallerController@step1')->name('step1post');
Route::get('/step2', 'InstallerController@step2')->name('step2');
Route::post('/envsetup', 'InstallerController@envsetup')->name('envsetup');
Route::get('/dbsetup', 'InstallerController@dbsetup')->name('dbsetup');
Route::get('/step3', 'InstallerController@step3')->name('step3');
Route::post('/usersetup', 'InstallerController@usersetup')->name('usersetup');
Route::get('/complete', 'InstallerController@complete')->name('complete');
});
}
protected function mapUpdaterRoutes()
{
Route::group([
'as' => 'update.',
'prefix' => 'update',
'middleware' => ['web', 'auth', 'ability:admin,admin-access'],
'namespace' => 'App\Http\Controllers\System',
], function () {
Route::get('/', 'UpdateController@index')->name('index');
Route::get('/step1', 'UpdateController@step1')->name('step1');
Route::post('/step1', 'UpdateController@step1')->name('step1post');
Route::post('/run-migrations', 'UpdateController@run_migrations')->name('run_migrations');
Route::get('/complete', 'UpdateController@complete')->name('complete');
// Routes for the update downloader
Route::get('/downloader', 'UpdateController@updater')->name('updater');
Route::post('/downloader', 'UpdateController@update_download')->name('update_download');
});
}
/**
@@ -109,7 +41,7 @@ class RouteServiceProvider extends ServiceProvider
Route::group([
'middleware' => ['web'],
'namespace' => $this->namespace,
], function () {
], function ($router) {
Route::group([
'namespace' => 'Frontend',
'prefix' => '',
@@ -424,17 +356,10 @@ class RouteServiceProvider extends ServiceProvider
Route::resource('subfleets', 'SubfleetController')->middleware('ability:admin,fleet');
/**
* USERS
*/
Route::delete('users/{id}/award/{award_id}', 'UserController@destroy_user_award')
->name('users.destroy_user_award')->middleware('ability:admin,users');
Route::resource('users', 'UserController')->middleware('ability:admin,users');
Route::get('users/{id}/regen_apikey', 'UserController@regen_apikey')
->name('users.regen_apikey')->middleware('ability:admin,users');
Route::resource('users', 'UserController')->middleware('ability:admin,users');
// defaults
Route::get('', ['uses' => 'DashboardController@index'])
->middleware('update_pending', 'ability:admin,admin-access');
@@ -453,35 +378,6 @@ class RouteServiceProvider extends ServiceProvider
'delete',
], 'dashboard/news', ['uses' => 'DashboardController@news'])
->name('dashboard.news')->middleware('update_pending', 'ability:admin,admin-access');
//Modules
Route::group([
'as' => 'modules.',
'prefix' => 'modules',
'middleware' => ['ability:admin, modules'],
], function () {
//Modules Index
Route::get('/', 'ModulesController@index')->name('index');
//Add Module
Route::get('/create', 'ModulesController@create')->name('create');
//Store Module
Route::post('/create', 'ModulesController@store')->name('store');
//Enable Module
Route::post('/enable', 'ModulesController@enable')->name('enable');
//Edit Module
Route::get('/{id}/edit', 'ModulesController@edit')->name('edit');
//Update Module
Route::post('/{id}', 'ModulesController@update')->name('update');
//Delete Module
Route::delete('/{id}', 'ModulesController@destroy')->name('destroy');
});
});
}
@@ -499,7 +395,7 @@ class RouteServiceProvider extends ServiceProvider
'namespace' => $this->namespace.'\\Api',
'prefix' => 'api',
'as' => 'api.',
], function () {
], function ($router) {
Route::group([], function () {
Route::get('acars', 'AcarsController@live_flights');
Route::get('acars/geojson', 'AcarsController@pireps_geojson');
@@ -580,7 +476,6 @@ class RouteServiceProvider extends ServiceProvider
Route::post('user/bids', 'UserController@bids');
Route::delete('user/bids', 'UserController@bids');
Route::get('users/me', 'UserController@index');
Route::get('users/{id}', 'UserController@get');
Route::get('users/{id}/fleet', 'UserController@fleet');
Route::get('users/{id}/pireps', 'UserController@pireps');

View File

@@ -8,6 +8,9 @@ use Illuminate\Support\Collection;
use Prettus\Repository\Contracts\CacheableInterface;
use Prettus\Repository\Traits\CacheableRepository;
/**
* Class ExpenseRepository
*/
class ExpenseRepository extends Repository implements CacheableInterface
{
use CacheableRepository;
@@ -21,18 +24,17 @@ class ExpenseRepository extends Repository implements CacheableInterface
* Get all of the expenses for a given type, and also
* include expenses for a given airline ID
*
* @param $type
* @param null $airline_id
* @param null $ref_model
* @param mixed $ref_model_id
* @param $type
* @param int $airline_id
* @param string $ref_model
* @param mixed $ref_model_id
*
* @return Collection
*/
public function getAllForType($type, $airline_id = null, $ref_model = null, $ref_model_id = null)
{
$where = [
'type' => $type,
'active' => true,
'type' => $type,
['airline_id', '=', null],
];
@@ -57,7 +59,6 @@ class ExpenseRepository extends Repository implements CacheableInterface
if ($airline_id) {
$where = [
'type' => $type,
'active' => true,
'airline_id' => $airline_id,
];

View File

@@ -7,9 +7,6 @@ use App\Models\Enums\PirepState;
use App\Models\Pirep;
use App\Models\User;
/**
* Class PirepRepository
*/
class PirepRepository extends Repository
{
protected $fieldSearchable = [

View File

@@ -4,11 +4,13 @@ namespace App\Services;
use App\Contracts\Service;
use App\Models\Aircraft;
use App\Models\Enums\PirepState;
use App\Models\Pirep;
use App\Repositories\PirepRepository;
class AircraftService extends Service
{
/** @var PirepRepository */
private $pirepRepo;
public function __construct(PirepRepository $pirepRepo)
@@ -16,6 +18,26 @@ class AircraftService extends Service
$this->pirepRepo = $pirepRepo;
}
/**
* Get a list of the PIREPs that have been flown by this aircraft
*
* @param Aircraft $aircraft
* @param int $count
*
* @return Pirep[] Collection of PIREPs
*/
public function getFlightHistory(Aircraft $aircraft, $count = 5)
{
return $this->pirepRepo
->orderBy('created_at', 'desc')
->limit($count)
->where([
'aircraft_id' => $aircraft->id,
'state' => PirepState::ACCEPTED,
])
->get();
}
/**
* Recalculate all aircraft stats and hours
*/

View File

@@ -13,24 +13,12 @@ use Illuminate\Support\Facades\Log;
class BidService extends Service
{
/** @var FareService */
private $fareSvc;
/** @var FlightService */
private $flightSvc;
public function __construct(FareService $fareSvc, FlightService $flightSvc)
{
$this->fareSvc = $fareSvc;
$this->flightSvc = $flightSvc;
}
/**
* Get a specific bid for a user
*
* @param $bid_id
*
* @return \App\Models\Bid|\Illuminate\Database\Eloquent\Model|tests/ImporterTest.php:521object|null
* @return \App\Models\Bid|\Illuminate\Database\Eloquent\Model|object|null
*/
public function getBid($bid_id)
{
@@ -47,22 +35,8 @@ class BidService extends Service
*/
public function findBidsForUser(User $user)
{
$bids = Bid::with([
'flight',
'flight.fares',
'flight.simbrief',
'flight.subfleets',
'flight.subfleets.aircraft',
'flight.subfleets.fares',
])
return Bid::with(['flight', 'flight.simbrief'])
->where(['user_id' => $user->id])->get();
foreach ($bids as $bid) {
$bid->flight = $this->flightSvc->filterSubfleets($user, $bid->flight);
$bid->flight = $this->fareSvc->getReconciledFaresForFlight($bid->flight);
}
return $bids;
}
/**

View File

@@ -38,9 +38,10 @@ class CronService extends Service
}
$path = [
'cd '.base_path(),
'&&',
$php_exec,
base_path('artisan'),
'schedule:run',
'artisan schedule:run',
];
return implode(' ', $path);

View File

@@ -9,99 +9,17 @@ use App\Models\Pirep;
use App\Models\PirepFare;
use App\Models\Subfleet;
use App\Support\Math;
use function count;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use InvalidArgumentException;
class FareService extends Service
{
/**
* @param Collection[Fare] $subfleet_fares The fare for a subfleet
* @param Collection[Fare] $flight_fares The fares on a flight
* Get the fares for a particular flight, with an optional subfleet
* This will go through if there are any fares assigned to the flight,
* and then check the fares assigned on the subfleet, and give the
* final "authoritative" list of the fares for a flight.
*
* @return Collection[Fare] Collection of Fare
*/
public function getFareWithOverrides($subfleet_fares, $flight_fares): Collection
{
/**
* Make sure we've got something in terms of fares on the subfleet or the flight
*/
if (empty($subfleet_fares) && empty($flight_fares)) {
return collect();
}
/**
* Check to see if there are any subfleet fares. This might only have fares on the
* flight, no matter how rare that might be
*/
if ($subfleet_fares === null || count($subfleet_fares) === 0) {
return $flight_fares->map(function ($fare, $_) {
return $this->getFareWithPivot($fare, $fare->pivot);
});
}
return $subfleet_fares->map(function ($sf_fare, $_) use ($flight_fares) {
/**
* Get the fare, using the subfleet's pivot values. This will return
* the fares with all the costs, etc, that are overridden for the given subfleet
*/
$fare = $this->getFareWithPivot($sf_fare, $sf_fare->pivot);
/**
* Now, using the fares that have already been used from the subfleet
* now pass those fares in for the flight to override.
*
* First look to see that there actually is an override for that fare that's on
* the flight
*/
$flight_fare = $flight_fares->whereStrict('id', $fare->id)->first();
if ($flight_fare === null) {
return $fare;
}
/**
* Found an override on the flight for the given fare. Check to see if we
* have values there that can be used to override or act as a pivot
*/
$fare = $this->getFareWithPivot($fare, $flight_fare->pivot);
/**
* Finally return the fare that we have, it should have gone through the
* multiple levels of reconciliation that were required
*/
return $fare;
});
}
/**
* This will return the flight but all of the subfleets will have the corrected fares with the
* right amounts based on the pivots, and with the correct "inheritence" for the flights
*
* @param Flight $flight
*
* @return \App\Models\Flight
*/
public function getReconciledFaresForFlight(Flight $flight): Flight
{
$subfleets = $flight->subfleets;
$flight_fares = $flight->fares;
/**
* @var int $key
* @var Subfleet $subfleet
*/
foreach ($subfleets as $key => $subfleet) {
$subfleet->fares = $this->getFareWithOverrides($subfleet->fares, $flight_fares);
}
$flight->subfleets = $subfleets;
return $flight;
}
/**
* Get the fares for a particular flight, with the subfleet that is in use being passed in
* If a subfleet is passed in,
*
* @param Flight|null $flight
* @param Subfleet|null $subfleet
@@ -113,59 +31,62 @@ class FareService extends Service
if (!$flight) {
$flight_fares = collect();
} else {
$flight_fares = $flight->fares;
$flight_fares = $this->getForFlight($flight);
}
if (empty($subfleet)) {
throw new InvalidArgumentException('Subfleet argument missing');
return $flight_fares;
}
return $this->getFareWithOverrides($subfleet->fares, $flight_fares);
$subfleet_fares = $this->getForSubfleet($subfleet);
if (empty($subfleet_fares) || $subfleet_fares->count() === 0) {
return $flight_fares;
}
// Go through all of the fares assigned by the subfleet
// See if any of the same fares are assigned to the flight
$fares = $subfleet_fares->map(function ($fare, $idx) use ($flight_fares) {
$flight_fare = $flight_fares->whereStrict('id', $fare->id)->first();
if (!$flight_fare) {
return $fare;
}
return $flight_fare;
});
return $fares;
}
/**
* Get a fare with the proper prices/costs populated in the pivot
* Get fares
*
* @param $fare
*
* @return mixed
*/
public function getFares($fare)
protected function getFares($fare)
{
return $this->getFareWithPivot($fare, $fare->pivot);
}
/**
* Get the correct price of something supplied with the correct pivot
*
* @param Fare $fare
* @param Pivot $pivot
*
* @return \App\Models\Fare
*/
public function getFareWithPivot(Fare $fare, Pivot $pivot)
{
if (filled($pivot->price)) {
if (strpos($pivot->price, '%', -1) !== false) {
$fare->price = Math::addPercent($fare->price, $pivot->price);
if (filled($fare->pivot->price)) {
if (strpos($fare->pivot->price, '%', -1) !== false) {
$fare->price = Math::addPercent($fare->price, $fare->pivot->price);
} else {
$fare->price = $pivot->price;
$fare->price = $fare->pivot->price;
}
}
if (filled($pivot->cost)) {
if (strpos($pivot->cost, '%', -1) !== false) {
$fare->cost = Math::addPercent($fare->cost, $pivot->cost);
if (filled($fare->pivot->cost)) {
if (strpos($fare->pivot->cost, '%', -1) !== false) {
$fare->cost = Math::addPercent($fare->cost, $fare->pivot->cost);
} else {
$fare->cost = $pivot->cost;
$fare->cost = $fare->pivot->cost;
}
}
if (filled($pivot->capacity)) {
if (strpos($pivot->capacity, '%', -1) !== false) {
$fare->capacity = floor(Math::addPercent($fare->capacity, $pivot->capacity));
if (filled($fare->pivot->capacity)) {
if (strpos($fare->pivot->capacity, '%', -1) !== false) {
$fare->capacity = Math::addPercent($fare->capacity, $fare->pivot->capacity);
} else {
$fare->capacity = floor($pivot->capacity);
$fare->capacity = $fare->pivot->capacity;
}
}
@@ -183,12 +104,16 @@ class FareService extends Service
*/
public function setForFlight(Flight $flight, Fare $fare, array $override = []): Flight
{
Log::info('Setting fare "'.$fare->name.'" to flight "'.$flight->ident.'"');
$flight->fares()->syncWithoutDetaching([$fare->id]);
foreach ($override as $key => $item) {
if (!$item) {
unset($override[$key]);
}
}
// modify any pivot values?
if (count($override) > 0) {
if (\count($override) > 0) {
$flight->fares()->updateExistingPivot($fare->id, $override);
}
@@ -198,6 +123,24 @@ class FareService extends Service
return $flight;
}
/**
* return all the fares for a flight. check the pivot
* table to see if the price/cost/capacity has been overridden
* and return the correct amounts.
*
* @param Flight $flight
*
* @return Collection
*/
public function getForFlight(Flight $flight)
{
$fares = $flight->fares->map(function ($fare) {
return $this->getFares($fare);
});
return $fares;
}
/**
* @param Flight $flight
* @param Fare $fare
@@ -206,8 +149,6 @@ class FareService extends Service
*/
public function delFareFromFlight(Flight $flight, Fare $fare)
{
Log::info('Removing fare "'.$fare->name.'" to flight "'.$flight->ident.'"');
$flight->fares()->detach($fare->id);
$flight->refresh();
@@ -225,12 +166,10 @@ class FareService extends Service
*/
public function setForSubfleet(Subfleet $subfleet, Fare $fare, array $override = []): Subfleet
{
Log::info('Setting fare "'.$fare->name.'" to subfleet "'.$subfleet->name.'"');
$subfleet->fares()->syncWithoutDetaching([$fare->id]);
// modify any pivot values?
if (count($override) > 0) {
if (\count($override) > 0) {
$subfleet->fares()->updateExistingPivot($fare->id, $override);
}
@@ -268,8 +207,6 @@ class FareService extends Service
*/
public function delFareFromSubfleet(Subfleet &$subfleet, Fare &$fare)
{
Log::info('Removing fare "'.$fare->name.'" from subfleet "'.$subfleet->name.'"');
$subfleet->fares()->detach($fare->id);
$subfleet->refresh();
@@ -286,6 +223,7 @@ class FareService extends Service
*/
public function getForPirep(Pirep $pirep)
{
$fares = [];
$found_fares = PirepFare::where('pirep_id', $pirep->id)->get();
return $found_fares;

View File

@@ -8,7 +8,6 @@ use App\Models\Bid;
use App\Models\Enums\Days;
use App\Models\Flight;
use App\Models\FlightFieldValue;
use App\Models\User;
use App\Repositories\FlightRepository;
use App\Repositories\NavdataRepository;
use App\Support\Units\Time;
@@ -16,7 +15,6 @@ use App\Support\Units\Time;
class FlightService extends Service
{
private $airportSvc;
private $fareSvc;
private $flightRepo;
private $navDataRepo;
private $userSvc;
@@ -25,20 +23,17 @@ class FlightService extends Service
* FlightService constructor.
*
* @param AirportService $airportSvc
* @param FareService $fareSvc
* @param FlightRepository $flightRepo
* @param NavdataRepository $navdataRepo
* @param UserService $userSvc
*/
public function __construct(
AirportService $airportSvc,
FareService $fareSvc,
FlightRepository $flightRepo,
NavdataRepository $navdataRepo,
UserService $userSvc
) {
$this->airportSvc = $airportSvc;
$this->fareSvc = $fareSvc;
$this->flightRepo = $flightRepo;
$this->navDataRepo = $navdataRepo;
$this->userSvc = $userSvc;
@@ -128,12 +123,12 @@ class FlightService extends Service
/**
* Filter out subfleets to only include aircraft that a user has access to
*
* @param User $user
* @param Flight $flight
* @param $user
* @param $flight
*
* @return mixed
*/
public function filterSubfleets(User $user, Flight $flight)
public function filterSubfleets($user, $flight)
{
/** @var \Illuminate\Support\Collection $subfleets */
$subfleets = $flight->subfleets;

View File

@@ -45,20 +45,8 @@ class AirportImporter extends ImportExport
$row['id'] = $row['icao'];
$row['hub'] = get_truth_state($row['hub']);
if ($row['ground_handling_cost'] === null && $row['ground_handling_cost'] !== 0.0) {
$row['ground_handling_cost'] = (float) setting('airports.default_ground_handling_cost');
} else {
$row['ground_handling_cost'] = (float) $row['ground_handling_cost'];
}
if ($row['fuel_jeta_cost'] === null && $row['fuel_jeta_cost'] !== 0.0) {
$row['fuel_jeta_cost'] = (float) setting('airports.default_jet_a_fuel_cost');
} else {
$row['fuel_jeta_cost'] = (float) $row['fuel_jeta_cost'];
}
try {
Airport::updateOrCreate([
$airport = Airport::updateOrCreate([
'id' => $row['icao'],
], $row);
} catch (\Exception $e) {

View File

@@ -44,10 +44,6 @@ class ExpenseExporter extends ImportExport
$ret['airline'] = $expense->airline->icao;
}
if ($ret['flight_type']) {
$ret['flight_type'] = $ret['flight_type'][0];
}
// For the different expense types, instead of exporting
// the ID, export a specific column
if ($expense->ref_model === Expense::class) {
@@ -71,6 +67,6 @@ class ExpenseExporter extends ImportExport
// And convert the ref_model into the shorter name
$ret['ref_model'] = str_replace('App\Models\\', '', $ret['ref_model']);
return array_values($ret);
return $ret;
}
}

View File

@@ -3,7 +3,6 @@
namespace App\Services\ImportExport;
use App\Contracts\ImportExport;
use App\Models\Airport;
use App\Models\Enums\Days;
use App\Models\Enums\FlightType;
use App\Models\Fare;
@@ -12,7 +11,7 @@ use App\Models\Subfleet;
use App\Services\AirportService;
use App\Services\FareService;
use App\Services\FlightService;
use Illuminate\Support\Facades\Log;
use Log;
/**
* The flight importer can be imported or export. Operates on rows
@@ -78,14 +77,25 @@ class FlightImporter extends ImportExport
// Get the airline ID from the ICAO code
$airline = $this->getAirline($row['airline']);
// Check if the imported flight is a duplicate
/*$temp_flight = new Flight([
'airline_id' => $airline->id,
'flight_number' => $row['flight_number'],
'route_code' => $row['route_code'],
'route_leg' => $row['route_leg'],
]);
if($this->flightSvc->isFlightDuplicate($temp_flight)) {
$this->errorLog('Error in row '.$index.': Duplicate flight number detected');
return false;
}*/
// Try to find this flight
/** @var Flight $flight */
$flight = Flight::firstOrNew([
'airline_id' => $airline->id,
'flight_number' => $row['flight_number'],
'route_code' => $row['route_code'],
'route_leg' => $row['route_leg'],
'visible' => true,
], $row);
$row['dpt_airport'] = strtoupper($row['dpt_airport']);
@@ -190,9 +200,9 @@ class FlightImporter extends ImportExport
*
* @param $airport
*
* @return Airport
* @return \Illuminate\Database\Eloquent\Model
*/
protected function processAirport($airport): Airport
protected function processAirport($airport)
{
return $this->airportSvc->lookupAirportIfNotFound($airport);
}

View File

@@ -47,7 +47,6 @@ class DatabaseService extends Service
} catch (\PDOException $e) {
throw $e;
}
return true;
}

View File

@@ -4,7 +4,7 @@ namespace App\Services\Installer;
use App\Contracts\Service;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
use Nwidart\Modules\Facades\Module;
class InstallerService extends Service
{
@@ -28,14 +28,11 @@ class InstallerService extends Service
*/
public function isUpgradePending(): bool
{
$pendingMigrations = count($this->migrationSvc->migrationsAvailable());
if ($pendingMigrations > 0) {
Log::info('Found '.$pendingMigrations.' pending migrations, update available');
if (count($this->migrationSvc->migrationsAvailable()) > 0) {
return true;
}
if ($this->seederSvc->seedsPending()) {
Log::info('Found seeds pending, update available');
return true;
}
@@ -47,6 +44,27 @@ class InstallerService extends Service
*/
public function clearCaches(): void
{
Artisan::call('optimize:clear');
$commands = [
'clear-compiled',
'cache:clear',
'route:clear',
'view:clear',
];
foreach ($commands as $cmd) {
Artisan::call($cmd);
}
}
/**
* Disable the installer and importer modules
*/
public function disableInstallerModules()
{
$module = Module::find('installer');
$module->disable();
$module = Module::find('importer');
$module->disable();
}
}

View File

@@ -3,16 +3,13 @@
namespace App\Services\Installer;
use App\Contracts\Service;
use Exception;
use Illuminate\Database\Migrations\Migrator;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
use Nwidart\Modules\Facades\Module;
class MigrationService extends Service
{
protected function getMigrator(): Migrator
protected function getMigrator()
{
$m = app('migrator');
$m->setConnection(config('database.default'));
@@ -39,6 +36,8 @@ class MigrationService extends Service
}
}
// Log::info('Update - migration paths', $paths);
return $paths;
}
@@ -50,25 +49,10 @@ class MigrationService extends Service
$migrator = $this->getMigrator();
$migration_dirs = $this->getMigrationPaths();
$availMigrations = [];
$runFiles = [];
try {
$runFiles = $migrator->getRepository()->getRan();
} catch (Exception $e) {
} // Skip database run initialized
$files = $migrator->getMigrationFiles(array_values($migration_dirs));
$availMigrations = array_diff(array_keys($files), $migrator->getRepository()->getRan());
foreach ($files as $filename => $filepath) {
if (in_array($filename, $runFiles, true)) {
continue;
}
$availMigrations[] = $filepath;
}
Log::info('Migrations available: '.count($availMigrations));
// Log::info('Migrations available:', $availMigrations);
return $availMigrations;
}
@@ -79,23 +63,11 @@ class MigrationService extends Service
*/
public function runAllMigrations()
{
// A little ugly, run the main migration first, this makes sure the migration table is there
$output = '';
Artisan::call('migrate');
$output .= trim(Artisan::output());
// Then get any remaining migrations that are left over
// Due to caching or whatever reason, the migrations are not all loaded when Artisan first
// runs. This is likely a side effect of the database being used as the module activator,
// and the list of migrations being pulled before the initial modules are populated
$migrator = $this->getMigrator();
$availMigrations = $this->migrationsAvailable();
Log::info('Running '.count($availMigrations).' available migrations');
$ret = $migrator->run($availMigrations);
Log::info('Ran '.count($ret).' migrations');
return $output."\n".implode("\n", $ret);
return $output;
}
}

View File

@@ -5,7 +5,6 @@ namespace App\Services\Installer;
use App\Contracts\Service;
use App\Models\Setting;
use App\Services\DatabaseService;
use Carbon\Carbon;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
@@ -52,10 +51,9 @@ class SeederService extends Service
*/
public function syncAllSeeds(): void
{
$this->syncAllYamlFileSeeds();
$this->syncAllSettings();
$this->syncAllPermissions();
$this->syncAllModules();
$this->syncAllYamlFileSeeds();
}
/**
@@ -85,24 +83,6 @@ class SeederService extends Service
});
}
public function syncAllModules(): void
{
$data = file_get_contents(database_path('/seeds/modules.yml'));
$yml = Yaml::parse($data);
foreach ($yml as $module) {
$module['updated_at'] = Carbon::now();
$count = DB::table('modules')->where('name', $module['name'])->count('name');
if ($count === 0) {
$module['created_at'] = Carbon::now();
DB::table('modules')->insert($module);
} else {
DB::table('modules')
->where('name', $module['name'])
->update($module);
}
}
}
public function syncAllSettings(): void
{
$data = file_get_contents(database_path('/seeds/settings.yml'));

View File

@@ -3,22 +3,6 @@
namespace App\Services;
use App\Contracts\Service;
use App\Exceptions\ModuleExistsException;
use App\Exceptions\ModuleInstallationError;
use App\Exceptions\ModuleInvalidFileType;
use App\Models\Module;
use Exception;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Laracasts\Flash\FlashNotifier;
use Madnest\Madzipper\Madzipper;
use Nwidart\Modules\Json;
use PharData;
class ModuleService extends Service
{
@@ -38,14 +22,14 @@ class ModuleService extends Service
* @param string $title
* @param string $url
* @param string $icon
* @param bool $logged_in
* @param mixed $logged_in
*/
public function addFrontendLink(string $title, string $url, string $icon = 'pe-7s-users', $logged_in = true)
public function addFrontendLink(string $title, string $url, string $icon = '', $logged_in = true)
{
self::$frontendLinks[$logged_in][] = [
'title' => $title,
'url' => $url,
'icon' => $icon,
'icon' => 'pe-7s-users',
];
}
@@ -68,12 +52,12 @@ class ModuleService extends Service
* @param string $url
* @param string $icon
*/
public function addAdminLink(string $title, string $url, string $icon = 'pe-7s-users')
public function addAdminLink(string $title, string $url, string $icon = '')
{
self::$adminLinks[] = [
'title' => $title,
'url' => $url,
'icon' => $icon,
'icon' => 'pe-7s-users',
];
}
@@ -86,226 +70,4 @@ class ModuleService extends Service
{
return self::$adminLinks;
}
/**
* Get All modules from Database
*
* @return object
*/
public function getAllModules(): object
{
return Module::all();
}
/**
* Get Module Information from Database.
*
* @param $id
*
* @return object
*/
public function getModule($id): object
{
return Module::find($id);
}
/**
* Adding installed module to the database
*
* @param $module_name
*
* @return bool
*/
public function addModule($module_name): bool
{
/*Check if module already exists*/
$module = Module::where('name', $module_name);
if (!$module->exists()) {
Module::create([
'name' => $module_name,
'enabled' => 1,
]);
Artisan::call('module:migrate '.$module_name);
return true;
}
return false;
}
/**
* User's uploaded file is passed into this method
* to install module in the Storage.
*
* @param UploadedFile $file
*
* @return FlashNotifier
*/
public function installModule(UploadedFile $file): FlashNotifier
{
$file_ext = $file->getClientOriginalExtension();
$allowed_extensions = ['zip', 'tar', 'gz'];
if (!in_array($file_ext, $allowed_extensions, true)) {
throw new ModuleInvalidFileType();
}
$module = null;
$new_dir = rand();
File::makeDirectory(
storage_path('app/tmp/modules/'.$new_dir),
0777,
true
);
$temp_ext_folder = storage_path('app/tmp/modules/'.$new_dir);
$temp = storage_path('app/tmp/modules/'.$new_dir);
$zipper = null;
if ($file_ext === 'tar' || $file_ext === 'gz') {
$zipper = new PharData($file);
$zipper->decompress();
}
if ($file_ext === 'zip') {
$madZipper = new Madzipper();
try {
$zipper = $madZipper->make($file);
} catch (Exception $e) {
throw new ModuleInstallationError();
}
}
try {
$zipper->extractTo($temp);
} catch (Exception $e) {
throw new ModuleInstallationError();
}
if (!File::exists($temp.'/module.json')) {
$directories = Storage::directories('tmp/modules/'.$new_dir);
$temp = storage_path('app/'.$directories[0]);
}
$json_file = $temp.'/module.json';
if (File::exists($json_file)) {
$json = json_decode(file_get_contents($json_file), true);
$module = $json['name'];
} else {
File::deleteDirectory($temp_ext_folder);
return flash()->error('Module Structure Not Correct!');
}
if (!$module) {
File::deleteDirectory($temp_ext_folder);
return flash()->error('Not a Valid Module File.');
}
$toCopy = base_path().'/modules/'.$module;
if (File::exists($toCopy)) {
File::deleteDirectory($temp_ext_folder);
throw new ModuleExistsException($module);
}
File::moveDirectory($temp, $toCopy);
File::deleteDirectory($temp_ext_folder);
try {
$this->addModule($module);
} catch (Exception $e) {
throw new ModuleExistsException($module);
}
Artisan::call('config:cache');
Artisan::call('module:migrate '.$module);
return flash()->success('Module Installed');
}
/**
* Update module with the status passed by user.
*
* @param $id
* @param $status
*
* @return bool
*/
public function updateModule($id, $status): bool
{
$module = Module::find($id);
$module->update([
'enabled' => $status,
]);
if ($status === true) {
Artisan::call('module:migrate '.$module->name);
}
return true;
}
/**
* Delete Module from the Storage & Database.
*
* @param $id
* @param $data
*
* @return bool
*/
public function deleteModule($id, $data): bool
{
$module = Module::find($id);
if ($data['verify'] === strtoupper($module->name)) {
try {
$module->delete();
} catch (Exception $e) {
Log::emergency('Cannot Delete Module!');
}
$moduleDir = base_path().'/modules/'.$module->name;
try {
File::deleteDirectory($moduleDir);
} catch (Exception $e) {
Log::info('Folder Deleted Manually for Module : '.$module->name);
return true;
}
return true;
}
return false;
}
/**
* Get & scan all modules.
*
* @return array
*/
public function scan()
{
$modules_path = base_path('modules/*');
$path = Str::endsWith($modules_path, '/*') ? $modules_path : Str::finish($modules_path, '/*');
$modules = [];
$manifests = (new Filesystem())->glob("{$path}/module.json");
is_array($manifests) || $manifests = [];
foreach ($manifests as $manifest) {
$name = Json::make($manifest)->get('name');
$module = Module::where('name', $name);
if (!$module->exists()) {
array_push($modules, $name);
}
}
return $modules;
}
}

View File

@@ -29,51 +29,29 @@ class UserService extends Service
{
private $aircraftRepo;
private $airlineRepo;
private $fareSvc;
private $subfleetRepo;
private $userRepo;
/**
* UserService constructor.
*
* @param AircraftRepository $aircraftRepo
* @param AirlineRepository $airlineRepo
* @param FareService $fareSvc
* @param SubfleetRepository $subfleetRepo
* @param UserRepository $userRepo
*/
public function __construct(
AircraftRepository $aircraftRepo,
AirlineRepository $airlineRepo,
FareService $fareSvc,
SubfleetRepository $subfleetRepo,
UserRepository $userRepo
) {
$this->aircraftRepo = $aircraftRepo;
$this->airlineRepo = $airlineRepo;
$this->fareSvc = $fareSvc;
$this->subfleetRepo = $subfleetRepo;
$this->userRepo = $userRepo;
}
/**
* Find the user and return them with all of the data properly attached
*
* @param $user_id
*
* @return User
*/
public function getUser($user_id): User
{
$user = $this->userRepo
->with(['airline', 'bids', 'rank'])
->find($user_id);
// Load the proper subfleets to the rank
$user->rank->subfleets = $this->getAllowableSubfleets($user);
$user->subfleets = $user->rank->subfleets;
return $user;
}
/**
* Register a pilot. Also attaches the initial roles
* required, and then triggers the UserRegistered event
@@ -85,7 +63,7 @@ class UserService extends Service
*
* @return User
*/
public function createUser(array $attrs, array $roles = []): User
public function createUser(array $attrs, array $roles = null): User
{
$user = User::create($attrs);
$user->api_key = Utils::generateApiKey();
@@ -265,18 +243,11 @@ class UserService extends Service
public function getAllowableSubfleets($user)
{
if ($user === null || setting('pireps.restrict_aircraft_to_rank') === false) {
/** @var Collection $subfleets */
$subfleets = $this->subfleetRepo->with('aircraft')->all();
} else {
/** @var Collection $subfleets */
$subfleets = $user->rank->subfleets()->with('aircraft')->get();
return $this->subfleetRepo->with('aircraft')->all();
}
// Map the subfleets with the proper fare information
return $subfleets->transform(function ($sf, $key) {
$sf->fares = $this->fareSvc->getForSubfleet($sf);
return $sf;
});
$subfleets = $user->rank->subfleets();
return $subfleets->with('aircraft')->get();
}
/**

View File

@@ -515,7 +515,7 @@ class Metar implements \ArrayAccess
// Delete null values from the TAF report
if ($this->result['taf'] === true) {
foreach ($this->result as $parameter => $value) {
if ($value === null) {
if (!$value) {
unset($this->result[$parameter]);
}
}
@@ -530,8 +530,7 @@ class Metar implements \ArrayAccess
} else {
/* @noinspection NestedPositiveIfStatementsInspection */
if (array_key_exists('cloud_height', $this->result) && $this->result['cloud_height'] !== null) {
if ($this->result['cloud_height']['ft'] > 3000
&& (empty($this->result['visibility']) || $this->result['visibility']['nmi'] > 5)) {
if ($this->result['cloud_height']['ft'] > 3000 && $this->result['visibility']['nmi'] > 5) {
$this->result['category'] = 'VFR';
} else {
$this->result['category'] = 'IFR';
@@ -869,11 +868,11 @@ class Metar implements \ArrayAccess
$this->set_result_value('cavok', false, true);
// Cloud and visibilty OK or ICAO visibilty greater than 10 km
if (strtoupper($found[1]) === 'CAVOK' || $found[1] === '9999') {
if ($found[1] === 'CAVOK' || $found[1] === '9999') {
$this->set_result_value('visibility', $this->createDistance(10000, 'm'));
$this->set_result_value('visibility_report', 'Greater than 10 km');
/* @noinspection NotOptimalIfConditionsInspection */
if (strtoupper($found[1]) === 'CAVOK') {
if ($found[1] === 'CAVOK') {
$this->set_result_value('cavok', true);
$this->method += 4; // can skip the next 4 methods: visibility_min, runway_vr, present_weather, clouds
}
@@ -1485,8 +1484,6 @@ class Metar implements \ArrayAccess
return false;
}
// Ignore trends
return true;
// Detects TAF on report
if ($this->part <= 4) {
$this->set_result_value('taf', true);

View File

@@ -1,172 +0,0 @@
<?php
namespace App\Support\Modules;
use Exception;
use Illuminate\Config\Repository as Config;
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Log;
use Nwidart\Modules\Contracts\ActivatorInterface;
use Nwidart\Modules\Module;
class DatabaseActivator implements ActivatorInterface
{
/**
* Laravel config instance
*
* @var Config
*/
private $config;
/**
* @var Filesystem
*/
private $files;
/**
* The module path.
*
* @var string|null
*/
protected $path;
/**
* The scanned paths.
*
* @var array
*/
protected $paths = [];
/**
* Array of modules activation statuses
*
* @var array
*/
private $modulesStatuses;
public function __construct(Container $app, $path = null)
{
$this->config = $app['config'];
$this->files = $app['files'];
$this->modulesStatuses = $this->getModulesStatuses();
$this->path = $path;
}
/**
* @param string $name
*
* @return \App\Models\Module|null
*/
public function getModuleByName(string $name): ?\App\Models\Module
{
try {
return \App\Models\Module::where(['name' => $name])->first();
} catch (Exception $e) { // Catch any database/connection errors
return null;
}
}
/**
* Get modules statuses, from the database
*
* @return array
*/
private function getModulesStatuses(): array
{
try {
$modules = \App\Models\Module::all();
$retVal = [];
foreach ($modules as $i) {
$retVal[$i->name] = $i->enabled;
}
return $retVal;
} catch (Exception $e) {
return [];
}
}
/**
* {@inheritdoc}
*/
public function reset(): void
{
(new \App\Models\Module())->truncate();
}
/**
* {@inheritdoc}
*/
public function enable(Module $module): void
{
$this->setActive($module, true);
}
/**
* {@inheritdoc}
*/
public function disable(Module $module): void
{
$this->setActive($module, false);
}
/**
* \Nwidart\Modules\Module instance passed
* {@inheritdoc}
*/
public function hasStatus(Module $module, bool $status): bool
{
$module = $this->getModuleByName($module->getName());
if (!$module) {
return false;
}
return $module->enabled;
}
/**
* {@inheritdoc}
*/
public function setActive(Module $module, bool $active): void
{
$module = $this->getModuleByName($module->getName());
if (!$module) {
return;
}
$module->enabled = $active;
$module->save();
}
/**
* {@inheritdoc}
*/
public function setActiveByName(string $name, bool $status): void
{
$module = $this->getModuleByName($name);
if (!$module) {
return;
}
$module->enabled = $status;
$module->save();
}
/**
* {@inheritdoc}
*/
public function delete(Module $module): void
{
$name = $module->getName();
try {
(new \App\Models\Module())->where([
'name' => $name,
])->delete();
} catch (Exception $e) {
Log::error('Module '.$module.' Delete failed! Exception : '.$e->getMessage());
return;
}
}
}

View File

@@ -34,7 +34,7 @@
"joshbrw/laravel-module-installer": "0.1.*",
"laracasts/flash": "^3.1",
"laravel/helpers": "^1.2",
"laravelcollective/html": "~6.2.0",
"laravelcollective/html": "~6.1.0",
"layershifter/tld-extract": "^2.0",
"league/csv": "9.2.*",
"league/geotools": "0.8.*",
@@ -42,7 +42,7 @@
"markrogoyski/math-php": "^0.38.0",
"myclabs/deep-copy": "~1.9.0",
"nabeel/vacentral": "~2.0",
"nwidart/laravel-modules": "^8.0",
"nwidart/laravel-modules": "^7.0",
"php-units-of-measure/php-units-of-measure": "~2.1.0",
"phpvms/sample-module": "^1.0",
"pragmarx/version": "^1.2.2",
@@ -57,8 +57,7 @@
"vlucas/phpdotenv": "v4.0",
"webpatser/laravel-uuid": "~3.0",
"oomphinc/composer-installers-extender": "^1.1",
"laravel/ui": "^2.0",
"madnest/madzipper": "^1.0"
"laravel/ui": "^2.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.0",

99
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6f5fb0bd12dc789b1ad1613ddf907a80",
"content-hash": "1fa03b1b729d3f2f2dd04eba1c1749f0",
"packages": [
{
"name": "akaunting/money",
@@ -2925,28 +2925,28 @@
},
{
"name": "laravelcollective/html",
"version": "v6.2.0",
"version": "v6.1.2",
"source": {
"type": "git",
"url": "https://github.com/LaravelCollective/html.git",
"reference": "3bb99be7502feb2129b375cd026ccb0fa4b66628"
"reference": "5ef9a3c9ae2423fe5618996f3cde375d461a3fc6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/LaravelCollective/html/zipball/3bb99be7502feb2129b375cd026ccb0fa4b66628",
"reference": "3bb99be7502feb2129b375cd026ccb0fa4b66628",
"url": "https://api.github.com/repos/LaravelCollective/html/zipball/5ef9a3c9ae2423fe5618996f3cde375d461a3fc6",
"reference": "5ef9a3c9ae2423fe5618996f3cde375d461a3fc6",
"shasum": ""
},
"require": {
"illuminate/http": "^6.0|^7.0|^8.0",
"illuminate/routing": "^6.0|^7.0|^8.0",
"illuminate/session": "^6.0|^7.0|^8.0",
"illuminate/support": "^6.0|^7.0|^8.0",
"illuminate/view": "^6.0|^7.0|^8.0",
"illuminate/http": "^6.0|^7.0",
"illuminate/routing": "^6.0|^7.0",
"illuminate/session": "^6.0|^7.0",
"illuminate/support": "^6.0|^7.0",
"illuminate/view": "^6.0|^7.0",
"php": ">=7.2.5"
},
"require-dev": {
"illuminate/database": "^6.0|^7.0|^8.0",
"illuminate/database": "^6.0|^7.0",
"mockery/mockery": "~1.0",
"phpunit/phpunit": "~7.1"
},
@@ -2989,7 +2989,7 @@
],
"description": "HTML and Form Builders for the Laravel Framework",
"homepage": "https://laravelcollective.com",
"time": "2020-09-07T19:59:40+00:00"
"time": "2020-05-19T18:02:16+00:00"
},
{
"name": "layershifter/tld-database",
@@ -3575,63 +3575,6 @@
],
"time": "2020-08-09T10:34:01+00:00"
},
{
"name": "madnest/madzipper",
"version": "v1.0.5",
"source": {
"type": "git",
"url": "https://github.com/madnest/madzipper.git",
"reference": "c9ee808506a5d53e28876580f98d57717e9b80af"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/madnest/madzipper/zipball/c9ee808506a5d53e28876580f98d57717e9b80af",
"reference": "c9ee808506a5d53e28876580f98d57717e9b80af",
"shasum": ""
},
"require": {
"ext-zip": "*",
"illuminate/filesystem": "^6.18|^7.0|^8.0",
"illuminate/support": "^6.18|^7.0|^8.0",
"laravel/framework": "~7.0|~8.0",
"php": ">=7.2.0"
},
"require-dev": {
"mockery/mockery": "^1.3",
"orchestra/testbench": "^5.1",
"phpunit/phpunit": "^8.0|^9.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Madnest\\Madzipper\\MadzipperServiceProvider"
],
"aliases": {
"Madzipper": "Madnest\\Madzipper\\Madzipper"
}
}
},
"autoload": {
"psr-4": {
"Madnest\\Madzipper\\": "src/Madnest/Madzipper"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jakub Theimer",
"email": "theimer@madne.st",
"homepage": "https://madne.st",
"role": "Developer"
}
],
"description": "Wannabe successor of Chumper/Zipper package for Laravel",
"time": "2020-09-15T11:11:06+00:00"
},
{
"name": "markrogoyski/math-php",
"version": "v0.38.0",
@@ -4016,27 +3959,27 @@
},
{
"name": "nwidart/laravel-modules",
"version": "8.0.0",
"version": "7.2.0",
"source": {
"type": "git",
"url": "https://github.com/nWidart/laravel-modules.git",
"reference": "7983e41c3832a13e521aa915532efdc7b67563af"
"reference": "8980876d63096951e067bcaf8649d591d4c7f0da"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nWidart/laravel-modules/zipball/7983e41c3832a13e521aa915532efdc7b67563af",
"reference": "7983e41c3832a13e521aa915532efdc7b67563af",
"url": "https://api.github.com/repos/nWidart/laravel-modules/zipball/8980876d63096951e067bcaf8649d591d4c7f0da",
"reference": "8980876d63096951e067bcaf8649d591d4c7f0da",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": ">=7.3"
"php": ">=7.2.5"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"laravel/framework": "^8.0",
"laravel/framework": "^7.0",
"mockery/mockery": "~1.0",
"orchestra/testbench": "^6.0",
"orchestra/testbench": "^5.0",
"phpstan/phpstan": "^0.12.14",
"phpunit/phpunit": "^8.5",
"spatie/phpunit-snapshot-assertions": "^2.1.0"
@@ -4052,7 +3995,7 @@
}
},
"branch-alias": {
"dev-master": "8.0-dev"
"dev-master": "7.0-dev"
}
},
"autoload": {
@@ -4089,7 +4032,7 @@
"type": "github"
}
],
"time": "2020-10-03T14:56:31+00:00"
"time": "2020-07-30T17:10:13+00:00"
},
{
"name": "oomphinc/composer-installers-extender",

View File

@@ -7,8 +7,6 @@
* your install. Otherwise, any changes here will get overridden in an update!
*/
use Carbon\Carbon;
return [
'name' => env('APP_NAME', 'phpvms'),
'env' => env('APP_ENV', 'dev'),
@@ -94,7 +92,7 @@ return [
'Auth' => Illuminate\Support\Facades\Auth::class,
'Blade' => Illuminate\Support\Facades\Blade::class,
'Cache' => Illuminate\Support\Facades\Cache::class,
'Carbon' => Carbon::class,
'Carbon' => \Carbon\Carbon::class,
'Config' => Illuminate\Support\Facades\Config::class,
'Cookie' => Illuminate\Support\Facades\Cookie::class,
'Crypt' => Illuminate\Support\Facades\Crypt::class,

View File

@@ -1,6 +1,5 @@
<?php
use App\Support\Modules\DatabaseActivator;
use Nwidart\Modules\Activators\FileActivator;
return [
@@ -12,18 +11,15 @@ return [
'routes' => 'Http/Routes/web.php',
'routes-api' => 'Http/Routes/api.php',
'routes-admin' => 'Http/Routes/admin.php',
'provider' => 'Providers/AppServiceProvider.php',
'route-provider' => 'Providers/RouteServiceProvider.php',
'event-service-provider' => 'Providers/EventServiceProvider.php',
'views/index' => 'Resources/views/index.blade.php',
'views/index-admin' => 'Resources/views/admin/index.blade.php',
'views/frontend' => 'Resources/views/layouts/frontend.blade.php',
'views/admin' => 'Resources/views/layouts/admin.blade.php',
'listener-test' => 'Listeners/TestEventListener.php',
'controller-index' => 'Http/Controllers/Frontend/IndexController.php',
'controller-api' => 'Http/Controllers/Api/ApiController.php',
'controller-admin' => 'Http/Controllers/Admin/AdminController.php',
'config' => 'Config/config.php',
'scaffold/config' => 'Config/config.php',
'composer' => 'composer.json',
],
'replacements' => [
@@ -31,46 +27,22 @@ return [
'routes' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'routes-api' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'json' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'provider' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'route-provider' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'event-service-provider' => [
'LOWER_NAME',
'STUDLY_NAME',
'MODULE_NAMESPACE',
'CLASS_NAMESPACE',
],
'listener-test' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'views/index' => ['LOWER_NAME', 'STUDLY_NAME'],
'views/index-admin' => ['LOWER_NAME', 'STUDLY_NAME'],
'views/frontend' => ['STUDLY_NAME'],
'views/admin' => ['STUDLY_NAME'],
'controller-index' => [
'MODULE_NAMESPACE',
'STUDLY_NAME',
'CLASS_NAMESPACE',
'LOWER_NAME',
],
'controller-admin' => [
'MODULE_NAMESPACE',
'STUDLY_NAME',
'CLASS_NAMESPACE',
'LOWER_NAME',
],
'controller-api' => [
'MODULE_NAMESPACE',
'STUDLY_NAME',
'CLASS_NAMESPACE',
'LOWER_NAME',
],
'config' => ['STUDLY_NAME'],
'composer' => [
'event-service-provider' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'listener-test' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'views/index' => ['LOWER_NAME'],
'views/index-admin' => ['LOWER_NAME', 'STUDLY_NAME'],
'views/frontend' => ['STUDLY_NAME'],
'views/admin' => ['STUDLY_NAME'],
'controller-admin' => ['MODULE_NAMESPACE', 'STUDLY_NAME', 'CLASS_NAMESPACE', 'LOWER_NAME'],
'controller-api' => ['MODULE_NAMESPACE', 'STUDLY_NAME', 'CLASS_NAMESPACE', 'LOWER_NAME'],
'scaffold/config' => ['STUDLY_NAME'],
'composer' => [
'LOWER_NAME',
'STUDLY_NAME',
'VENDOR',
'AUTHOR_NAME',
'AUTHOR_EMAIL',
'MODULE_NAMESPACE',
'PROVIDER_NAMESPACE',
],
],
'gitkeep' => false,
@@ -80,20 +52,19 @@ return [
'assets' => public_path('modules'),
'migration' => base_path('database/migrations'),
'generator' => [
'config' => ['path' => 'Config', 'generate' => true],
'command' => ['path' => 'Console', 'generate' => true],
'migration' => ['path' => 'Database/migrations', 'generate' => true],
'seeds' => ['path' => 'Database/seeds', 'generate' => true],
'factory' => ['path' => 'Database/factories', 'generate' => true],
'model' => ['path' => 'Models', 'generate' => true],
//'controller' => ['path' => 'Http/Controllers', 'generate' => true],
'config' => ['path' => 'Config', 'generate' => true],
'command' => ['path' => 'Console', 'generate' => true],
'migration' => ['path' => 'Database/migrations', 'generate' => true],
'seeds' => ['path' => 'Database/seeds', 'generate' => true],
'factory' => ['path' => 'Database/factories', 'generate' => true],
'model' => ['path' => 'Models', 'generate' => true],
'controller' => ['path' => 'Http/Controllers', 'generate' => true],
'controller-admin' => ['path' => 'Http/Controllers/Admin', 'generate' => true],
'controller-api' => ['path' => 'Http/Controllers/Api', 'generate' => true],
'controller-index' => ['path' => 'Http/Controllers/Frontend', 'generate' => true],
'filter' => ['path' => 'Http/Middleware', 'generate' => true],
'request' => ['path' => 'Http/Requests', 'generate' => true],
'routes' => ['path' => 'Http/Routes', 'generate' => true],
'provider' => ['path' => 'Providers', 'generate' => false],
'provider' => ['path' => 'Providers', 'generate' => true],
'assets' => ['path' => 'Resources/assets', 'generate' => true],
'lang' => ['path' => 'Resources/lang', 'generate' => true],
'views' => ['path' => 'Resources/views', 'generate' => true],
@@ -153,7 +124,7 @@ return [
'cache' => [
'enabled' => true,
'key' => 'phpvms-modules',
'lifetime' => 0,
'lifetime' => 10,
],
/*
|--------------------------------------------------------------------------
@@ -166,16 +137,13 @@ return [
'translations' => true,
],
'activator' => 'database',
'activator' => 'file',
'activators' => [
'file' => [
'class' => FileActivator::class,
'statuses-file' => config_path('modules_statuses.json'),
'cache-key' => 'activator.installed',
'cache-lifetime' => 0,
],
'database' => [
'class' => DatabaseActivator::class,
'cache-lifetime' => 604800,
],
],
];

View File

@@ -0,0 +1,9 @@
{
"Awards": true,
"Importer": true,
"Installer": true,
"Sample": true,
"Updater": true,
"VMSAcars": true,
"Vacentral": true
}

View File

@@ -106,7 +106,7 @@ return [
* The links to various docs on the documentation site
*/
'docs' => [
'root' => 'https://docs.phpvms.net',
'root' => 'http://docs.phpvms.net',
'cron' => '/installation/cron',
'finances' => '/concepts/finances',
'importing_legacy' => '/installation/importing',

1
modules/.gitignore vendored
View File

@@ -8,4 +8,3 @@
!/Installer
!/Updater
!/Vacentral
!/ModulesManager

View File

@@ -1,71 +0,0 @@
<?php
namespace Modules\Awards\Awards;
use App\Contracts\Award;
use ErrorException;
use Illuminate\Support\Facades\Log;
/**
* All award classes need to extend Award and implement the check() method
* This award is based on the original PilotFlightAwards.php file but
* changes the fields that it checks in the PIREP to confirm the Departure
* and Arrival Airport ICAO codes.
* This award means you can create an award for a pilot that complets a flight
* from one airport to another.
*
* See: https://docs.phpvms.net/developers/awards
*/
class FlightRouteAwards extends Award
{
/**
* Set the name of this award class to make it easier to see when
* assigning to a specific award
*
* @var string
*/
public $name = 'Flight Route Award';
/**
* The description to show under the parameters field, so the admin knows
* what the parameter actually controls. You can leave this blank if there
* isn't a parameter.
*
* @var string
*/
public $param_description = 'Departure Airport ICAO and Arrival Airport ICAO as XXXX:YYYY';
/**
* This method only needs to return a true or false of whether it should be awarded or not.
*
* If no parameter is passed in, just default it to XXXX:YYYY.
*
* @param null|mixed $dptarr
*
* @return bool
*/
public function check($dptarr = null): bool
{
if ($this->user->last_pirep_id === null) {
return false;
}
$dptarr = strtoupper(trim($dptarr));
if (empty($dptarr)) {
Log::error('FlightRouteAwards: empty departure/arrival string');
return false;
}
try {
[$dpt_icao, $arr_icao] = explode(':', $dptarr);
} catch (ErrorException $e) {
Log::error('FlightRouteAwards: Invalid departure/arrival, val="'.$dptarr.'\"');
return false;
}
$dpt = $this->user->last_pirep->dpt_airport_id;
$arr = $this->user->last_pirep->arr_airport_id;
return $dpt === $dpt_icao && $arr === $arr_icao;
}
}

View File

@@ -8,7 +8,7 @@ use App\Contracts\Award;
* Simple example of an awards class, where you can apply an award when a user
* has 100 flights. All award classes need to extend Award and implement the check() method
*
* See: https://docs.phpvms.net/developers/awards
* See: http://docs.phpvms.net/customizing/awards
*/
class PilotFlightAwards extends Award
{

View File

@@ -1,52 +0,0 @@
<?php
namespace Modules\Awards\Awards;
use App\Contracts\Award;
use Log;
/**
* All award classes need to extend Award and implement the check() method
* This award is based on the original PilotFlightAwards.php file but
* checks the Pilots Flight Time (In Minutes).
* This award means you can create an award for a pilot that completes any
* amount of flight time (In Minutes).
*
* See: https://docs.phpvms.net/developers/awards
*/
class PilotHoursAwards extends Award
{
/**
* Set the name of this award class to make it easier to see when
* assigning to a specific award
*
* @var string
*/
public $name = 'Pilot Flight Time';
/**
* The description to show under the parameters field, so the admin knows
* what the parameter actually controls. You can leave this blank if there
* isn't a parameter.
*
* @var string
*/
public $param_description = 'Amount of flight time in Minutes at which to give this award';
/**
* If the user has over N minutes of flights, then we can give them this award.
*
* @param int|null $flight_minutes The parameters passed in from the UI
*
* @return bool
*/
public function check($flight_minutes = null): bool
{
if (!is_int($flight_minutes)) {
Log::error('PilotHourAwards: Flight time "'.$flight_minutes.'" is not a valid flight time');
return false;
}
return $this->user->flight_time >= (int) $flight_minutes;
}
}

View File

@@ -2,7 +2,7 @@
namespace Modules\Awards\Providers;
use App\Contracts\Modules\ServiceProvider;
use Illuminate\Support\ServiceProvider;
class AwardServiceProvider extends ServiceProvider
{

View File

@@ -1,10 +1,10 @@
<?php
namespace App\Console\Commands;
namespace Modules\Importer\Console\Commands;
use App\Contracts\Command;
use App\Services\ImporterService;
use Illuminate\Support\Facades\Log;
use Modules\Importer\Services\ImporterService;
class ImportFromClassicCommand extends Command
{

View File

@@ -1,14 +1,14 @@
<?php
namespace App\Http\Controllers\System;
namespace Modules\Importer\Http\Controllers;
use App\Contracts\Controller;
use App\Services\ImporterService;
use App\Services\Installer\DatabaseService;
use App\Services\Installer\InstallerService;
use App\Support\Utils;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Modules\Importer\Services\ImporterService;
class ImporterController extends Controller
{
@@ -27,11 +27,13 @@ class ImporterController extends Controller
* Show the main page for the importer; show form for the admin email
* and the credentials for the other database
*
* @param \Illuminate\Http\Request $request
*
* @return mixed
*/
public function index()
public function index(Request $request)
{
return view('system.importer.step1-configure');
return view('importer::step1-configure');
}
protected function testDb(Request $request)
@@ -49,7 +51,7 @@ class ImporterController extends Controller
/**
* Check the database connection
*
* @param Request $request
* @param \Illuminate\Http\Request $request
*
* @return mixed
*/
@@ -60,12 +62,12 @@ class ImporterController extends Controller
try {
$this->testDb($request);
} catch (Exception $e) {
} catch (\Exception $e) {
$status = 'danger';
$message = 'Failed! '.$e->getMessage();
}
return view('system.importer.dbtest', [
return view('importer::dbtest', [
'status' => $status,
'message' => $message,
]);
@@ -74,7 +76,7 @@ class ImporterController extends Controller
/**
* The post from the above
*
* @param Request $request
* @param \Illuminate\Http\Request $request
*
* @return mixed
*/
@@ -88,17 +90,17 @@ class ImporterController extends Controller
// Generate the import manifest
$manifest = $this->importerSvc->generateImportManifest();
} catch (Exception $e) {
} catch (\Exception $e) {
Log::error($e->getMessage());
// Send it to run, step1
return view('system.importer.error', [
return view('importer::error', [
'error' => $e->getMessage(),
]);
}
// Send it to run, step1
return view('system.importer.step2-processing', [
return view('importer::step2-processing', [
'manifest' => $manifest,
]);
}
@@ -109,9 +111,9 @@ class ImporterController extends Controller
* stage=STAGE NAME
* start=record_start
*
* @param Request $request
* @param \Illuminate\Http\Request $request
*
* @throws Exception
* @throws \Exception
*
* @return mixed
*/
@@ -134,6 +136,9 @@ class ImporterController extends Controller
*/
public function complete()
{
$installerSvc = app(InstallerService::class);
$installerSvc->disableInstallerModules();
return redirect('/');
}
}

View File

@@ -0,0 +1,102 @@
<?php
namespace Modules\Importer\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Modules\Importer\Console\Commands\ImportFromClassicCommand;
class ImporterServiceProvider extends ServiceProvider
{
/**
* Boot the application events.
*/
public function boot()
{
$this->registerCommands();
$this->registerRoutes();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
}
protected function registerCommands()
{
$this->commands([
ImportFromClassicCommand::class,
]);
}
/**
* Register the routes
*/
protected function registerRoutes()
{
Route::group([
'as' => 'importer.',
'prefix' => 'importer',
'middleware' => ['web'],
'namespace' => 'Modules\Importer\Http\Controllers',
], function () {
Route::get('/', 'ImporterController@index')->name('index');
Route::post('/config', 'ImporterController@config')->name('config');
Route::post('/dbtest', 'ImporterController@dbtest')->name('dbtest');
// Run the actual importer process. Additional middleware
Route::post('/run', 'ImporterController@run')->middleware('api')->name('run');
Route::post('/complete', 'ImporterController@complete')->name('complete');
});
}
/**
* Register config.
*/
protected function registerConfig()
{
$this->mergeConfigFrom(__DIR__.'/../Config/config.php', 'importer');
}
/**
* Register views.
*/
public function registerViews()
{
$viewPath = resource_path('views/modules/importer');
$sourcePath = __DIR__.'/../Resources/views';
$this->publishes([$sourcePath => $viewPath], 'views');
$paths = array_map(
function ($path) {
return $path.'/modules/importer';
},
\Config::get('view.paths')
);
$paths[] = $sourcePath;
$this->loadViewsFrom($paths, 'importer');
}
/**
* Register translations.
*/
public function registerTranslations()
{
$langPath = resource_path('lang/modules/importer');
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, 'importer');
} else {
$this->loadTranslationsFrom(__DIR__.'/../Resources/lang', 'importer');
}
}
/**
* Get the services provided by the provider.
*/
public function provides(): array
{
return [];
}
}

View File

@@ -53,7 +53,7 @@
</div>
<div class="card card-login card-plain" style="background: #FFF">
<div class="card-body">
@include('system.updater.flash.message')
@include('importer::flash.message')
@yield('content')
</div>
</div>

View File

@@ -1,4 +1,4 @@
@extends('system.importer.app')
@extends('importer::app')
@section('title', 'Import Completed!')
@section('content')

View File

@@ -1,4 +1,4 @@
@extends('system.importer.app')
@extends('importer::app')
@section('title', 'Import Error!')
@section('content')

View File

@@ -1,4 +1,4 @@
@extends('system.importer.app')
@extends('importer::app')
@section('title', 'Import Configuration')
@section('content')

View File

@@ -1,4 +1,4 @@
@extends('system.importer.app')
@extends('importer::app')
@section('title', 'Import Configuration')
@section('content')

View File

@@ -1,16 +1,15 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services;
use App\Services\ImporterService;
use App\Services\Installer\LoggerTrait;
use App\Utils\IdMapper;
use App\Utils\ImporterDB;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
use Modules\Importer\Utils\IdMapper;
use Modules\Importer\Utils\ImporterDB;
abstract class BaseImporter
{
@@ -21,7 +20,7 @@ abstract class BaseImporter
/**
* Holds the connection to the legacy database
*
* @var ImporterDB
* @var \Modules\Importer\Utils\ImporterDB
*/
protected $db;
@@ -110,7 +109,6 @@ abstract class BaseImporter
*/
public function getColumns(): array
{
return [];
}
/**
@@ -120,7 +118,9 @@ abstract class BaseImporter
*/
protected function parseDate($date)
{
return Carbon::parse($date);
$carbon = Carbon::parse($date);
return $carbon;
}
/**

View File

@@ -1,25 +1,25 @@
<?php
namespace App\Services;
namespace Modules\Importer\Services;
use App\Contracts\Service;
use App\Repositories\KvpRepository;
use App\Services\Importers\AircraftImporter;
use App\Services\Importers\AirlineImporter;
use App\Services\Importers\AirportImporter;
use App\Services\Importers\ClearDatabase;
use App\Services\Importers\ExpenseImporter;
use App\Services\Importers\FinalizeImporter;
use App\Services\Importers\FlightImporter;
use App\Services\Importers\GroupImporter;
use App\Services\Importers\LedgerImporter;
use App\Services\Importers\PirepImporter;
use App\Services\Importers\RankImport;
use App\Services\Importers\SettingsImporter;
use App\Services\Importers\UserImport;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Modules\Importer\Services\Importers\AircraftImporter;
use Modules\Importer\Services\Importers\AirlineImporter;
use Modules\Importer\Services\Importers\AirportImporter;
use Modules\Importer\Services\Importers\ClearDatabase;
use Modules\Importer\Services\Importers\ExpenseImporter;
use Modules\Importer\Services\Importers\FinalizeImporter;
use Modules\Importer\Services\Importers\FlightImporter;
use Modules\Importer\Services\Importers\GroupImporter;
use Modules\Importer\Services\Importers\LedgerImporter;
use Modules\Importer\Services\Importers\PirepImporter;
use Modules\Importer\Services\Importers\RankImport;
use Modules\Importer\Services\Importers\SettingsImporter;
use Modules\Importer\Services\Importers\UserImport;
class ImporterService extends Service
{
@@ -110,7 +110,7 @@ class ImporterService extends Service
$manifest = [];
foreach ($this->importList as $importerKlass) {
/** @var BaseImporter $importer */
/** @var \Modules\Importer\Services\BaseImporter $importer */
$importer = new $importerKlass();
$manifest = array_merge($manifest, $importer->getManifest());
}
@@ -130,11 +130,11 @@ class ImporterService extends Service
*/
public function run($importer, $start = 0)
{
if (!in_array($importer, $this->importList, true)) {
if (!in_array($importer, $this->importList)) {
throw new Exception('Unknown importer "'.$importer.'"');
}
/** @var $importerInst BaseImporter */
/** @var $importerInst \Modules\Importer\Services\BaseImporter */
$importerInst = new $importer();
try {

View File

@@ -1,10 +1,11 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services\Importers;
use App\Models\Aircraft;
use App\Models\Airline;
use App\Models\Subfleet;
use Modules\Importer\Services\BaseImporter;
class AircraftImporter extends BaseImporter
{
@@ -25,11 +26,11 @@ class AircraftImporter extends BaseImporter
// See if there is an airline column
$columns = $this->db->getColumns($this->table);
if (in_array('airline', $columns, true)) {
if (in_array('airline', $columns)) {
$fields[] = 'airline';
}
if (in_array('location', $columns, true)) {
if (in_array('location', $columns)) {
$fields[] = 'location';
}

View File

@@ -1,9 +1,10 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services\Importers;
use App\Models\Airline;
use Illuminate\Support\Facades\Log;
use Modules\Importer\Services\BaseImporter;
class AirlineImporter extends BaseImporter
{

View File

@@ -1,10 +1,11 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services\Importers;
use App\Models\Airport;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Log;
use Modules\Importer\Services\BaseImporter;
class AirportImporter extends BaseImporter
{
@@ -21,34 +22,19 @@ class AirportImporter extends BaseImporter
'lat',
'lng',
'hub',
'ground_handling_cost',
'fuel_jeta_cost',
];
$count = 0;
$rows = $this->db->readRows($this->table, $this->idField, $start, $fields);
foreach ($rows as $row) {
$ground_handling_cost = (float) $row->ground_handling_cost;
$fuel_jetA_cost = (float) $row->fuel_jeta_cost;
if ($ground_handling_cost === null && $ground_handling_cost !== 0) {
$ground_handling_cost = (float) setting('general.default_ground_handling_cost');
}
if ($fuel_jetA_cost === null && $fuel_jetA_cost !== 0) {
$fuel_jetA_cost = (float) setting('general.default_jetA_fuel_cost');
}
$attrs = [
'id' => trim($row->icao),
'icao' => trim($row->icao),
'name' => $row->name,
'country' => $row->country,
'lat' => $row->lat,
'lon' => $row->lng,
'hub' => $row->hub,
'ground_handling_cost' => $ground_handling_cost,
'fuel_jeta_cost' => $fuel_jetA_cost,
'id' => trim($row->icao),
'icao' => trim($row->icao),
'name' => $row->name,
'country' => $row->country,
'lat' => $row->lat,
'lon' => $row->lng,
'hub' => $row->hub,
];
$w = ['id' => $attrs['id']];
@@ -73,6 +59,5 @@ class AirportImporter extends BaseImporter
}
$this->info('Imported '.$count.' airports');
return true;
}
}

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services\Importers;
use App\Models\Acars;
use App\Models\Aircraft;
@@ -17,10 +17,12 @@ use App\Models\JournalTransaction;
use App\Models\Ledger;
use App\Models\News;
use App\Models\Pirep;
use App\Models\Role;
use App\Models\Subfleet;
use App\Models\User;
use App\Models\UserAward;
use Illuminate\Support\Facades\DB;
use Modules\Importer\Services\BaseImporter;
class ClearDatabase extends BaseImporter
{

View File

@@ -1,9 +1,10 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services\Importers;
use App\Models\Enums\ExpenseType;
use App\Models\Expense;
use Modules\Importer\Services\BaseImporter;
class ExpenseImporter extends BaseImporter
{

View File

@@ -1,12 +1,12 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services\Importers;
use App\Models\Airline;
use App\Models\Expense;
use App\Services\FinanceService;
use App\Support\Money;
use Prettus\Validator\Exceptions\ValidatorException;
use Modules\Importer\Services\BaseImporter;
class ExpenseLogImporter extends BaseImporter
{
@@ -15,7 +15,7 @@ class ExpenseLogImporter extends BaseImporter
/**
* {@inheritdoc}
*
* @throws ValidatorException
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function run($start = 0)
{

View File

@@ -1,10 +1,11 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services\Importers;
use App\Models\User;
use App\Services\AircraftService;
use App\Services\UserService;
use Modules\Importer\Services\BaseImporter;
class FinalizeImporter extends BaseImporter
{

View File

@@ -1,8 +1,9 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services\Importers;
use App\Models\Flight;
use Modules\Importer\Services\BaseImporter;
class FlightImporter extends BaseImporter
{

View File

@@ -1,11 +1,12 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services\Importers;
use App\Models\Permission;
use App\Models\Role;
use App\Services\RoleService;
use Illuminate\Support\Facades\Log;
use Modules\Importer\Services\BaseImporter;
/**
* Imports the groups into the permissions feature(s)
@@ -114,7 +115,7 @@ class GroupImporter extends BaseImporter
$permName = $this->legacy_to_permission[$legacy_name];
if ($permName === 'admin') {
foreach ($permMappings as $name => $value) {
if (!in_array($value, $permissions, true)) {
if (!in_array($value, $permissions)) {
$permissions[] = $value;
}
}
@@ -123,7 +124,7 @@ class GroupImporter extends BaseImporter
}
$permMapId = $permMappings[$permName];
if (!in_array($permMapId, $permissions, true)) {
if (!in_array($permMapId, $permissions)) {
$permissions[] = $permMapId;
}
} catch (\Exception $e) {

View File

@@ -1,10 +1,11 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services\Importers;
use App\Models\Pirep;
use App\Services\FinanceService;
use App\Support\Money;
use Modules\Importer\Services\BaseImporter;
class LedgerImporter extends BaseImporter
{

View File

@@ -1,11 +1,12 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services\Importers;
use App\Models\Enums\FlightType;
use App\Models\Enums\PirepSource;
use App\Models\Enums\PirepState;
use App\Models\Pirep;
use Modules\Importer\Services\BaseImporter;
class PirepImporter extends BaseImporter
{
@@ -36,7 +37,7 @@ class PirepImporter extends BaseImporter
// See if there's a flightlevel column, export that if there is
$columns = $this->db->getColumns($this->table);
if (in_array('flightlevel', $columns, true)) {
if (in_array('flightlevel', $columns)) {
$fields[] = 'flightlevel';
}
@@ -143,7 +144,7 @@ class PirepImporter extends BaseImporter
];
$old_state = (int) $old_state;
if (!in_array($old_state, $map, true)) {
if (!in_array($old_state, $map)) {
return PirepState::PENDING;
}

View File

@@ -1,8 +1,9 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services\Importers;
use App\Models\Rank;
use Modules\Importer\Services\BaseImporter;
class RankImport extends BaseImporter
{

View File

@@ -1,8 +1,9 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services\Importers;
use App\Repositories\SettingRepository;
use Modules\Importer\Services\BaseImporter;
class SettingsImporter extends BaseImporter
{

View File

@@ -1,8 +1,9 @@
<?php
namespace App\Services\Importers;
namespace Modules\Importer\Services\Importers;
use App\Models\Enums\UserState;
use App\Models\Role;
use App\Models\User;
use App\Services\UserService;
use App\Support\Units\Time;
@@ -10,6 +11,7 @@ use App\Support\Utils;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Modules\Importer\Services\BaseImporter;
class UserImport extends BaseImporter
{

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Utils;
namespace Modules\Importer\Utils;
use App\Contracts\Service;
use Spatie\Valuestore\Valuestore;

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Utils;
namespace Modules\Importer\Utils;
use Illuminate\Support\Facades\Log;
use PDO;

View File

@@ -0,0 +1,29 @@
{
"name": "phpvms/importer",
"type": "laravel-library",
"description": "The importer module for phpVMS",
"authors": [
{
"name": "Nabeel Shahzad",
"email": ""
}
],
"require": {
"composer/installers": "~1.0"
},
"extra": {
"laravel": {
"providers": [
"Modules\\Importer\\Providers\\ImporterServiceProvider"
],
"aliases": {
}
}
},
"autoload": {
"psr-4": {
"Modules\\Importer\\": ""
}
}
}

View File

@@ -0,0 +1,14 @@
{
"name": "Importer",
"alias": "importer",
"description": "",
"keywords": [],
"active": 1,
"order": 0,
"providers": [
"Modules\\Importer\\Providers\\ImporterServiceProvider"
],
"aliases": {},
"files": [],
"requires": []
}

Some files were not shown because too many files have changed in this diff Show More