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;
|
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
|
|
|
|
{
|
2018-08-27 00:40:04 +08:00
|
|
|
private $userSvc;
|
2018-08-20 22:42:54 +08:00
|
|
|
|
2019-08-11 08:42:35 +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');
|
|
|
|
|
2019-08-11 08:42:35 +08:00
|
|
|
$this->userSvc->recalculateAllUserStats();
|
2018-08-20 22:42:54 +08:00
|
|
|
|
|
|
|
Log::info('Done recalculating stats');
|
|
|
|
}
|
|
|
|
}
|