phpvms/app/Cron/Nightly/PilotLeave.php

47 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2018-04-07 06:14:01 +08:00
namespace App\Cron\Nightly;
use App\Contracts\Listener;
2019-07-16 03:51:35 +08:00
use App\Events\CronNightly;
use App\Services\UserService;
use Illuminate\Support\Facades\Log;
/**
* Determine if any pilots should be set to ON LEAVE status
*/
class PilotLeave extends Listener
{
private UserService $userSvc;
/**
* PilotLeave constructor.
*
* @param UserService $userSvc
*/
public function __construct(UserService $userSvc)
{
$this->userSvc = $userSvc;
}
/**
* Set any users to being on leave after X days
2018-08-27 00:40:04 +08:00
*
* @param CronNightly $event
2018-08-27 00:40:04 +08:00
*
* @throws \UnexpectedValueException
* @throws \InvalidArgumentException
*/
public function handle(CronNightly $event): void
{
Log::info('Cron: Running pilot leave check');
$users = $this->userSvc->findUsersOnLeave();
Log::info('Found '.count($users).' users on leave');
2018-08-27 00:40:04 +08:00
foreach ($users as $user) {
Log::info('Setting user '.$user->ident.' to ON LEAVE status');
2018-03-31 11:36:01 +08:00
$this->userSvc->setStatusOnLeave($user);
}
}
}