1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-10-27 04:12:28 +01:00

add ability to delete a service

This commit is contained in:
Dane Everitt 2016-02-20 16:23:04 -05:00
parent a50bb5da14
commit 177bd4ec9d
4 changed files with 54 additions and 0 deletions

View File

@ -106,6 +106,22 @@ class ServiceController extends Controller
return redirect()->route('admin.services.service', $service)->withInput();
}
public function deleteService(Request $request, $service)
{
try {
$repo = new ServiceRepository\Service;
$repo->delete($service);
Alert::success('Successfully deleted that service.')->flash();
return redirect()->route('admin.services');
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An error was encountered while attempting to delete that service.')->flash();
}
return redirect()->route('admin.services.service', $service);
}
public function getOption(Request $request, $option)
{
$opt = Models\ServiceOptions::findOrFail($option);

View File

@ -366,6 +366,10 @@ class AdminRoutes {
'uses' => 'Admin\ServiceController@postService'
]);
$router->delete('/service/{id}', [
'uses' => 'Admin\ServiceController@deleteService'
]);
$router->get('/option/{id}', [
'as' => 'admin.services.option',
'uses' => 'Admin\ServiceController@getOption'

View File

@ -85,4 +85,26 @@ class Service
$service->save();
}
public function delete($id)
{
$service = Models\Service::findOrFail($id);
$servers = Models\Server::where('service', $service->id)->get();
$options = Models\ServiceOptions::select('id')->where('parent_service', $service->id);
if (count($servers) !== 0) {
throw new DisplayException('You cannot delete a service that has servers associated with it.');
}
DB::beginTransaction();
try {
Models\ServiceVariables::whereIn('option_id', $options->get()->toArray())->delete();
$options->delete();
$service->delete();
DB::commit();
} catch (\Exception $ex) {
DB::rollBack();
throw $ex;
}
}
}

View File

@ -106,6 +106,18 @@
</div>
</form>
</div>
<form action="{{ route('admin.services.service', $service->id) }}" method="POST">
<div class="row">
<div class="col-md-12">
<div class="alert alert-danger">
Deleting a service is an irreversible action. A service can <em>only</em> be deleted if no servers are associated with it.
</div>
{!! csrf_field() !!}
{!! method_field('DELETE') !!}
<input type="submit" class="btn btn-sm btn-danger pull-right" value="Delete Service" />
</div>
</div>
</form>
</div>
<script>
$(document).ready(function () {