7.0.0-beta3 Release (#541)
* 391 Notification refactorings (#441) * Refactor notifications to allow easier plugins * Notification refactoring * Formatting * Move news to NewsService; cleanup of events * More refactoring; added send email out for news item and the template * Formatting * Formatting * Fix missing newsRepo (#445) * Refactor and add importer to Installer module #443 (#444) * Refactor and add importer to Installer module #443 * Refactor for finances to use in import * Import groups into roles * Formatting * Formatting * Add interface in installer for import * Notes about importing * Check for installer folder * Formatting * Fix pirep->user mapping * Unused import * Formatting * Replace importer with AJAX powered; better error handling #443 (#447) * Replace importer with AJAX powered; better error handling #443 * Formatting * Fix command line importer * Remove bootstrap cache (#448) * Cleanup the bootstrap/cache directory when packaging * Fix removal of bootstrap cache * Formatting * Stricter checks on ACARS API data (#451) * Stricter checks on ACARS API data * More checks * Fix for flight_number check forcing to exist * Allow nullable on flight_id * Avoid proc_open use #455 (#456) * Use PhpExecutableFinder() closes #457 #458 (#460) * Use DateTimeZone instead of int for creating datetime closes #461 * Fix CSV imports giving Storage class not found #454 (#462) * Fix CSV imports giving Storage class not found #454 * Update yarn files for security alert * Add PHP 7.4 support (#464) * Add PHP 7.4 to build matrix * DB fix * YAML parser fix in test data * Show versions * Package updates * Track used ICAOs * 7.4 METAR parsing fix * METAR parser fix * Formatting * Add meters to response units * Call instance for unit conversion * Return value * Catch exception for unknown quantity * Comment fix * Formatting * METAR parsing fixes on PHP 7.4 * Package updates * More random airport ID * More random airport ID * Properly disable toolbar * Semver written out to version file * Use dev as default identifier * Fix BindingResolutionError when debug toolbar isn't present (#465) * Fix BindingResolutionError when debug toolbar isn't present * Formatting * Split the importer module out from the installer module (#468) * Split the importer module out from the installer module * Cleanup of unused imports * Move updater into separate module #453 * Remove unused imports/formatting * Disable the install and importer modules at the end of the setup * Unused imports; update IJ style * test explicit stage for php+mysql * add more to matrix * Add different MariaDB versions * undo * Cleanup Model doc * Pilots cannot use the dashboard or flights without admin rights (#481) * Use auth middleware instead of specific groups for logged in state * Auth check for admin access * Check user admin access for updates * Formatting * Allow nullable field and calculate distance if nulled for flight import #478 (#482) * Check for no roles being attached #480 (#483) * Return the flight fares if there are no subfleet fares #488 (#489) * Return the flight fares if there are no subfleet fares #488 * Formatting * Formatting * Account for units when entering fuel amounts #493 * Search for ICAO not working properly (#496) * /flights and /flights/search direct to the same endpoint * Properly set the distance/planned_distance on save (#497) * 491 Installation Error (#495) * Disable CSRF token * Add error handling around looking up the theme and set a default * Note about logs in issue template * Formatting * Fix GeoService errors when viewing PIREP #498 (#499) * Add new command to export a specific PIREP for debugging (#501) * Set a default model value for airports on PIREP (#500) * Set a default model value for airports on PIREP * Fix airport icao reference * Default airport models * Catch broader exception writing out config files #491 * style * Add reference to docs on doc site (#502) * Properly create/update rows importing #486 (#503) * Add base Dockerfile for Dockerhub builds (#504) * New subfleet not being attached to an airline on import #479 (#505) * Fix subfleet not being attached to an airline on creation in import #479 * Call airline name with optional() around subfleet * Minor cleanup * Search flights by subfleet #484 (#506) * API level search of flights #484 * Add Subfleet to flights page for search * Make the fuel used optional (#512) * Add make to Docker container * Add getRootDomain() to Utils (#514) * Show admin dropdown for admin-access ability (#515) * Show admin dropdown for admin-access ability closes #509 * Formatting * Check user permissions on the routes #508 (#516) * Check user permissions on the routes #508 * Formatting * Return default value on exception for setting() * Correct text for no subfleets #507 (#518) * Add a public_url() helper #513 (#519) * Reduce number of queries for update check (#520) * Try to clear caches before updating (#522) * Try to clear caches before updating * Add clear-compiled to maintenance cache list * Formatting * Set PIREPs page to public (#526) Set PIREPs page to public * Fix live and route map errors #527 (#528) * Add menu bar for mobile (#529) * Format all blade templates to 2 spaces #530 (#531) * Fix PIREP edit endpoint closes #533 (#534) * Fix import during flight cron #532 (#535) * PIREPS resource except for show (#536) * Use optional() around the airport fields (#537) * Use optional() around the airport fields * Add null-coalesce around full_name * Add link to download ACARS config from profile (#539) * Add link to download ACARS config from profile * Formatting * Update xml config file template (#540)
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Services;
|
||||
|
||||
use App\Contracts\Service;
|
||||
use App\Support\ClassLoader;
|
||||
use function get_class;
|
||||
use Nwidart\Modules\Facades\Module;
|
||||
|
||||
class AwardService extends Service
|
||||
@@ -18,9 +19,9 @@ class AwardService extends Service
|
||||
$awards = [];
|
||||
$formatted_awards = [];
|
||||
|
||||
// Find the awards in the app/Awards directory
|
||||
$classes = ClassLoader::getClassesInPath(app_path('/Awards'));
|
||||
$awards = array_merge($awards, $classes);
|
||||
// Find the awards in the modules/Awards directory
|
||||
// $classes = ClassLoader::getClassesInPath(module_path('Awards'));
|
||||
// $awards = array_merge($awards, $classes);
|
||||
|
||||
// Look throughout all the other modules, in the module/{MODULE}/Awards directory
|
||||
foreach (Module::all() as $module) {
|
||||
@@ -33,7 +34,7 @@ class AwardService extends Service
|
||||
}
|
||||
|
||||
foreach ($awards as $award) {
|
||||
$formatted_awards[\get_class($award)] = $award;
|
||||
$formatted_awards[get_class($award)] = $award;
|
||||
}
|
||||
|
||||
return $formatted_awards;
|
||||
|
||||
@@ -8,6 +8,7 @@ use DateTime;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
|
||||
class CronService extends Service
|
||||
{
|
||||
@@ -26,22 +27,39 @@ class CronService extends Service
|
||||
*/
|
||||
public function getCronPath(): string
|
||||
{
|
||||
$finder = new PhpExecutableFinder();
|
||||
$php_path = $finder->find(false);
|
||||
|
||||
$path = [
|
||||
'cd '.base_path(),
|
||||
'&&',
|
||||
str_replace('-fpm', '', PHP_BINARY),
|
||||
str_replace('-fpm', '', $php_path),
|
||||
'artisan schedule:run',
|
||||
];
|
||||
|
||||
return implode(' ', $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an example cron command that runs every minute
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCronExecString(): string
|
||||
{
|
||||
return implode(' ', [
|
||||
'* * * * *',
|
||||
$this->getCronPath(),
|
||||
'>> /dev/null 2>&1',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the last time the cron was run in the kvp repo
|
||||
*/
|
||||
public function updateLastRunTime()
|
||||
{
|
||||
$dt = new DateTime('now', DateTimeZone::UTC);
|
||||
$dt = new DateTime('now', new DateTimeZone('UTC'));
|
||||
$this->kvpRepo->save('cron_last_run', $dt->format(DateTime::ISO8601));
|
||||
}
|
||||
|
||||
@@ -60,7 +78,7 @@ class CronService extends Service
|
||||
|
||||
try {
|
||||
$dt = DateTime::createFromFormat(DateTime::ISO8601, $last_run);
|
||||
$dt_now = new DateTime('now', DateTimeZone::UTC);
|
||||
$dt_now = new DateTime('now', new DateTimeZone('UTC'));
|
||||
} catch (Exception $e) {
|
||||
Log::error('Error checking for cron problem: '.$e->getMessage());
|
||||
return true;
|
||||
|
||||
@@ -34,7 +34,14 @@ class FareService extends Service
|
||||
$flight_fares = $this->getForFlight($flight);
|
||||
}
|
||||
|
||||
if (empty($subfleet)) {
|
||||
return $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
|
||||
@@ -60,7 +67,7 @@ class FareService extends Service
|
||||
protected function getFares($fare)
|
||||
{
|
||||
if (filled($fare->pivot->price)) {
|
||||
if (substr_count($fare->pivot->price, '%', -1)) {
|
||||
if (strpos($fare->pivot->price, '%', -1) !== false) {
|
||||
$fare->price = Math::addPercent($fare->price, $fare->pivot->price);
|
||||
} else {
|
||||
$fare->price = $fare->pivot->price;
|
||||
@@ -68,7 +75,7 @@ class FareService extends Service
|
||||
}
|
||||
|
||||
if (filled($fare->pivot->cost)) {
|
||||
if (substr_count($fare->pivot->cost, '%', -1)) {
|
||||
if (strpos($fare->pivot->cost, '%', -1) !== false) {
|
||||
$fare->cost = Math::addPercent($fare->cost, $fare->pivot->cost);
|
||||
} else {
|
||||
$fare->cost = $fare->pivot->cost;
|
||||
@@ -76,7 +83,7 @@ class FareService extends Service
|
||||
}
|
||||
|
||||
if (filled($fare->pivot->capacity)) {
|
||||
if (substr_count($fare->pivot->capacity, '%', -1)) {
|
||||
if (strpos($fare->pivot->capacity, '%', -1) !== false) {
|
||||
$fare->capacity = Math::addPercent($fare->capacity, $fare->pivot->capacity);
|
||||
} else {
|
||||
$fare->capacity = $fare->pivot->capacity;
|
||||
|
||||
@@ -11,17 +11,16 @@ use App\Models\Pirep;
|
||||
use App\Repositories\ExpenseRepository;
|
||||
use App\Repositories\JournalRepository;
|
||||
use App\Services\FareService;
|
||||
use App\Services\FinanceService;
|
||||
use App\Support\Math;
|
||||
use App\Support\Money;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class FinanceService
|
||||
*/
|
||||
class PirepFinanceService extends Service
|
||||
{
|
||||
private $expenseRepo;
|
||||
private $fareSvc;
|
||||
private $financeSvc;
|
||||
private $journalRepo;
|
||||
|
||||
/**
|
||||
@@ -30,15 +29,18 @@ class PirepFinanceService extends Service
|
||||
* @param ExpenseRepository $expenseRepo
|
||||
* @param FareService $fareSvc
|
||||
* @param JournalRepository $journalRepo
|
||||
* @param FinanceService $financeSvc
|
||||
*/
|
||||
public function __construct(
|
||||
ExpenseRepository $expenseRepo,
|
||||
FareService $fareSvc,
|
||||
FinanceService $financeSvc,
|
||||
JournalRepository $journalRepo
|
||||
) {
|
||||
$this->expenseRepo = $expenseRepo;
|
||||
$this->fareSvc = $fareSvc;
|
||||
$this->journalRepo = $journalRepo;
|
||||
$this->financeSvc = $financeSvc;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,13 +151,11 @@ class PirepFinanceService extends Service
|
||||
Log::info('Finance: Fuel cost, (fuel='.$fuel_used.', cost='.$ap->fuel_jeta_cost.') D='
|
||||
.$debit->getAmount());
|
||||
|
||||
$this->journalRepo->post(
|
||||
$this->financeSvc->debitFromJournal(
|
||||
$pirep->airline->journal,
|
||||
null,
|
||||
$debit,
|
||||
$pirep,
|
||||
'Fuel Cost ('.$ap->fuel_jeta_cost.'/'.config('phpvms.internal_units.fuel').')',
|
||||
null,
|
||||
'Fuel',
|
||||
'fuel'
|
||||
);
|
||||
@@ -194,13 +194,11 @@ class PirepFinanceService extends Service
|
||||
$debit = Money::createFromAmount($cost_per_min * $block_time);
|
||||
Log::info('Finance: Subfleet Block Hourly, D='.$debit->getAmount());
|
||||
|
||||
$this->journalRepo->post(
|
||||
$this->financeSvc->debitFromJournal(
|
||||
$pirep->airline->journal,
|
||||
null,
|
||||
$debit,
|
||||
$pirep,
|
||||
'Subfleet '.$sf->type.': Block Time Cost',
|
||||
null,
|
||||
'Subfleet '.$sf->type,
|
||||
'subfleet'
|
||||
);
|
||||
@@ -265,13 +263,11 @@ class PirepFinanceService extends Service
|
||||
$journal = $pirep->user->journal;
|
||||
}
|
||||
|
||||
$this->journalRepo->post(
|
||||
$this->financeSvc->debitFromJournal(
|
||||
$journal,
|
||||
null,
|
||||
$debit,
|
||||
$pirep,
|
||||
$memo,
|
||||
null,
|
||||
$transaction_group,
|
||||
strtolower($klass)
|
||||
);
|
||||
@@ -320,13 +316,11 @@ class PirepFinanceService extends Service
|
||||
|
||||
$debit = Money::createFromAmount($expense->amount);
|
||||
|
||||
$this->journalRepo->post(
|
||||
$this->financeSvc->debitFromJournal(
|
||||
$pirep->airline->journal,
|
||||
null,
|
||||
$debit,
|
||||
$pirep,
|
||||
'Expense: '.$expense->name,
|
||||
null,
|
||||
$expense->transaction_group ?? 'Expenses',
|
||||
'expense'
|
||||
);
|
||||
@@ -347,13 +341,12 @@ class PirepFinanceService extends Service
|
||||
{
|
||||
$ground_handling_cost = $this->getGroundHandlingCost($pirep);
|
||||
Log::info('Finance: PIREP: '.$pirep->id.'; ground handling: '.$ground_handling_cost);
|
||||
$this->journalRepo->post(
|
||||
|
||||
$this->financeSvc->debitFromJournal(
|
||||
$pirep->airline->journal,
|
||||
null,
|
||||
Money::createFromAmount($ground_handling_cost),
|
||||
$pirep,
|
||||
'Ground Handling',
|
||||
null,
|
||||
'Ground Handling',
|
||||
'ground_handling'
|
||||
);
|
||||
@@ -378,24 +371,20 @@ class PirepFinanceService extends Service
|
||||
Log::info('Finance: PIREP: '.$pirep->id
|
||||
.'; pilot pay: '.$pilot_pay_rate.', total: '.$pilot_pay);
|
||||
|
||||
$this->journalRepo->post(
|
||||
$this->financeSvc->debitFromJournal(
|
||||
$pirep->airline->journal,
|
||||
null,
|
||||
$pilot_pay,
|
||||
$pirep,
|
||||
$memo,
|
||||
null,
|
||||
'Pilot Pay',
|
||||
'pilot_pay'
|
||||
);
|
||||
|
||||
$this->journalRepo->post(
|
||||
$this->financeSvc->creditToJournal(
|
||||
$pirep->user->journal,
|
||||
$pilot_pay,
|
||||
null,
|
||||
$pirep,
|
||||
$memo,
|
||||
null,
|
||||
'Pilot Pay',
|
||||
'pilot_pay'
|
||||
);
|
||||
|
||||
@@ -8,23 +8,22 @@ use App\Models\Enums\ExpenseType;
|
||||
use App\Models\Expense;
|
||||
use App\Models\JournalTransaction;
|
||||
use App\Repositories\JournalRepository;
|
||||
use App\Services\FinanceService;
|
||||
use App\Support\Money;
|
||||
use Log;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Process all of the daily expenses and charge them
|
||||
*/
|
||||
class RecurringFinanceService extends Service
|
||||
{
|
||||
private $financeSvc;
|
||||
private $journalRepo;
|
||||
|
||||
/**
|
||||
* RecurringFinanceService constructor.
|
||||
*
|
||||
* @param JournalRepository $journalRepo
|
||||
*/
|
||||
public function __construct(JournalRepository $journalRepo)
|
||||
public function __construct(JournalRepository $journalRepo, FinanceService $financeSvc)
|
||||
{
|
||||
$this->financeSvc = $financeSvc;
|
||||
$this->journalRepo = $journalRepo;
|
||||
}
|
||||
|
||||
@@ -87,10 +86,8 @@ class RecurringFinanceService extends Service
|
||||
/**
|
||||
* Run all of the daily expense/financials
|
||||
*
|
||||
* @param int $type
|
||||
* @param string $type
|
||||
*
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
*/
|
||||
public function processExpenses($type = ExpenseType::DAILY): void
|
||||
@@ -101,7 +98,7 @@ class RecurringFinanceService extends Service
|
||||
if ($type === ExpenseType::DAILY) {
|
||||
$tag = 'expenses_daily';
|
||||
} elseif ($type === ExpenseType::MONTHLY) {
|
||||
$tag === 'expenses_monthly';
|
||||
$tag = 'expenses_monthly';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +119,7 @@ class RecurringFinanceService extends Service
|
||||
];
|
||||
|
||||
$found = JournalTransaction::where($w)
|
||||
->whereDate('post_date', '=', \Carbon::now('UTC')->toDateString())
|
||||
->whereDate('post_date', '=', Carbon::now('UTC')->toDateString())
|
||||
->count(['id']);
|
||||
|
||||
if ($found > 0) {
|
||||
@@ -132,13 +129,11 @@ class RecurringFinanceService extends Service
|
||||
|
||||
[$memo, $ta_group] = $this->getMemoAndGroup($expense);
|
||||
|
||||
$this->journalRepo->post(
|
||||
$this->financeSvc->debitFromJournal(
|
||||
$journal,
|
||||
null,
|
||||
Money::createFromAmount($amount),
|
||||
$expense,
|
||||
$memo,
|
||||
null,
|
||||
$ta_group,
|
||||
$tag
|
||||
);
|
||||
|
||||
@@ -4,11 +4,125 @@ namespace App\Services;
|
||||
|
||||
use App\Contracts\Service;
|
||||
use App\Models\Airline;
|
||||
use App\Models\Journal;
|
||||
use App\Models\JournalTransaction;
|
||||
use App\Repositories\AirlineRepository;
|
||||
use App\Repositories\JournalRepository;
|
||||
use App\Support\Dates;
|
||||
use App\Support\Money;
|
||||
|
||||
class FinanceService extends Service
|
||||
{
|
||||
private $airlineRepo;
|
||||
private $journalRepo;
|
||||
|
||||
public function __construct(
|
||||
AirlineRepository $airlineRepo,
|
||||
JournalRepository $journalRepo
|
||||
) {
|
||||
$this->airlineRepo = $airlineRepo;
|
||||
$this->journalRepo = $journalRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Credit some amount to a given journal
|
||||
* E.g, some amount for expenses or ground handling fees, etc. Example, to pay a user a dollar
|
||||
* for a pirep:
|
||||
*
|
||||
* creditToJournal($user->journal, new Money(1000), $pirep, 'Payment', 'pirep', 'payment');
|
||||
*
|
||||
* @param \App\Models\Journal $journal
|
||||
* @param Money $amount
|
||||
* @param \Illuminate\Database\Eloquent\Model $reference
|
||||
* @param string $memo
|
||||
* @param string $transaction_group
|
||||
* @param string|array $tag
|
||||
*
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function creditToJournal(
|
||||
Journal $journal,
|
||||
Money $amount,
|
||||
$reference,
|
||||
$memo,
|
||||
$transaction_group,
|
||||
$tag
|
||||
) {
|
||||
return $this->journalRepo->post(
|
||||
$journal,
|
||||
$amount,
|
||||
null,
|
||||
$reference,
|
||||
$memo,
|
||||
null,
|
||||
$transaction_group,
|
||||
$tag
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge some expense for a given PIREP to the airline its file against
|
||||
* E.g, some amount for expenses or ground handling fees, etc.
|
||||
*
|
||||
* @param \App\Models\Journal $journal
|
||||
* @param Money $amount
|
||||
* @param \Illuminate\Database\Eloquent\Model $reference
|
||||
* @param string $memo
|
||||
* @param string $transaction_group
|
||||
* @param string|array $tag
|
||||
*
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function debitFromJournal(
|
||||
Journal $journal,
|
||||
Money $amount,
|
||||
$reference,
|
||||
$memo,
|
||||
$transaction_group,
|
||||
$tag
|
||||
) {
|
||||
return $this->journalRepo->post(
|
||||
$journal,
|
||||
null,
|
||||
$amount,
|
||||
$reference,
|
||||
$memo,
|
||||
null,
|
||||
$transaction_group,
|
||||
$tag
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the transactions for every airline in a given month
|
||||
*
|
||||
* @param string $month In Y-m format
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllAirlineTransactionsBetween($month): array
|
||||
{
|
||||
$between = Dates::getMonthBoundary($month);
|
||||
|
||||
$transaction_groups = [];
|
||||
$airlines = $this->airlineRepo->orderBy('icao')->all();
|
||||
|
||||
// group by the airline
|
||||
foreach ($airlines as $airline) {
|
||||
$transaction_groups[] = $this->getAirlineTransactionsBetween(
|
||||
$airline,
|
||||
$between[0],
|
||||
$between[1]
|
||||
);
|
||||
}
|
||||
|
||||
return $transaction_groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the transactions for an airline between two given dates. Returns an array
|
||||
* with `credits`, `debits` and `transactions` fields, where transactions contains the
|
||||
|
||||
@@ -221,20 +221,12 @@ class GeoService extends Service
|
||||
]);
|
||||
}
|
||||
|
||||
/*
|
||||
* @var $point \App\Models\Acars
|
||||
*/
|
||||
/*foreach ($pirep->acars as $point) {
|
||||
$route->addPoint($point->lat, $point->lon, [
|
||||
'pirep_id' => $pirep->id,
|
||||
'alt' => $point->altitude,
|
||||
]);
|
||||
}*/
|
||||
|
||||
return [
|
||||
// If there is a position update from ACARS, show where it is
|
||||
// Otherwise, just assume it's at the arrival airport currently
|
||||
'position' => [
|
||||
'lat' => $pirep->position->lat,
|
||||
'lon' => $pirep->position->lon,
|
||||
'lat' => optional($pirep->position)->lat ?? $pirep->arr_airport->lat,
|
||||
'lon' => optional($pirep->position)->lon ?? $pirep->arr_airport->lon,
|
||||
],
|
||||
'line' => $route->getLine(),
|
||||
'points' => $route->getPoints(),
|
||||
@@ -299,17 +291,17 @@ class GeoService extends Service
|
||||
$route = new GeoJson();
|
||||
|
||||
//# Departure Airport
|
||||
$route->addPoint($flight->dpt_airport->lat, $flight->dpt_airport->lon, [
|
||||
'name' => $flight->dpt_airport->icao,
|
||||
'popup' => $flight->dpt_airport->full_name,
|
||||
$route->addPoint(optional($flight->dpt_airport)->lat, optional($flight->dpt_airport)->lon, [
|
||||
'name' => $flight->dpt_airport_id,
|
||||
'popup' => optional($flight->dpt_airport)->full_name ?? $flight->dpt_airport_id,
|
||||
'icon' => 'airport',
|
||||
]);
|
||||
|
||||
if ($flight->route) {
|
||||
$all_route_points = $this->getCoordsFromRoute(
|
||||
$flight->dpt_airport->icao,
|
||||
$flight->arr_airport->icao,
|
||||
[$flight->dpt_airport->lat, $flight->dpt_airport->lon],
|
||||
$flight->dpt_airport_id,
|
||||
$flight->arr_airport_id,
|
||||
[optional($flight->dpt_airport)->lat, optional($flight->dpt_airport)->lon],
|
||||
$flight->route
|
||||
);
|
||||
|
||||
@@ -323,9 +315,9 @@ class GeoService extends Service
|
||||
}
|
||||
}
|
||||
|
||||
$route->addPoint($flight->arr_airport->lat, $flight->arr_airport->lon, [
|
||||
'name' => $flight->arr_airport->icao,
|
||||
'popup' => $flight->arr_airport->full_name,
|
||||
$route->addPoint(optional($flight->arr_airport)->lat, optional($flight->arr_airport)->lon, [
|
||||
'name' => $flight->arr_airport_id,
|
||||
'popup' => optional($flight->arr_airport)->full_name ?? $flight->arr_airport_id,
|
||||
'icon' => 'airport',
|
||||
]);
|
||||
|
||||
@@ -350,9 +342,9 @@ class GeoService extends Service
|
||||
/*
|
||||
* PLANNED ROUTE
|
||||
*/
|
||||
$planned->addPoint($pirep->dpt_airport->lat, $pirep->dpt_airport->lon, [
|
||||
'name' => $pirep->dpt_airport->icao,
|
||||
'popup' => $pirep->dpt_airport->full_name,
|
||||
$planned->addPoint(optional($pirep->dpt_airport)->lat, optional($pirep->dpt_airport)->lon, [
|
||||
'name' => $pirep->dpt_airport_id,
|
||||
'popup' => optional($pirep->dpt_airport)->full_name ?? $pirep->dpt_airport_id,
|
||||
]);
|
||||
|
||||
$planned_route = $this->acarsRepo->forPirep($pirep->id, AcarsType::ROUTE);
|
||||
@@ -363,9 +355,9 @@ class GeoService extends Service
|
||||
]);
|
||||
}
|
||||
|
||||
$planned->addPoint($pirep->arr_airport->lat, $pirep->arr_airport->lon, [
|
||||
'name' => $pirep->arr_airport->icao,
|
||||
'popup' => $pirep->arr_airport->full_name,
|
||||
$planned->addPoint(optional($pirep->arr_airport)->lat, optional($pirep->arr_airport)->lon, [
|
||||
'name' => $pirep->arr_airport_id,
|
||||
'popup' => optional($pirep->arr_airport)->full_name ?? $pirep->arr_airport_id,
|
||||
'icon' => 'airport',
|
||||
]);
|
||||
|
||||
@@ -382,9 +374,8 @@ class GeoService extends Service
|
||||
}
|
||||
|
||||
return [
|
||||
'planned_rte_points' => $planned->getPoints(),
|
||||
'planned_rte_line' => $planned->getLine(),
|
||||
|
||||
'planned_rte_points' => $planned->getPoints(),
|
||||
'planned_rte_line' => $planned->getLine(),
|
||||
'actual_route_points' => $actual->getPoints(),
|
||||
'actual_route_line' => $actual->getLine(),
|
||||
];
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Services\ImportExport;
|
||||
|
||||
use App\Contracts\ImportExport;
|
||||
use App\Models\Aircraft;
|
||||
use App\Models\Airline;
|
||||
use App\Models\Enums\AircraftState;
|
||||
use App\Models\Enums\AircraftStatus;
|
||||
use App\Models\Subfleet;
|
||||
@@ -32,7 +33,8 @@ class AircraftImporter extends ImportExport
|
||||
];
|
||||
|
||||
/**
|
||||
* Find the subfleet specified, or just create it on the fly
|
||||
* Find the subfleet specified, or just create it on the fly and attach it to the
|
||||
* first airline that's been found
|
||||
*
|
||||
* @param $type
|
||||
*
|
||||
@@ -40,11 +42,12 @@ class AircraftImporter extends ImportExport
|
||||
*/
|
||||
protected function getSubfleet($type)
|
||||
{
|
||||
$subfleet = Subfleet::firstOrCreate([
|
||||
return Subfleet::firstOrCreate([
|
||||
'type' => $type,
|
||||
], ['name' => $type]);
|
||||
|
||||
return $subfleet;
|
||||
], [
|
||||
'name' => $type,
|
||||
'airline_id' => Airline::where('active', true)->first()->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +72,7 @@ class AircraftImporter extends ImportExport
|
||||
|
||||
// Set a default status
|
||||
$row['status'] = trim($row['status']);
|
||||
if ($row['status'] === null || $row['status'] === '') {
|
||||
if (empty($row['status'])) {
|
||||
$row['status'] = AircraftStatus::ACTIVE;
|
||||
}
|
||||
|
||||
@@ -77,12 +80,10 @@ class AircraftImporter extends ImportExport
|
||||
$row['state'] = AircraftState::PARKED;
|
||||
|
||||
// Try to add or update
|
||||
$aircraft = Aircraft::firstOrNew([
|
||||
'registration' => $row['registration'],
|
||||
], $row);
|
||||
|
||||
try {
|
||||
$aircraft->save();
|
||||
Aircraft::updateOrCreate([
|
||||
'registration' => $row['registration'],
|
||||
], $row);
|
||||
} catch (\Exception $e) {
|
||||
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
|
||||
return false;
|
||||
|
||||
@@ -45,12 +45,10 @@ class AirportImporter extends ImportExport
|
||||
$row['id'] = $row['icao'];
|
||||
$row['hub'] = get_truth_state($row['hub']);
|
||||
|
||||
$airport = Airport::firstOrNew([
|
||||
'id' => $row['icao'],
|
||||
], $row);
|
||||
|
||||
try {
|
||||
$airport->save();
|
||||
$airport = Airport::updateOrCreate([
|
||||
'id' => $row['icao'],
|
||||
], $row);
|
||||
} catch (\Exception $e) {
|
||||
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
|
||||
return false;
|
||||
|
||||
@@ -7,7 +7,7 @@ use App\Models\Aircraft;
|
||||
use App\Models\Airport;
|
||||
use App\Models\Expense;
|
||||
use App\Models\Subfleet;
|
||||
use Log;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Import expenses
|
||||
@@ -53,12 +53,10 @@ class ExpenseImporter extends ImportExport
|
||||
$row['active'] = true;
|
||||
}
|
||||
|
||||
$expense = Expense::firstOrNew([
|
||||
'name' => $row['name'],
|
||||
], $row);
|
||||
|
||||
try {
|
||||
$expense->save();
|
||||
$expense = Expense::updateOrCreate([
|
||||
'name' => $row['name'],
|
||||
], $row);
|
||||
} catch (\Exception $e) {
|
||||
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
|
||||
return false;
|
||||
|
||||
@@ -36,13 +36,11 @@ class FareImporter extends ImportExport
|
||||
*/
|
||||
public function import(array $row, $index): bool
|
||||
{
|
||||
// Try to add or update
|
||||
$fare = Fare::firstOrNew([
|
||||
'code' => $row['code'],
|
||||
], $row);
|
||||
|
||||
try {
|
||||
$fare->save();
|
||||
// Try to add or update
|
||||
$fare = Fare::updateOrCreate([
|
||||
'code' => $row['code'],
|
||||
], $row);
|
||||
} catch (\Exception $e) {
|
||||
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
|
||||
return false;
|
||||
|
||||
@@ -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;
|
||||
@@ -37,7 +36,7 @@ class FlightImporter extends ImportExport
|
||||
'dpt_time' => 'nullable',
|
||||
'arr_time' => 'nullable',
|
||||
'level' => 'nullable|integer',
|
||||
'distance' => 'required|numeric',
|
||||
'distance' => 'nullable|numeric',
|
||||
'flight_time' => 'required|integer',
|
||||
'flight_type' => 'required|alpha',
|
||||
'route' => 'nullable',
|
||||
@@ -112,7 +111,7 @@ class FlightImporter extends ImportExport
|
||||
// Check for a valid value
|
||||
$flight_type = $row['flight_type'];
|
||||
if (!array_key_exists($flight_type, FlightType::labels())) {
|
||||
$flight_type = 'J';
|
||||
$flight_type = FlightType::SCHED_PAX;
|
||||
}
|
||||
|
||||
$flight->setAttribute('flight_type', $flight_type);
|
||||
@@ -132,6 +131,14 @@ class FlightImporter extends ImportExport
|
||||
$this->processAirport($row['alt_airport']);
|
||||
}
|
||||
|
||||
// Check/calculate the distance
|
||||
if (empty($row['distance'])) {
|
||||
$row['distance'] = $this->airportSvc->calculateDistance(
|
||||
$row['dpt_airport'],
|
||||
$row['arr_airport']
|
||||
);
|
||||
}
|
||||
|
||||
$this->processSubfleets($flight, $row['subfleets']);
|
||||
$this->processFares($flight, $row['fares']);
|
||||
$this->processFields($flight, $row['fields']);
|
||||
@@ -209,7 +216,7 @@ class FlightImporter extends ImportExport
|
||||
$count = 0;
|
||||
$subfleets = $this->parseMultiColumnValues($col);
|
||||
foreach ($subfleets as $subfleet_type) {
|
||||
$subfleet = Subfleet::firstOrCreate(
|
||||
$subfleet = Subfleet::updateOrCreate(
|
||||
['type' => $subfleet_type],
|
||||
['name' => $subfleet_type]
|
||||
);
|
||||
@@ -239,7 +246,7 @@ class FlightImporter extends ImportExport
|
||||
$fare_attributes = [];
|
||||
}
|
||||
|
||||
$fare = Fare::firstOrCreate(['code' => $fare_code], ['name' => $fare_code]);
|
||||
$fare = Fare::updateOrCreate(['code' => $fare_code], ['name' => $fare_code]);
|
||||
$this->fareSvc->setForFlight($flight, $fare, $fare_attributes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,12 +48,10 @@ class SubfleetImporter extends ImportExport
|
||||
$airline = $this->getAirline($row['airline']);
|
||||
$row['airline_id'] = $airline->id;
|
||||
|
||||
$subfleet = Subfleet::firstOrNew([
|
||||
'type' => $row['type'],
|
||||
], $row);
|
||||
|
||||
try {
|
||||
$subfleet->save();
|
||||
$subfleet = Subfleet::updateOrCreate([
|
||||
'type' => $row['type'],
|
||||
], $row);
|
||||
} catch (\Exception $e) {
|
||||
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
|
||||
return false;
|
||||
@@ -80,7 +78,7 @@ class SubfleetImporter extends ImportExport
|
||||
$fare_attributes = [];
|
||||
}
|
||||
|
||||
$fare = Fare::firstOrCreate(['code' => $fare_code], ['name' => $fare_code]);
|
||||
$fare = Fare::updateOrCreate(['code' => $fare_code], ['name' => $fare_code]);
|
||||
$this->fareSvc->setForSubfleet($subfleet, $fare, $fare_attributes);
|
||||
}
|
||||
}
|
||||
|
||||
69
app/Services/Installer/DatabaseService.php
Normal file
69
app/Services/Installer/DatabaseService.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Installer;
|
||||
|
||||
use App\Contracts\Service;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use PDO;
|
||||
|
||||
class DatabaseService extends Service
|
||||
{
|
||||
/**
|
||||
* Check the PHP version that it meets the minimum requirement
|
||||
*
|
||||
* @param $driver
|
||||
* @param $host
|
||||
* @param $port
|
||||
* @param $name
|
||||
* @param $user
|
||||
* @param $pass
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkDbConnection($driver, $host, $port, $name, $user, $pass)
|
||||
{
|
||||
Log::info('Testing Connection: '.$driver.'::'.$user.':<hidden>@'.$host.':'.$port.';'.$name);
|
||||
|
||||
// TODO: Needs testing
|
||||
if ($driver === 'postgres') {
|
||||
$dsn = "pgsql:host=$host;port=$port;dbname=$name";
|
||||
|
||||
try {
|
||||
$conn = new PDO($dsn, $user, $pass);
|
||||
} catch (\PDOException $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Default MySQL
|
||||
$dsn = "mysql:host=$host;port=$port;dbname=$name";
|
||||
Log::info('Connection string: '.$dsn);
|
||||
|
||||
try {
|
||||
$conn = new PDO($dsn, $user, $pass);
|
||||
} catch (\PDOException $e) {
|
||||
throw $e;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the database by running the migration commands
|
||||
* Only run the setup for sqlite, otherwise, we're assuming
|
||||
* that the MySQL database has already been created
|
||||
*/
|
||||
public function setupDB()
|
||||
{
|
||||
$output = '';
|
||||
|
||||
if (config('database.default') === 'sqlite') {
|
||||
Artisan::call('database:create');
|
||||
$output .= Artisan::output();
|
||||
}
|
||||
|
||||
return trim($output);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Services\Installer;
|
||||
|
||||
use App\Contracts\Service;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Nwidart\Modules\Facades\Module;
|
||||
|
||||
class InstallerService extends Service
|
||||
{
|
||||
@@ -36,4 +38,33 @@ class InstallerService extends Service
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear whatever caches we can by calling Artisan
|
||||
*/
|
||||
public function clearCaches(): void
|
||||
{
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
||||
23
app/Services/Installer/LoggerTrait.php
Normal file
23
app/Services/Installer/LoggerTrait.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Installer;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
trait LoggerTrait
|
||||
{
|
||||
protected function comment($text)
|
||||
{
|
||||
Log::info($text);
|
||||
}
|
||||
|
||||
protected function info($text)
|
||||
{
|
||||
Log::info($text);
|
||||
}
|
||||
|
||||
protected function error($text)
|
||||
{
|
||||
Log::error($text);
|
||||
}
|
||||
}
|
||||
@@ -218,6 +218,7 @@ class SeederService extends Service
|
||||
*/
|
||||
private function settingsSeedsPending(): bool
|
||||
{
|
||||
$all_settings = DB::table('settings')->get();
|
||||
$data = file_get_contents(database_path('/seeds/settings.yml'));
|
||||
$yml = Yaml::parse($data);
|
||||
|
||||
@@ -228,7 +229,7 @@ class SeederService extends Service
|
||||
}
|
||||
|
||||
$id = Setting::formatKey($setting['key']);
|
||||
$row = DB::table('settings')->where('id', $id)->first();
|
||||
$row = $all_settings->firstWhere('id', $id);
|
||||
|
||||
// Doesn't exist in the table, quit early and say there is stuff pending
|
||||
if (!$row) {
|
||||
@@ -236,6 +237,15 @@ class SeederService extends Service
|
||||
return true;
|
||||
}
|
||||
|
||||
// See if any of these column values have changed
|
||||
foreach (['name', 'description'] as $column) {
|
||||
$currVal = $row->{$column};
|
||||
$newVal = $setting[$column];
|
||||
if ($currVal !== $newVal) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// See if any of the options have changed
|
||||
if ($row->type === 'select') {
|
||||
if ($row->options !== $setting['options']) {
|
||||
@@ -255,14 +265,23 @@ class SeederService extends Service
|
||||
*/
|
||||
private function permissionsSeedsPending(): bool
|
||||
{
|
||||
$all_permissions = DB::table('permissions')->get();
|
||||
|
||||
$data = file_get_contents(database_path('/seeds/permissions.yml'));
|
||||
$yml = Yaml::parse($data);
|
||||
|
||||
foreach ($yml as $perm) {
|
||||
$count = DB::table('permissions')->where('name', $perm['name'])->count('name');
|
||||
if ($count === 0) {
|
||||
$row = $all_permissions->firstWhere('name', $perm['name']);
|
||||
if (!$row) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// See if any of these column values have changed
|
||||
foreach (['display_name', 'description'] as $column) {
|
||||
if ($row->{$column} !== $perm[$column]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
44
app/Services/NewsService.php
Normal file
44
app/Services/NewsService.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Contracts\Service;
|
||||
use App\Events\NewsAdded;
|
||||
use App\Repositories\NewsRepository;
|
||||
|
||||
class NewsService extends Service
|
||||
{
|
||||
private $newsRepo;
|
||||
|
||||
public function __construct(NewsRepository $newsRepo)
|
||||
{
|
||||
$this->newsRepo = $newsRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a news item
|
||||
*
|
||||
* @param array $attrs
|
||||
*
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function addNews(array $attrs)
|
||||
{
|
||||
$news = $this->newsRepo->create($attrs);
|
||||
event(new NewsAdded($news));
|
||||
|
||||
return $news;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete something from the news items
|
||||
*
|
||||
* @param int $id ID of the news row to delete
|
||||
*/
|
||||
public function deleteNews($id)
|
||||
{
|
||||
$this->newsRepo->delete($id);
|
||||
}
|
||||
}
|
||||
@@ -269,10 +269,10 @@ class PirepService extends Service
|
||||
foreach ($field_values as $fv) {
|
||||
PirepFieldValue::updateOrCreate(
|
||||
['pirep_id' => $pirep_id,
|
||||
'name' => $fv['name'],
|
||||
'name' => $fv['name'],
|
||||
],
|
||||
['value' => $fv['value'],
|
||||
'source' => $fv['source'],
|
||||
['value' => $fv['value'],
|
||||
'source' => $fv['source'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
47
app/Services/RoleService.php
Normal file
47
app/Services/RoleService.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Contracts\Service;
|
||||
use App\Models\Role;
|
||||
use App\Repositories\RoleRepository;
|
||||
|
||||
class RoleService extends Service
|
||||
{
|
||||
private $roleRepo;
|
||||
|
||||
public function __construct(RoleRepository $roleRepo)
|
||||
{
|
||||
$this->roleRepo = $roleRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a role with the given attributes
|
||||
*
|
||||
* @param Role $role
|
||||
* @param array $attrs
|
||||
*
|
||||
* @return Role
|
||||
*/
|
||||
public function updateRole(Role $role, array $attrs)
|
||||
{
|
||||
$role->update($attrs);
|
||||
$role->save();
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Role $role
|
||||
* @param array $permissions
|
||||
*/
|
||||
public function setPermissionsForRole(Role $role, array $permissions)
|
||||
{
|
||||
// Update the permissions, filter out null/invalid values
|
||||
$perms = collect($permissions)->filter(static function ($v, $k) {
|
||||
return $v;
|
||||
});
|
||||
|
||||
$role->permissions()->sync($perms);
|
||||
}
|
||||
}
|
||||
@@ -48,14 +48,14 @@ class UserService extends Service
|
||||
* Register a pilot. Also attaches the initial roles
|
||||
* required, and then triggers the UserRegistered event
|
||||
*
|
||||
* @param User $user User model
|
||||
* @param array $groups Additional groups to assign
|
||||
* @param User $user User model
|
||||
* @param array $roles List of "display_name" of groups to assign
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function createUser(User $user, array $groups = null)
|
||||
public function createUser(User $user, array $roles = null)
|
||||
{
|
||||
// Determine if we want to auto accept
|
||||
if (setting('pilots.auto_accept') === true) {
|
||||
@@ -66,15 +66,10 @@ class UserService extends Service
|
||||
|
||||
$user->save();
|
||||
|
||||
// Attach the user roles
|
||||
// $role = Role::where('name', 'user')->first();
|
||||
// $user->attachRole($role);
|
||||
|
||||
// Attach any additional roles
|
||||
if (!empty($groups) && is_array($groups)) {
|
||||
foreach ($groups as $group) {
|
||||
$role = Role::where('name', $group)->first();
|
||||
$user->attachRole($role);
|
||||
if (!empty($roles) && is_array($roles)) {
|
||||
foreach ($roles as $role) {
|
||||
$this->addUserToRole($user, $role);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +82,32 @@ class UserService extends Service
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a user to a given role
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $roleName
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function addUserToRole(User $user, $roleName): User
|
||||
{
|
||||
$role = Role::where(['name' => $roleName])->first();
|
||||
$user->attachRole($role);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and return the next available pilot ID (usually just the max+1)
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNextAvailablePilotId(): int
|
||||
{
|
||||
return (int) User::max('pilot_id') + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the next available pilot ID and set the current user's pilot_id to that +1
|
||||
* Called from UserObserver right now after a record is created
|
||||
@@ -101,8 +122,7 @@ class UserService extends Service
|
||||
return $user;
|
||||
}
|
||||
|
||||
$max = (int) User::max('pilot_id');
|
||||
$user->pilot_id = $max + 1;
|
||||
$user->pilot_id = $this->getNextAvailablePilotId();
|
||||
$user->save();
|
||||
|
||||
Log::info('Set pilot ID for user '.$user->id.' to '.$user->pilot_id);
|
||||
@@ -348,8 +368,8 @@ class UserService extends Service
|
||||
'state' => PirepState::ACCEPTED,
|
||||
];
|
||||
|
||||
$flight_count = Pirep::where($w)->count();
|
||||
$user->flights = $flight_count;
|
||||
$pirep_count = Pirep::where($w)->count();
|
||||
$user->flights = $pirep_count;
|
||||
|
||||
$flight_time = Pirep::where($w)->sum('flight_time');
|
||||
$user->flight_time = $flight_time;
|
||||
@@ -359,7 +379,7 @@ class UserService extends Service
|
||||
// Recalc the rank
|
||||
$this->calculatePilotRank($user);
|
||||
|
||||
Log::info('User '.$user->ident.' updated; flight count='.$flight_count
|
||||
Log::info('User '.$user->ident.' updated; pirep count='.$pirep_count
|
||||
.', rank='.$user->rank->name
|
||||
.', flight_time='.$user->flight_time.' minutes');
|
||||
|
||||
|
||||
@@ -153,6 +153,12 @@ class VersionService extends Service
|
||||
|
||||
$c = $cfg['current'];
|
||||
$version = "{$c['major']}.{$c['minor']}.{$c['patch']}";
|
||||
if ($c['prerelease'] !== '') {
|
||||
$version .= "-{$c['prerelease']}";
|
||||
if ($c['buildmetadata'] !== '') {
|
||||
$version .= ".{$c['buildmetadata']}";
|
||||
}
|
||||
}
|
||||
|
||||
if ($include_build) {
|
||||
// Get the current build id
|
||||
@@ -179,6 +185,8 @@ class VersionService extends Service
|
||||
$current_version = $this->cleanVersionString($current_version);
|
||||
}
|
||||
|
||||
// Replace "dev" with "alpha", since
|
||||
|
||||
$latest_version = $this->getLatestVersion();
|
||||
|
||||
// Convert to semver
|
||||
|
||||
Reference in New Issue
Block a user