2016-06-30 06:01:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
2019-11-09 02:52:04 +00:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2016-06-30 06:01:12 +00:00
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
2019-11-09 02:52:04 +00:00
|
|
|
|
|
|
|
use App\Models\Photo;
|
2016-06-30 06:01:12 +00:00
|
|
|
|
|
|
|
class PhotoDelete extends Job implements ShouldQueue
|
|
|
|
{
|
2019-11-09 02:52:04 +00:00
|
|
|
use InteractsWithQueue,SerializesModels;
|
2016-06-30 06:01:12 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2016-06-30 11:34:18 +00:00
|
|
|
Log::warning(sprintf('%s: NOT Deleting [%s] not marked for deletion',__METHOD__,$this->photo->file_path()));
|
2016-06-30 06:01:12 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove tags;
|
2016-07-01 04:37:55 +00:00
|
|
|
if ($this->photo->Tags->count())
|
|
|
|
$this->photo->Tags()->detach();
|
2016-06-30 06:01:12 +00:00
|
|
|
|
|
|
|
// Remove People;
|
2016-07-01 04:37:55 +00:00
|
|
|
if ($this->photo->People->count())
|
|
|
|
$this->photo->People()->detach();
|
2016-06-30 06:01:12 +00:00
|
|
|
|
|
|
|
// Make sure our parent is writable
|
|
|
|
if (! is_writable(dirname($this->photo->file_path())))
|
2016-06-30 11:34:18 +00:00
|
|
|
Log::warning(sprintf('%s: NOT Deleting [%s] parent directory not writable',__METHOD__,$this->photo->file_path()));
|
2016-06-30 06:01:12 +00:00
|
|
|
|
|
|
|
// Perform delete
|
|
|
|
if (file_exists($this->photo->file_path()))
|
|
|
|
unlink($this->photo->file_path());
|
|
|
|
|
2016-06-30 11:34:18 +00:00
|
|
|
Log::warning(sprintf('%s: Deleted [%s]',__METHOD__,$this->photo->file_path()));
|
2016-06-30 06:01:12 +00:00
|
|
|
$this->photo->delete();
|
|
|
|
}
|
|
|
|
}
|