2022-11-01 11:24:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
2023-10-04 11:22:01 +00:00
|
|
|
use Carbon\Carbon;
|
2022-11-01 11:24:36 +00:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2022-11-02 10:20:02 +00:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2023-09-23 12:01:18 +00:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2023-10-04 11:22:01 +00:00
|
|
|
use League\Flysystem\UnableToMoveFile;
|
2022-11-01 11:24:36 +00:00
|
|
|
|
|
|
|
use App\Classes\FTN\Tic;
|
2022-11-11 12:34:33 +00:00
|
|
|
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';
|
|
|
|
|
2022-11-11 12:34:33 +00:00
|
|
|
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.
|
|
|
|
*
|
2023-10-04 11:22:01 +00:00
|
|
|
* @param string $file Received name, stored in Storage::disk('local'), ie: storage/app
|
2022-11-11 12:34:33 +00:00
|
|
|
* @param string|null $domain
|
2022-11-01 11:24:36 +00:00
|
|
|
*/
|
2022-11-11 12:34:33 +00:00
|
|
|
public function __construct(private string $file,private ?string $domain=NULL)
|
2022-11-01 11:24:36 +00:00
|
|
|
{
|
2024-11-08 12:31:21 +00:00
|
|
|
$this->do = $domain ? Domain::where('name',$domain)->sole() : NULL;
|
2023-08-15 02:25:38 +00:00
|
|
|
|
|
|
|
$this->onQueue(self::QUEUE);
|
2022-11-01 11:24:36 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 07:42:41 +00:00
|
|
|
public function __get($key): mixed
|
|
|
|
{
|
|
|
|
switch ($key) {
|
2024-05-21 11:10:58 +00:00
|
|
|
case 'jobname':
|
2023-09-05 07:42:41 +00:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2023-09-23 12:01:18 +00:00
|
|
|
$fs = Storage::disk(config('fido.local_disk'));
|
2023-10-04 11:22:01 +00:00
|
|
|
$rel_name = sprintf('%s/%s',config('fido.dir'),$this->file);
|
2023-09-23 12:01:18 +00:00
|
|
|
|
2023-06-22 07:36:22 +00:00
|
|
|
$to = new Tic;
|
2023-11-21 23:40:15 +00:00
|
|
|
|
2023-10-04 11:22:01 +00:00
|
|
|
try {
|
2024-05-25 01:08:33 +00:00
|
|
|
$fo = $to->load($this->file);
|
2023-10-04 11:22:01 +00:00
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
2023-10-06 03:59:14 +00:00
|
|
|
Log::error(sprintf('%s:! Error loading TIC file [%s] (%s)',self::LOGKEY,$rel_name,$e->getMessage()));
|
2023-11-21 23:40:15 +00:00
|
|
|
|
2023-10-04 11:22:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-11-02 10:20:02 +00:00
|
|
|
|
2024-05-25 01:08:33 +00:00
|
|
|
$fo->save();
|
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
Log::info(sprintf('%s:= Processed [%s] storing [%s] as id [%d]',self::LOGKEY,$this->file,$to->file->name,$to->file->id));
|
2022-11-02 10:20:02 +00:00
|
|
|
|
2023-10-04 11:22:01 +00:00
|
|
|
if (config('fido.packet_keep')) {
|
2024-06-06 23:13:18 +00:00
|
|
|
$dir = sprintf('%s/%s/%s/%s',config('fido.dir'),($x=Carbon::now())->format('Y'),$x->format('m'),$x->format('d'));
|
2023-10-04 11:22:01 +00:00
|
|
|
Log::debug(sprintf('%s:- Moving processed TIC [%s] to [%s]',self::LOGKEY,$rel_name,$dir));
|
|
|
|
|
|
|
|
try {
|
|
|
|
if ($fs->makeDirectory($dir)) {
|
2023-10-06 03:59:14 +00:00
|
|
|
$fs->move($rel_name,$x=sprintf('%s/%s',$dir,$this->file));
|
2023-10-04 11:22:01 +00:00
|
|
|
Log::info(sprintf('%s:- Moved processed TIC [%s] to [%s]',self::LOGKEY,$rel_name,$x));
|
|
|
|
|
|
|
|
} else
|
|
|
|
Log::error(sprintf('%s:! Unable to create dir [%s]',self::LOGKEY,$dir));
|
|
|
|
|
|
|
|
} catch (UnableToMoveFile $e) {
|
|
|
|
Log::error(sprintf('%s:! Unable to move TIC [%s] to [%s] (%s)',self::LOGKEY,$rel_name,$dir,$e->getMessage()));
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error(sprintf('%s:! Failed moving TIC [%s] to [%s] (%s)',self::LOGKEY,$rel_name,$dir,$e->getMessage()));
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (! $fs->delete($rel_name))
|
|
|
|
Log::alert(sprintf('%s:! Failed to delete [%s]',self::LOGKEY,$rel_name));
|
|
|
|
}
|
2022-11-04 06:20:22 +00:00
|
|
|
|
|
|
|
if ($to->isNodelist())
|
2024-05-25 01:08:33 +00:00
|
|
|
NodelistImport::dispatch($fo->withoutRelations(),$this->domain);
|
2022-11-01 11:24:36 +00:00
|
|
|
}
|
|
|
|
}
|