2016-07-04 06:00:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
2019-11-09 02:52:04 +00:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2016-07-04 06:00:33 +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\Video;
|
2016-07-04 06:00:33 +00:00
|
|
|
|
|
|
|
class VideoDelete extends Job implements ShouldQueue
|
|
|
|
{
|
2019-11-09 02:52:04 +00:00
|
|
|
use InteractsWithQueue,SerializesModels;
|
2016-07-04 06:00:33 +00:00
|
|
|
|
|
|
|
private $video;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(Video $video)
|
|
|
|
{
|
|
|
|
$this->video = $video;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
if (! $this->video->remove)
|
|
|
|
{
|
|
|
|
Log::warning(sprintf('%s: NOT Deleting [%s] not marked for deletion',__METHOD__,$this->video->file_path()));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove tags;
|
|
|
|
if ($this->video->Tags->count())
|
|
|
|
$this->video->Tags()->detach();
|
|
|
|
|
|
|
|
// Remove People;
|
|
|
|
if ($this->video->People->count())
|
|
|
|
$this->video->People()->detach();
|
|
|
|
|
|
|
|
// Make sure our parent is writable
|
|
|
|
if (! is_writable(dirname($this->video->file_path())))
|
|
|
|
Log::warning(sprintf('%s: NOT Deleting [%s] parent directory not writable',__METHOD__,$this->video->file_path()));
|
|
|
|
|
|
|
|
// Perform delete
|
|
|
|
if (file_exists($this->video->file_path()))
|
|
|
|
unlink($this->video->file_path());
|
|
|
|
|
|
|
|
Log::warning(sprintf('%s: Deleted [%s]',__METHOD__,$this->video->file_path()));
|
|
|
|
$this->video->delete();
|
|
|
|
}
|
|
|
|
}
|