2024-09-30 14:01:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
2024-10-01 01:48:17 +00:00
|
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
|
|
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
2024-09-30 14:01:33 +00:00
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
|
|
|
|
use App\Models\Abstracted\Catalog;
|
|
|
|
|
|
|
|
class CatalogDelete implements ShouldQueue
|
|
|
|
{
|
2024-10-01 01:48:17 +00:00
|
|
|
use InteractsWithQueue,Queueable,SerializesModels;
|
2024-09-30 14:01:33 +00:00
|
|
|
|
|
|
|
// Our object
|
|
|
|
private Catalog $o;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(Catalog $o)
|
|
|
|
{
|
|
|
|
$this->o = $o;
|
|
|
|
}
|
|
|
|
|
2024-10-01 01:48:17 +00:00
|
|
|
public function middleware(): array
|
|
|
|
{
|
|
|
|
return [new WithoutOverlapping($this->uniqueId())];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the unique ID for the job.
|
|
|
|
*/
|
|
|
|
public function uniqueId(): string
|
|
|
|
{
|
|
|
|
return $this->o::config.'|'.$this->o->id;
|
|
|
|
}
|
|
|
|
|
2024-09-30 14:01:33 +00:00
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
if (! $this->o->remove) {
|
|
|
|
Log::warning(sprintf('%s: NOT Deleting [%s] not marked for deletion',__METHOD__,$this->o->file_name_rel(FALSE)));
|
|
|
|
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove tags;
|
|
|
|
if ($this->o->tags->count())
|
|
|
|
$this->o->tags()->detach();
|
|
|
|
|
|
|
|
// Remove People;
|
|
|
|
if ($this->o->people->count())
|
|
|
|
$this->o->people()->detach();
|
|
|
|
|
|
|
|
// Make sure our parent is writable
|
|
|
|
if (! $this->o->isParentWritable(dirname($this->o->file_name(FALSE)))) {
|
|
|
|
Log::warning(sprintf('%s: NOT Deleting [%s] parent directory not writable',__METHOD__,$this->o->file_name(FALSE)));
|
|
|
|
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform delete
|
|
|
|
if (file_exists($this->o->file_name(FALSE)))
|
|
|
|
unlink($this->o->file_name(FALSE));
|
|
|
|
|
|
|
|
Log::warning(sprintf('%s: Deleted [%s]',__METHOD__,$this->o->file_name(FALSE)));
|
|
|
|
$this->o->delete();
|
|
|
|
}
|
|
|
|
}
|