2018-03-31 11:28:19 +08:00
|
|
|
<?php
|
|
|
|
|
2018-04-07 06:14:01 +08:00
|
|
|
namespace App\Cron\Nightly;
|
2018-03-31 11:28:19 +08:00
|
|
|
|
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-03-31 11:28:19 +08:00
|
|
|
use App\Services\UserService;
|
2021-02-18 07:54:18 +08:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2018-03-31 11:28:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if any pilots should be set to ON LEAVE status
|
|
|
|
*/
|
|
|
|
class PilotLeave extends Listener
|
|
|
|
{
|
|
|
|
private $userSvc;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PilotLeave constructor.
|
2021-02-18 07:54:18 +08:00
|
|
|
*
|
|
|
|
* @param UserService $userSvc
|
2018-03-31 11:28:19 +08:00
|
|
|
*/
|
|
|
|
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
|
|
|
*
|
2018-03-31 11:28:19 +08:00
|
|
|
* @param CronNightly $event
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-31 11:28:19 +08:00
|
|
|
* @throws \UnexpectedValueException
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function handle(CronNightly $event): void
|
|
|
|
{
|
2021-03-03 04:43:34 +08:00
|
|
|
Log::info('Cron: Running pilot leave check');
|
2021-02-18 07:54:18 +08:00
|
|
|
$users = $this->userSvc->findUsersOnLeave();
|
2021-03-03 04:43:34 +08:00
|
|
|
Log::info('Found '.count($users).' users on leave');
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
foreach ($users as $user) {
|
2018-07-13 11:23:45 +08:00
|
|
|
Log::info('Setting user '.$user->ident.' to ON LEAVE status');
|
2018-03-31 11:36:01 +08:00
|
|
|
$this->userSvc->setStatusOnLeave($user);
|
2018-03-31 11:28:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|