diff --git a/app/Jobs/CatalogDelete.php b/app/Jobs/CatalogDelete.php new file mode 100644 index 0000000..a1bd5e2 --- /dev/null +++ b/app/Jobs/CatalogDelete.php @@ -0,0 +1,64 @@ +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(); + } +} \ No newline at end of file diff --git a/app/Jobs/PhotoDelete.php b/app/Jobs/PhotoDelete.php deleted file mode 100644 index ae6cda1..0000000 --- a/app/Jobs/PhotoDelete.php +++ /dev/null @@ -1,60 +0,0 @@ -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(); - } -} diff --git a/app/Jobs/VideoDelete.php b/app/Jobs/VideoDelete.php deleted file mode 100644 index 56a1971..0000000 --- a/app/Jobs/VideoDelete.php +++ /dev/null @@ -1,60 +0,0 @@ -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(); - } -} diff --git a/app/Models/Abstracted/Catalog.php b/app/Models/Abstracted/Catalog.php index 4d18e74..90dab18 100644 --- a/app/Models/Abstracted/Catalog.php +++ b/app/Models/Abstracted/Catalog.php @@ -416,7 +416,7 @@ abstract class Catalog extends Model // 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. $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; // Otherwise we can move it diff --git a/app/Traits/Multimedia.php b/app/Traits/Multimedia.php index e6bbf17..54d6aa8 100644 --- a/app/Traits/Multimedia.php +++ b/app/Traits/Multimedia.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; -use App\Jobs\{PhotoDelete,VideoDelete}; +use App\Jobs\CatalogDelete; /** * Multimedia Controller Functions @@ -80,13 +80,12 @@ trait Multimedia if ($delete && $o->remove && ($request->input('remove.'.$id) ? 1 : NULL)) { switch (strtolower($request->input('type'))) { case 'photo': - $this->dispatch((new PhotoDelete($o))->onQueue('delete')); - Log::info(sprintf('Dispatching delete for [%s]',$o->id)); - break; - case 'video': - $this->dispatch((new VideoDelete($o))->onQueue('delete')); Log::info(sprintf('Dispatching delete for [%s]',$o->id)); + + CatalogDelete::dispatch($o) + ->onQueue('delete'); + break; default: