Passed
Push — feature/job-status-transitions ( 9ca399...644244 )
by Chris
03:52
created

ProcessJobStatusTransitions::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
dl 0
loc 2
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
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
use Illuminate\Support\Facades\Log;
14
15
class ProcessJobStatusTransitions implements ShouldQueue
16
{
17
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
18
19
    /**
20
     * Create a new job instance.
21
     *
22
     * @return void
23
     */
24
    public function __construct()
25
    {
26
        //
27
    }
28
29
    /**
30
     * Execute the job.
31
     *
32
     * @return void
33
     */
34
    public function handle()
35
    {
36
        $now = Date::now();
37
        $ready = JobPosterStatus::where('key', 'ready')->first();
38
        $live = JobPosterStatus::where('key', 'live')->first();
39
        $assessment = JobPosterStatus::where('key', 'assessment')->first();
40
41
        $jobsReadyForLive = JobPoster::where('job_poster_status_id', $ready->id)
42
            ->where('open_date_time', '<=', $now)->get();
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 udpates.
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