2019-11-27 22:19:20 +08:00
|
|
|
<?php
|
|
|
|
|
2020-10-19 22:10:28 +08:00
|
|
|
namespace App\Services\Importers;
|
2019-11-27 22:19:20 +08:00
|
|
|
|
|
|
|
use App\Models\User;
|
2020-02-25 08:35:28 +08:00
|
|
|
use App\Services\AircraftService;
|
2019-11-27 22:19:20 +08:00
|
|
|
use App\Services\UserService;
|
|
|
|
|
2019-12-02 22:57:35 +08:00
|
|
|
class FinalizeImporter extends BaseImporter
|
2019-11-27 22:19:20 +08:00
|
|
|
{
|
2019-12-02 22:57:35 +08:00
|
|
|
/**
|
|
|
|
* Returns a default manifest just so this step gets run
|
|
|
|
*/
|
|
|
|
public function getManifest(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
2020-08-12 05:48:51 +08:00
|
|
|
'importer' => static::class,
|
2019-12-02 22:57:35 +08:00
|
|
|
'start' => 0,
|
|
|
|
'end' => 1,
|
|
|
|
'message' => 'Finalizing import',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2019-11-27 22:19:20 +08:00
|
|
|
|
2019-12-02 22:57:35 +08:00
|
|
|
/**
|
|
|
|
* The start method. Takes the offset to start from
|
|
|
|
*
|
|
|
|
* @param int $start
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2019-11-27 22:19:20 +08:00
|
|
|
public function run($start = 0)
|
|
|
|
{
|
|
|
|
$this->findLastPireps();
|
|
|
|
$this->recalculateUserStats();
|
2020-02-24 08:48:28 +08:00
|
|
|
$this->clearValueStore();
|
2019-11-27 22:19:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Go through and set the last PIREP ID for the users
|
|
|
|
*/
|
|
|
|
protected function findLastPireps()
|
|
|
|
{
|
2020-02-24 08:48:28 +08:00
|
|
|
// TODO
|
2019-11-27 22:19:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recalculate all of the user stats
|
|
|
|
*/
|
|
|
|
protected function recalculateUserStats()
|
|
|
|
{
|
|
|
|
$this->comment('--- RECALCULATING USER STATS ---');
|
2020-02-25 08:35:28 +08:00
|
|
|
|
|
|
|
/** @var UserService $userSvc */
|
2019-11-27 22:19:20 +08:00
|
|
|
$userSvc = app(UserService::class);
|
|
|
|
|
|
|
|
User::all()->each(function ($user) use ($userSvc) {
|
|
|
|
$userSvc->recalculateStats($user);
|
|
|
|
});
|
|
|
|
}
|
2020-02-24 08:48:28 +08:00
|
|
|
|
2020-02-25 08:35:28 +08:00
|
|
|
/**
|
|
|
|
* Update the aircraft stats with the newest/latest PIREPs
|
|
|
|
*/
|
|
|
|
protected function recalculateAircraftStats()
|
|
|
|
{
|
|
|
|
$this->comment('--- RECALCULATING AIRCRAFT STATS ---');
|
|
|
|
|
|
|
|
/** @var AircraftService $aircraftSvc */
|
|
|
|
$aircraftSvc = app(AircraftService::class);
|
|
|
|
$aircraftSvc->recalculateStats();
|
|
|
|
}
|
|
|
|
|
2020-02-24 08:48:28 +08:00
|
|
|
/**
|
|
|
|
* Clear the value store of any old value mappings
|
|
|
|
*/
|
|
|
|
protected function clearValueStore()
|
|
|
|
{
|
|
|
|
$this->idMapper->clear();
|
|
|
|
}
|
2019-11-27 22:19:20 +08:00
|
|
|
}
|