1 | <?php |
||||||
2 | |||||||
3 | namespace UniSharp\LaravelFilemanager\Controllers; |
||||||
4 | |||||||
5 | use Illuminate\Support\Facades\Storage; |
||||||
6 | use UniSharp\LaravelFilemanager\Events\FileIsDeleting; |
||||||
7 | use UniSharp\LaravelFilemanager\Events\FileWasDeleted; |
||||||
8 | use UniSharp\LaravelFilemanager\Events\FolderIsDeleting; |
||||||
9 | use UniSharp\LaravelFilemanager\Events\FolderWasDeleted; |
||||||
10 | use UniSharp\LaravelFilemanager\Events\ImageIsDeleting; |
||||||
11 | use UniSharp\LaravelFilemanager\Events\ImageWasDeleted; |
||||||
12 | |||||||
13 | class DeleteController extends LfmController |
||||||
14 | { |
||||||
15 | /** |
||||||
16 | * Delete image and associated thumbnail. |
||||||
17 | * |
||||||
18 | * @return mixed |
||||||
19 | */ |
||||||
20 | public function getDelete() |
||||||
21 | { |
||||||
22 | $item_names = request('items'); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
23 | $errors = []; |
||||||
24 | |||||||
25 | foreach ($item_names as $name_to_delete) { |
||||||
26 | $file = $this->lfm->setName($name_to_delete); |
||||||
0 ignored issues
–
show
The method
setName() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() The property
lfm does not exist on UniSharp\LaravelFilemana...ollers\DeleteController . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
27 | |||||||
28 | if ($file->isDirectory()) { |
||||||
29 | event(new FolderIsDeleting($file->path('absolute'))); |
||||||
0 ignored issues
–
show
The function
event was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
30 | } else { |
||||||
31 | event(new FileIsDeleting($file->path('absolute'))); |
||||||
32 | event(new ImageIsDeleting($file->path('absolute'))); |
||||||
33 | } |
||||||
34 | |||||||
35 | if (!Storage::disk($this->helper->config('disk'))->exists($file->path('storage'))) { |
||||||
0 ignored issues
–
show
The property
helper does not exist on UniSharp\LaravelFilemana...ollers\DeleteController . Since you implemented __get , consider adding a @property annotation.
![]() The method
config() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
36 | abort(404); |
||||||
0 ignored issues
–
show
The function
abort was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
37 | } |
||||||
38 | |||||||
39 | $file_to_delete = $this->lfm->pretty($name_to_delete); |
||||||
40 | $file_path = $file_to_delete->path('absolute'); |
||||||
41 | |||||||
42 | if (is_null($name_to_delete)) { |
||||||
43 | array_push($errors, parent::error('folder-name')); |
||||||
44 | continue; |
||||||
45 | } |
||||||
46 | |||||||
47 | if (! $this->lfm->setName($name_to_delete)->exists()) { |
||||||
48 | array_push($errors, parent::error('folder-not-found', ['folder' => $file_path])); |
||||||
49 | continue; |
||||||
50 | } |
||||||
51 | |||||||
52 | if ($this->lfm->setName($name_to_delete)->isDirectory()) { |
||||||
53 | if (! $this->lfm->setName($name_to_delete)->directoryIsEmpty()) { |
||||||
54 | array_push($errors, parent::error('delete-folder')); |
||||||
55 | continue; |
||||||
56 | } |
||||||
57 | |||||||
58 | $this->lfm->setName($name_to_delete)->delete(); |
||||||
59 | |||||||
60 | event(new FolderWasDeleted($file_path)); |
||||||
61 | } else { |
||||||
62 | if ($file_to_delete->isImage()) { |
||||||
63 | $this->lfm->setName($name_to_delete)->thumb()->delete(); |
||||||
64 | } |
||||||
65 | |||||||
66 | $this->lfm->setName($name_to_delete)->delete(); |
||||||
67 | |||||||
68 | event(new FileWasDeleted($file_path)); |
||||||
69 | event(new ImageWasDeleted($file_path)); |
||||||
70 | } |
||||||
71 | } |
||||||
72 | |||||||
73 | if (count($errors) > 0) { |
||||||
74 | return response()->json($errors, 400); |
||||||
0 ignored issues
–
show
The function
response was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
75 | } |
||||||
76 | |||||||
77 | return parent::$success_response; |
||||||
78 | } |
||||||
79 | } |
||||||
80 |