61 lines
1.3 KiB
PHP
61 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use Log;
|
|
use App\Jobs\Job;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use App\Model\Photo;
|
|
|
|
class PhotoDelete extends Job implements ShouldQueue
|
|
{
|
|
use InteractsWithQueue, SerializesModels;
|
|
|
|
private $photo;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(Photo $photo)
|
|
{
|
|
$this->photo = $photo;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
if (! $this->photo->remove)
|
|
{
|
|
Log::warning(sprintf('%s: NOT Deleting [%s] not marked for deletion',__METHOD__,$this->photo->file_path()));
|
|
exit;
|
|
}
|
|
|
|
// Remove tags;
|
|
if ($this->photo->Tags->count())
|
|
$this->photo->Tags()->detach();
|
|
|
|
// Remove People;
|
|
if ($this->photo->People->count())
|
|
$this->photo->People()->detach();
|
|
|
|
// Make sure our parent is writable
|
|
if (! is_writable(dirname($this->photo->file_path())))
|
|
Log::warning(sprintf('%s: NOT Deleting [%s] parent directory not writable',__METHOD__,$this->photo->file_path()));
|
|
|
|
// Perform delete
|
|
if (file_exists($this->photo->file_path()))
|
|
unlink($this->photo->file_path());
|
|
|
|
Log::warning(sprintf('%s: Deleted [%s]',__METHOD__,$this->photo->file_path()));
|
|
$this->photo->delete();
|
|
}
|
|
}
|