clrghouz/app/Jobs/TicProcess.php

69 lines
1.5 KiB
PHP
Raw Normal View History

2022-11-01 11:24:36 +00:00
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
2022-11-01 11:24:36 +00:00
use App\Classes\FTN\Tic;
use App\Models\Domain;
2022-11-01 11:24:36 +00:00
class TicProcess implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private const LOGKEY = 'JTP';
private ?Domain $do;
2023-08-15 02:25:38 +00:00
public const QUEUE = 'tic';
2022-11-01 11:24:36 +00:00
/**
* Create a new job instance.
*
* @param string $file
* @param string|null $domain
2022-11-01 11:24:36 +00:00
*/
public function __construct(private string $file,private ?string $domain=NULL)
2022-11-01 11:24:36 +00:00
{
$this->do = $domain ? Domain::where('name',$domain)->singleOrFail() : NULL;
2023-08-15 02:25:38 +00:00
$this->onQueue(self::QUEUE);
2022-11-01 11:24:36 +00:00
}
public function __get($key): mixed
{
switch ($key) {
case 'subject':
return sprintf('%s %s',$this->do?->name,$this->file);
default:
return NULL;
}
}
2022-11-01 11:24:36 +00:00
/**
* Execute the job.
*
* @return void
* @throws FileNotFoundException
*/
public function handle()
{
$to = new Tic;
2023-09-05 09:57:34 +00:00
$to->load(storage_path('app').'/'.$this->file);
2023-09-05 09:57:34 +00:00
Log::info(sprintf('%s:Processed [%s] storing [%s] as id [%d]',self::LOGKEY,$this->file,$to->fo->name,$to->fo->id));
2023-09-05 09:57:34 +00:00
unlink(storage_path('app').'/'.$this->file);
if ($to->isNodelist())
NodelistImport::dispatch($to->fo,$this->domain);
2022-11-01 11:24:36 +00:00
}
}