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
|
|
|
|
*/
|
2024-10-04 02:49:09 +00:00
|
|
|
public function handle(): void
|
2024-09-30 14:01:33 +00:00
|
|
|
{
|
|
|
|
if (! $this->o->remove) {
|
|
|
|
Log::warning(sprintf('%s: NOT Deleting [%s] not marked for deletion',__METHOD__,$this->o->file_name_rel(FALSE)));
|
|
|
|
|
2024-10-04 02:49:09 +00:00
|
|
|
return;
|
2024-09-30 14:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2024-10-04 02:49:09 +00:00
|
|
|
if (! $this->o->isParentWritable($x=dirname($this->o->file_name_rel(TRUE)))) {
|
2024-09-30 14:01:33 +00:00
|
|
|
Log::warning(sprintf('%s: NOT Deleting [%s] parent directory not writable',__METHOD__,$this->o->file_name(FALSE)));
|
|
|
|
|
2024-10-04 02:49:09 +00:00
|
|
|
$this->fail('Parent not writable:'.$x);
|
|
|
|
|
|
|
|
return;
|
2024-09-30 14:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
}
|