Skip to content

Commit 5600f32

Browse files
committed
Add support for deleting service packs.
1 parent d472942 commit 5600f32

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

app/Http/Controllers/Admin/PackController.php

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,34 @@ public function edit(Request $request, $id)
138138

139139
public function update(Request $request, $id)
140140
{
141-
try {
142-
$repo = new Pack;
143-
$repo->update($id, $request->except([
144-
'_token'
145-
]));
146-
Alert::success('Service pack has been successfully updated.')->flash();
147-
} catch (DisplayValidationException $ex) {
148-
return redirect()->route('admin.services.packs.edit', $id)->withErrors(json_decode($ex->getMessage()))->withInput();
149-
} catch (\Exception $ex) {
150-
Log::error($ex);
151-
Alert::danger('An error occured while attempting to add edit this pack.')->flash();
141+
if (!is_null($request->input('action_delete'))) {
142+
try {
143+
$repo = new Pack;
144+
$repo->delete($id);
145+
Alert::success('The requested service pack has been deleted from the system.')->flash();
146+
return redirect()->route('admin.services.packs');
147+
} catch (DisplayException $ex) {
148+
Alert::danger($ex->getMessage())->flash();
149+
} catch (\Exception $ex) {
150+
Log::error($ex);
151+
Alert::danger('An error occured while attempting to delete this pack.')->flash();
152+
}
153+
return redirect()->route('admin.services.packs.edit', $id);
154+
} else {
155+
try {
156+
$repo = new Pack;
157+
$repo->update($id, $request->except([
158+
'_token'
159+
]));
160+
Alert::success('Service pack has been successfully updated.')->flash();
161+
} catch (DisplayValidationException $ex) {
162+
return redirect()->route('admin.services.packs.edit', $id)->withErrors(json_decode($ex->getMessage()))->withInput();
163+
} catch (\Exception $ex) {
164+
Log::error($ex);
165+
Alert::danger('An error occured while attempting to add edit this pack.')->flash();
166+
}
167+
return redirect()->route('admin.services.packs.edit', $id);
152168
}
153-
return redirect()->route('admin.services.packs.edit', $id);
154169
}
155170

156171
public function export(Request $request, $id, $files = false)

app/Repositories/ServiceRepository/Pack.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,13 @@ public function update($id, array $data)
225225
});
226226
}
227227

228+
public function delete($id) {
229+
$pack = Models\ServicePack::findOrFail($id);
230+
// @TODO Check for linked servers; foreign key should block this.
231+
DB::transaction(function () use ($pack) {
232+
$pack->delete();
233+
Storage::deleteDirectory('packs/' . $pack->uuid);
234+
});
235+
}
236+
228237
}

resources/views/admin/services/packs/edit.blade.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@
186186
<div class="col-md-12">
187187
<div class="form-group">
188188
{!! csrf_field() !!}
189-
<input type="submit" class="btn btn-sm btn-primary" value="Edit Service Pack" />
190-
<a href="{{ route('admin.services.packs.export', $pack->id) }}"><button type="button" class="pull-right btn btn-sm btn-default"><i class="fa fa-file"></i> Export</button></a>
189+
<input type="submit" name="action_submit" class="btn btn-sm btn-primary" value="Edit Service Pack" />
190+
<button type="submit" name="action_delete" class="pull-right btn btn-sm btn-danger"><i class="fa fa-times"></i> Delete</button>
191+
<a href="{{ route('admin.services.packs.export', $pack->id) }}"><button type="button" class="pull-right btn btn-sm btn-default" style="margin-right:10px;"><i class="fa fa-file"></i> Export</button></a>
191192
<a href="{{ route('admin.services.packs.export', [ $pack->id, 'true' ]) }}"><button type="button" class="pull-right btn btn-sm btn-default" style="margin-right:10px;"><i class="fa fa-download"></i> Export with Files</button></a>
192193
</div>
193194
</div>

0 commit comments

Comments
 (0)