Clean up enums and cache-keys configs

This commit is contained in:
Nabeel Shahzad 2017-07-04 15:43:47 -05:00
parent 870eefb83d
commit 7265eb1913
7 changed files with 45 additions and 96 deletions

View File

@ -76,7 +76,7 @@ class RankController extends BaseController
$model = $this->rankRepository->create($input);
Flash::success('Ranking saved successfully.');
Cache::forget(config('phpvms.cache_keys.RANKS_PILOT_LIST')['key']);
Cache::forget(config('cache.keys.RANKS_PILOT_LIST.key'));
return redirect(route('admin.ranks.edit', ['id' => $model->id]));
}
@ -143,7 +143,7 @@ class RankController extends BaseController
}
$rank = $this->rankRepository->update($request->all(), $id);
Cache::forget(config('phpvms.cache_keys.RANKS_PILOT_LIST')['key']);
Cache::forget(config('cache.keys.RANKS_PILOT_LIST.key'));
Flash::success('Ranking updated successfully.');
return redirect(route('admin.ranks.index'));

View File

@ -33,13 +33,13 @@ class PIREPService extends BaseService
# Figure out what default state should be. Look at the default
# behavior from the rank that the pilot is assigned to
if($pirep->source == \VMSEnums::$sources['ACARS']) {
if($pirep->source == config('enums.sources.ACARS')) {
$default_status = $pirep->pilot->rank->auto_approve_acars;
} else {
$default_status = $pirep->pilot->rank->auto_approve_manual;
}
if ($default_status == \VMSEnums::$pirep_status['ACCEPTED']) {
if ($default_status == config('enums.pirep_status.ACCEPTED')) {
$pirep = $this->accept($pirep);
}
@ -75,10 +75,10 @@ class PIREPService extends BaseService
/**
* Move from a PENDING status into either ACCEPTED or REJECTED
*/
if ($pirep->status == \VMSEnums::$pirep_status['PENDING']) {
if ($new_status == \VMSEnums::$pirep_status['ACCEPTED']) {
if ($pirep->status == config('enums.pirep_status.PENDING')) {
if ($new_status == config('enums.pirep_status.ACCEPTED')) {
return $this->accept($pirep);
} elseif ($new_status == \VMSEnums::$pirep_status['REJECTED']) {
} elseif ($new_status == config('enums.pirep_status.REJECTED')) {
return $this->reject($pirep);
} else {
return $pirep;
@ -88,7 +88,7 @@ class PIREPService extends BaseService
/*
* Move from a ACCEPTED to REJECTED status
*/
elseif ($pirep->status == \VMSEnums::$pirep_status['ACCEPTED']) {
elseif ($pirep->status == config('enums.pirep_status.ACCEPTED')) {
$pirep = $this->reject($pirep);
return $pirep;
}
@ -96,7 +96,7 @@ class PIREPService extends BaseService
/**
* Move from REJECTED to ACCEPTED
*/
elseif ($pirep->status == \VMSEnums::$pirep_status['REJECTED']) {
elseif ($pirep->status == config('enums.pirep_status.REJECTED')) {
$pirep = $this->accept($pirep);
return $pirep;
}
@ -109,7 +109,7 @@ class PIREPService extends BaseService
public function accept(Pirep &$pirep): Pirep
{
# moving from a REJECTED state to ACCEPTED, reconcile statuses
if ($pirep->status == \VMSEnums::$pirep_status['ACCEPTED']) {
if ($pirep->status == config('enums.pirep_status.ACCEPTED')) {
return $pirep;
}
@ -122,7 +122,7 @@ class PIREPService extends BaseService
$pirep->pilot->refresh();
# Change the status
$pirep->status = \VMSEnums::$pirep_status['ACCEPTED'];
$pirep->status = config('enums.pirep_status.ACCEPTED');
$pirep->save();
return $pirep;
@ -136,7 +136,7 @@ class PIREPService extends BaseService
{
# If this was previously ACCEPTED, then reconcile the flight hours
# that have already been counted, etc
if ($pirep->status == \VMSEnums::$pirep_status['ACCEPTED']) {
if ($pirep->status == config('enums.pirep_status.ACCEPTED')) {
$pilot = $pirep->pilot;
$ft = $pirep->flight_time * -1;
@ -147,7 +147,7 @@ class PIREPService extends BaseService
}
# Change the status
$pirep->status = \VMSEnums::$pirep_status['REJECTED'];
$pirep->status = config('enums.pirep_status.REJECTED');
$pirep->save();
return $pirep;

View File

@ -36,8 +36,8 @@ class PilotService extends BaseService
# TODO: Cache
$ranks = Cache::remember(
config('phpvms.cache_keys.RANKS_PILOT_LIST')['key'],
config('phpvms.cache_keys.RANKS_PILOT_LIST')['time'],
config('cache.keys.RANKS_PILOT_LIST.key'),
config('cache.keys.RANKS_PILOT_LIST.time'),
function () {
return Rank::where('auto_promote', true)->orderBy('hours', 'asc')->get();
});

View File

@ -2,42 +2,20 @@
return [
/*
|--------------------------------------------------------------------------
| Default Cache Store
|--------------------------------------------------------------------------
|
| This option controls the default cache connection that gets used while
| using this caching library. This connection is used when another is
| not explicitly specified when executing a given caching function.
|
| Supported: "apc", "array", "database", "file", "memcached", "redis"
|
*/
'default' => env('CACHE_DRIVER', 'file'),
'prefix' => env('CACHE_PREFIX', ''),
/*
|--------------------------------------------------------------------------
| Cache Stores
|--------------------------------------------------------------------------
|
| Here you may define all of the cache "stores" for your application as
| well as their drivers. You may even define multiple stores for the
| same cache driver to group types of items stored in your caches.
|
*/
'keys' => [
'RANKS_PILOT_LIST' => [
'key' => 'ranks::pilot_list',
'time' => 1440,
]
],
'stores' => [
'apc' => [
'driver' => 'apc',
],
'array' => [
'driver' => 'array',
],
'apc' => ['driver' => 'apc'],
'array' => ['driver' => 'array'],
'database' => [
'driver' => 'database',
'table' => 'cache',
@ -74,17 +52,4 @@ return [
],
],
/*
|--------------------------------------------------------------------------
| Cache Key Prefix
|--------------------------------------------------------------------------
|
| When utilizing a RAM based store such as APC or Memcached, there might
| be other applications utilizing the same cache. So, we'll specify a
| value to get prefixed to all our keys so we can avoid collisions.
|
*/
'prefix' => env('CACHE_PREFIX', ''),
];

View File

@ -1,31 +1,21 @@
<?php
# TODO: Remove this ugly hackiness
if(defined('VMSEnums')) {
return;
} else {
define('VMSEnums', true);
}
class VMSEnums
{
public static $sources
= [
return [
'sources' => [
'MANUAL' => 0,
'ACARS' => 1,
];
],
public static $pirep_status
= [
'pirep_status' => [
'PENDING' => 0,
'ACCEPTED' => 1,
'REJECTED' => -1,
];
],
public static $fuel_types
= [
'fuel_types' => [
'100LL' => 0,
'JETA' => 1,
'MOGAS' => 2,
];
}
],
];

View File

@ -8,10 +8,4 @@ return [
*/
'currency' => env('PHPVMS_CURRENCY', 'dollar'),
'cache_keys' => [
'RANKS_PILOT_LIST' => [
'key' => 'ranks::pilot_list',
'time' => 1440,
]
]
];

View File

@ -39,7 +39,7 @@ class PIREPTest extends TestCase
$pirep = $this->pirepSvc->create($pirep, []);
if($accept) {
$this->pirepSvc->changeStatus($pirep,
VMSEnums::$pirep_status['ACCEPTED']);
config('enums.pirep_status.ACCEPTED'));
}
}
@ -69,12 +69,12 @@ class PIREPTest extends TestCase
* Check the initial status info
*/
$this->assertEquals($pirep->pilot->flights, 0);
$this->assertEquals($pirep->status, VMSEnums::$pirep_status['PENDING']);
$this->assertEquals($pirep->status, config('enums.pirep_status.PENDING'));
/**
* Now set the PIREP state to ACCEPTED
*/
$this->pirepSvc->changeStatus($pirep, VMSEnums::$pirep_status['ACCEPTED']);
$this->pirepSvc->changeStatus($pirep, config('enums.pirep_status.ACCEPTED'));
$this->assertEquals(1, $pirep->pilot->flights);
$this->assertEquals(21600, $pirep->pilot->flight_time);
$this->assertEquals(1, $pirep->pilot->rank_id);
@ -82,7 +82,7 @@ class PIREPTest extends TestCase
/**
* Now go from ACCEPTED to REJECTED
*/
$this->pirepSvc->changeStatus($pirep, VMSEnums::$pirep_status['REJECTED']);
$this->pirepSvc->changeStatus($pirep, config('enums.pirep_status.REJECTED'));
$this->assertEquals(0, $pirep->pilot->flights);
$this->assertEquals(0, $pirep->pilot->flight_time);
$this->assertEquals(1, $pirep->pilot->rank_id);
@ -117,7 +117,7 @@ class PIREPTest extends TestCase
# The PIREP should have been automatically accepted
$this->assertEquals(
VMSEnums::$pirep_status['ACCEPTED'],
config('enums.pirep_status.ACCEPTED'),
$latest_pirep->status
);
}