ProcessJobStatusTransitions   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 16
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A handle() 0 22 3
1
<?php
2
3
namespace App\Jobs;
4
5
use Jenssegers\Date\Date;
6
use App\Models\JobPoster;
7
use App\Models\Lookup\JobPosterStatus;
8
use Illuminate\Bus\Queueable;
9
use Illuminate\Contracts\Queue\ShouldQueue;
10
use Illuminate\Foundation\Bus\Dispatchable;
11
use Illuminate\Queue\InteractsWithQueue;
12
use Illuminate\Queue\SerializesModels;
13
14
class ProcessJobStatusTransitions implements ShouldQueue
15
{
16
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
17
18
    /**
19
     * Create a new job instance.
20
     *
21
     * @return void
22
     */
23
    public function __construct()
24
    {
25
        //
26
    }
27
28
    /**
29
     * Execute the job.
30
     *
31
     * @return void
32
     */
33
    public function handle()
34
    {
35
        $now = Date::now();
36
        $ready = JobPosterStatus::where('key', 'ready')->first();
37
        $live = JobPosterStatus::where('key', 'live')->first();
38
        $assessment = JobPosterStatus::where('key', 'assessment')->first();
39
40
        $jobsReadyForLive = JobPoster::where('job_poster_status_id', $ready->id)
41
            ->where('open_date_time', '<=', $now)->get();
42
43
        // We want to call save on each model individually instead of doing a mass update in order to trigger
44
        // any events that may be listening for eloquent model updates.
45
        foreach ($jobsReadyForLive as $job) {
46
            $job->job_poster_status_id = $live->id;
47
            $job->save();
48
        }
49
50
        $jobsReadyForAssessment = JobPoster::where('job_poster_status_id', $live->id)
51
            ->where('close_date_time', '<=', $now)->get();
52
        foreach ($jobsReadyForAssessment as $job) {
53
            $job->job_poster_status_id = $assessment->id;
54
            $job->save();
55
        }
56
    }
57
}
58