akubiczek /
applicake-backend
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Jobs; |
||
| 4 | |||
| 5 | use App\Models\Candidate; |
||
| 6 | use App\Utils\ResumeParser; |
||
| 7 | use Illuminate\Bus\Queueable; |
||
| 8 | use Illuminate\Contracts\Queue\ShouldQueue; |
||
| 9 | use Illuminate\Foundation\Bus\Dispatchable; |
||
| 10 | use Illuminate\Queue\InteractsWithQueue; |
||
| 11 | use Illuminate\Queue\SerializesModels; |
||
| 12 | use Illuminate\Support\Facades\Storage; |
||
| 13 | |||
| 14 | class ProcessResume implements ShouldQueue |
||
| 15 | { |
||
| 16 | use Dispatchable; |
||
| 17 | use InteractsWithQueue; |
||
| 18 | use Queueable; |
||
| 19 | use SerializesModels; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 20 | |||
| 21 | /** |
||
| 22 | * @var Candidate |
||
| 23 | */ |
||
| 24 | protected $candidate; |
||
| 25 | |||
| 26 | protected $override; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Create a new job instance. |
||
| 30 | * |
||
| 31 | * @param Candidate $candidate |
||
| 32 | * @param bool $override |
||
| 33 | */ |
||
| 34 | public function __construct(Candidate $candidate, $override = false) |
||
| 35 | { |
||
| 36 | $this->candidate = $candidate; |
||
| 37 | $this->override = $override; |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Execute the job. |
||
| 42 | * |
||
| 43 | * @throws \Exception |
||
| 44 | * |
||
| 45 | * @return void |
||
| 46 | */ |
||
| 47 | public function handle() |
||
| 48 | { |
||
| 49 | if (substr($this->candidate->path_to_cv, -4) == '.pdf') { |
||
| 50 | $outputFile = str_replace('.pdf', '_avatar.jpg', $this->candidate->path_to_cv); |
||
| 51 | |||
| 52 | if ($this->override || Storage::disk('s3')->missing($outputFile)) { |
||
| 53 | if (ResumeParser::extractPhoto($this->candidate->path_to_cv, $outputFile)) { |
||
| 54 | $this->candidate->photo_path = $outputFile; |
||
| 55 | } |
||
| 56 | |||
| 57 | $this->candidate->photo_extraction = new \DateTime(); |
||
| 58 | $this->candidate->save(); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 |