phpvms/app/Cron/Nightly/RecalculateStats.php

42 lines
998 B
PHP
Raw Normal View History

2018-08-20 22:42:54 +08:00
<?php
namespace App\Cron\Nightly;
use App\Contracts\Listener;
2019-07-16 03:51:35 +08:00
use App\Events\CronNightly;
use App\Services\AircraftService;
2018-08-20 22:42:54 +08:00
use App\Services\UserService;
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
{
private $aircraftSvc;
2018-08-27 00:40:04 +08:00
private $userSvc;
2018-08-20 22:42:54 +08:00
public function __construct(AircraftService $aircraftSvc, UserService $userSvc)
2018-08-20 22:42:54 +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
{
Log::info('Nightly: Recalculating user stats');
$this->userSvc->recalculateAllUserStats();
2018-08-20 22:42:54 +08:00
Log::info('Nightly: Recalcuating aircraft status');
$this->aircraftSvc->recalculateStats();
2018-08-20 22:42:54 +08:00
}
}