| @@ 81-96 (lines=16) @@ | ||
| 78 | * |
|
| 79 | * @throws \Pterodactyl\Exceptions\DisplayException |
|
| 80 | */ |
|
| 81 | public function delete($id) |
|
| 82 | { |
|
| 83 | $option = ServiceOption::with('variables')->withCount('servers')->findOrFail($id); |
|
| 84 | ||
| 85 | if ($option->servers_count > 0) { |
|
| 86 | throw new DisplayException('You cannot delete a service option that has servers associated with it.'); |
|
| 87 | } |
|
| 88 | ||
| 89 | DB::transaction(function () use ($option) { |
|
| 90 | foreach ($option->variables as $variable) { |
|
| 91 | (new VariableRepository)->delete($variable->id); |
|
| 92 | } |
|
| 93 | ||
| 94 | $option->delete(); |
|
| 95 | }); |
|
| 96 | } |
|
| 97 | ||
| 98 | /** |
|
| 99 | * Updates a service option in the database which can then be used |
|
| @@ 113-128 (lines=16) @@ | ||
| 110 | * @param int $id |
|
| 111 | * @return void |
|
| 112 | */ |
|
| 113 | public function delete($id) |
|
| 114 | { |
|
| 115 | $service = Service::withCount('servers')->with('options')->findOrFail($id); |
|
| 116 | ||
| 117 | if ($service->servers_count > 0) { |
|
| 118 | throw new DisplayException('You cannot delete a service that has servers associated with it.'); |
|
| 119 | } |
|
| 120 | ||
| 121 | DB::transaction(function () use ($service) { |
|
| 122 | foreach ($service->options as $option) { |
|
| 123 | (new OptionRepository)->delete($option->id); |
|
| 124 | } |
|
| 125 | ||
| 126 | $service->delete(); |
|
| 127 | }); |
|
| 128 | } |
|
| 129 | } |
|
| 130 | ||