Update and rename Photo/Video Delete to CatalogDelete
This commit is contained in:
parent
7742b4289d
commit
5b1b6a3fd2
64
app/Jobs/CatalogDelete.php
Normal file
64
app/Jobs/CatalogDelete.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
use InteractsWithQueue,SerializesModels;
|
||||||
|
|
||||||
|
// Our object
|
||||||
|
private Catalog $o;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Catalog $o)
|
||||||
|
{
|
||||||
|
$this->o = $o;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
}
|
||||||
|
}
|
@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs;
|
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
|
|
||||||
use App\Models\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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs;
|
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
|
|
||||||
use App\Models\Video;
|
|
||||||
|
|
||||||
class VideoDelete extends Job implements ShouldQueue
|
|
||||||
{
|
|
||||||
use InteractsWithQueue,SerializesModels;
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -416,7 +416,7 @@ abstract class Catalog extends Model
|
|||||||
// Test if the target dir is writable
|
// Test if the target dir is writable
|
||||||
// @todo The target dir may not exist yet, so we should check that a parent exists and is writable.
|
// @todo The target dir may not exist yet, so we should check that a parent exists and is writable.
|
||||||
$this->move_reason = 'Target parent dir doesnt is not writable';
|
$this->move_reason = 'Target parent dir doesnt is not writable';
|
||||||
if (! $this->isParentWritable(dirname($this->file_name(FALSE))))
|
if (! $this->isParentWritable(dirname($this->file_name(TRUE))))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
// Otherwise we can move it
|
// Otherwise we can move it
|
||||||
|
@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
use App\Jobs\{PhotoDelete,VideoDelete};
|
use App\Jobs\CatalogDelete;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multimedia Controller Functions
|
* Multimedia Controller Functions
|
||||||
@ -80,13 +80,12 @@ trait Multimedia
|
|||||||
if ($delete && $o->remove && ($request->input('remove.'.$id) ? 1 : NULL)) {
|
if ($delete && $o->remove && ($request->input('remove.'.$id) ? 1 : NULL)) {
|
||||||
switch (strtolower($request->input('type'))) {
|
switch (strtolower($request->input('type'))) {
|
||||||
case 'photo':
|
case 'photo':
|
||||||
$this->dispatch((new PhotoDelete($o))->onQueue('delete'));
|
|
||||||
Log::info(sprintf('Dispatching delete for [%s]',$o->id));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'video':
|
case 'video':
|
||||||
$this->dispatch((new VideoDelete($o))->onQueue('delete'));
|
|
||||||
Log::info(sprintf('Dispatching delete for [%s]',$o->id));
|
Log::info(sprintf('Dispatching delete for [%s]',$o->id));
|
||||||
|
|
||||||
|
CatalogDelete::dispatch($o)
|
||||||
|
->onQueue('delete');
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user