From 5600f3201c85e43de14965c2ee2d522c8e77baba Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 18 Nov 2016 17:31:57 -0500 Subject: [PATCH] Add support for deleting service packs. --- app/Http/Controllers/Admin/PackController.php | 39 +++++++++++++------ app/Repositories/ServiceRepository/Pack.php | 9 +++++ .../views/admin/services/packs/edit.blade.php | 5 ++- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Admin/PackController.php b/app/Http/Controllers/Admin/PackController.php index acb05c7a..c94a001d 100644 --- a/app/Http/Controllers/Admin/PackController.php +++ b/app/Http/Controllers/Admin/PackController.php @@ -138,19 +138,34 @@ class PackController extends Controller public function update(Request $request, $id) { - try { - $repo = new Pack; - $repo->update($id, $request->except([ - '_token' - ])); - Alert::success('Service pack has been successfully updated.')->flash(); - } catch (DisplayValidationException $ex) { - return redirect()->route('admin.services.packs.edit', $id)->withErrors(json_decode($ex->getMessage()))->withInput(); - } catch (\Exception $ex) { - Log::error($ex); - Alert::danger('An error occured while attempting to add edit this pack.')->flash(); + if (!is_null($request->input('action_delete'))) { + try { + $repo = new Pack; + $repo->delete($id); + Alert::success('The requested service pack has been deleted from the system.')->flash(); + return redirect()->route('admin.services.packs'); + } catch (DisplayException $ex) { + Alert::danger($ex->getMessage())->flash(); + } catch (\Exception $ex) { + Log::error($ex); + Alert::danger('An error occured while attempting to delete this pack.')->flash(); + } + return redirect()->route('admin.services.packs.edit', $id); + } else { + try { + $repo = new Pack; + $repo->update($id, $request->except([ + '_token' + ])); + Alert::success('Service pack has been successfully updated.')->flash(); + } catch (DisplayValidationException $ex) { + return redirect()->route('admin.services.packs.edit', $id)->withErrors(json_decode($ex->getMessage()))->withInput(); + } catch (\Exception $ex) { + Log::error($ex); + Alert::danger('An error occured while attempting to add edit this pack.')->flash(); + } + return redirect()->route('admin.services.packs.edit', $id); } - return redirect()->route('admin.services.packs.edit', $id); } public function export(Request $request, $id, $files = false) diff --git a/app/Repositories/ServiceRepository/Pack.php b/app/Repositories/ServiceRepository/Pack.php index c4b3529d..5d8591b6 100644 --- a/app/Repositories/ServiceRepository/Pack.php +++ b/app/Repositories/ServiceRepository/Pack.php @@ -225,4 +225,13 @@ class Pack }); } + public function delete($id) { + $pack = Models\ServicePack::findOrFail($id); + // @TODO Check for linked servers; foreign key should block this. + DB::transaction(function () use ($pack) { + $pack->delete(); + Storage::deleteDirectory('packs/' . $pack->uuid); + }); + } + } diff --git a/resources/views/admin/services/packs/edit.blade.php b/resources/views/admin/services/packs/edit.blade.php index abc89fe9..b71256fd 100644 --- a/resources/views/admin/services/packs/edit.blade.php +++ b/resources/views/admin/services/packs/edit.blade.php @@ -186,8 +186,9 @@
{!! csrf_field() !!} - - + + +