| Conditions | 8 |
| Paths | 14 |
| Total Lines | 42 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | public function getDelete() |
||
| 16 | { |
||
| 17 | $item_names = request('items'); |
||
|
|
|||
| 18 | $errors = []; |
||
| 19 | |||
| 20 | foreach ($item_names as $name_to_delete) { |
||
| 21 | $file_to_delete = $this->lfm->pretty($name_to_delete); |
||
| 22 | $file_path = $file_to_delete->path(); |
||
| 23 | |||
| 24 | event(new ImageIsDeleting($file_path)); |
||
| 25 | |||
| 26 | if (is_null($name_to_delete)) { |
||
| 27 | array_push($errors, parent::error('folder-name')); |
||
| 28 | continue; |
||
| 29 | } |
||
| 30 | |||
| 31 | if (! $this->lfm->setName($name_to_delete)->exists()) { |
||
| 32 | array_push($errors, parent::error('folder-not-found', ['folder' => $file_path])); |
||
| 33 | continue; |
||
| 34 | } |
||
| 35 | |||
| 36 | if ($this->lfm->setName($name_to_delete)->isDirectory()) { |
||
| 37 | if (! $this->lfm->setName($name_to_delete)->directoryIsEmpty()) { |
||
| 38 | array_push($errors, parent::error('delete-folder')); |
||
| 39 | continue; |
||
| 40 | } |
||
| 41 | } else { |
||
| 42 | if ($file_to_delete->isImage()) { |
||
| 43 | $this->lfm->setName($name_to_delete)->thumb()->delete(); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | $this->lfm->setName($name_to_delete)->delete(); |
||
| 48 | |||
| 49 | event(new ImageWasDeleted($file_path)); |
||
| 50 | } |
||
| 51 | |||
| 52 | if (count($errors) > 0) { |
||
| 53 | return $errors; |
||
| 54 | } |
||
| 55 | |||
| 56 | return parent::$success_response; |
||
| 57 | } |
||
| 59 |