2018-08-20 22:42:54 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Cron\Nightly;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Listener;
|
2019-07-16 03:51:35 +08:00
|
|
|
use App\Events\CronNightly;
|
2020-02-25 08:35:28 +08:00
|
|
|
use App\Services\AircraftService;
|
2018-08-20 22:42:54 +08:00
|
|
|
use App\Services\UserService;
|
2019-08-02 03:23:59 +08:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2018-08-20 22:42:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This recalculates the balances on all of the journals
|
|
|
|
*/
|
|
|
|
class RecalculateStats extends Listener
|
|
|
|
{
|
2022-03-14 23:45:18 +08:00
|
|
|
private AircraftService $aircraftSvc;
|
|
|
|
private UserService $userSvc;
|
2018-08-20 22:42:54 +08:00
|
|
|
|
2020-02-25 08:35:28 +08:00
|
|
|
public function __construct(AircraftService $aircraftSvc, UserService $userSvc)
|
2018-08-20 22:42:54 +08:00
|
|
|
{
|
2020-02-25 08:35:28 +08:00
|
|
|
$this->aircraftSvc = $aircraftSvc;
|
|
|
|
$this->userSvc = $userSvc;
|
2018-08-20 22:42:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recalculate the stats for active users
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-08-20 22:42:54 +08:00
|
|
|
* @param CronNightly $event
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-08-20 22:42:54 +08:00
|
|
|
* @throws \UnexpectedValueException
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function handle(CronNightly $event): void
|
|
|
|
{
|
2021-03-03 04:43:34 +08:00
|
|
|
Log::info('Nightly: Recalculating user stats');
|
2019-08-11 08:42:35 +08:00
|
|
|
$this->userSvc->recalculateAllUserStats();
|
2018-08-20 22:42:54 +08:00
|
|
|
|
2021-03-03 04:43:34 +08:00
|
|
|
Log::info('Nightly: Recalcuating aircraft status');
|
2020-02-25 08:35:28 +08:00
|
|
|
$this->aircraftSvc->recalculateStats();
|
2018-08-20 22:42:54 +08:00
|
|
|
}
|
|
|
|
}
|