Initial user stats recalculation #254
This commit is contained in:
49
app/Cron/Nightly/RecalculateStats.php
Normal file
49
app/Cron/Nightly/RecalculateStats.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Cron\Nightly;
|
||||
|
||||
use App\Events\CronNightly;
|
||||
use App\Interfaces\Listener;
|
||||
use App\Models\Enums\UserState;
|
||||
use App\Models\Journal;
|
||||
use App\Repositories\UserRepository;
|
||||
use App\Services\UserService;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* This recalculates the balances on all of the journals
|
||||
* @package App\Listeners\Cron
|
||||
*/
|
||||
class RecalculateStats extends Listener
|
||||
{
|
||||
private $userRepo,
|
||||
$userSvc;
|
||||
|
||||
public function __construct(UserRepository $userRepo, UserService $userService)
|
||||
{
|
||||
$this->userRepo = $userRepo;
|
||||
$this->userSvc = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculate the stats for active users
|
||||
* @param CronNightly $event
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function handle(CronNightly $event): void
|
||||
{
|
||||
Log::info('Recalculating balances');
|
||||
|
||||
$w = [
|
||||
['state', '!=', UserState::REJECTED]
|
||||
];
|
||||
|
||||
$users = $this->userRepo->findWhere($w, ['id', 'name', 'airline_id']);
|
||||
foreach ($users as $user) {
|
||||
$this->userSvc->recalculateStats($user);
|
||||
}
|
||||
|
||||
Log::info('Done recalculating stats');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user