phpvms/app/Cron/Nightly/RecalculateStats.php

39 lines
802 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;
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
{
2018-08-27 00:40:04 +08:00
private $userSvc;
2018-08-20 22:42:54 +08:00
public function __construct(UserService $userService)
2018-08-20 22:42:54 +08:00
{
$this->userSvc = $userService;
}
/**
* 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('Recalculating balances');
$this->userSvc->recalculateAllUserStats();
2018-08-20 22:42:54 +08:00
Log::info('Done recalculating stats');
}
}