56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Web;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Customer;
|
|
use App\Models\VmSnapshot;
|
|
use App\Services\Hosting\Snapshots\SnapshotService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class VmSnapshotController extends Controller
|
|
{
|
|
public function store(Request $request, Customer $vm, SnapshotService $snapshots): RedirectResponse
|
|
{
|
|
$this->authorize('manage', $vm);
|
|
$request->validate(['label' => ['nullable', 'string', 'max:64']]);
|
|
|
|
try {
|
|
$snapshots->create($vm, $request->user(), false, $request->input('label'));
|
|
} catch (\Throwable $e) {
|
|
return back()->withErrors(['snapshot' => $e->getMessage()]);
|
|
}
|
|
|
|
return back()->with('success', 'Snapshot erstellt.');
|
|
}
|
|
|
|
public function rollback(Customer $vm, VmSnapshot $snapshot, SnapshotService $snapshots): RedirectResponse
|
|
{
|
|
$this->authorize('manage', $vm);
|
|
abort_unless($snapshot->customer_id === $vm->id, 404);
|
|
|
|
try {
|
|
$snapshots->rollback($vm, $snapshot);
|
|
} catch (\Throwable $e) {
|
|
return back()->withErrors(['snapshot' => $e->getMessage()]);
|
|
}
|
|
|
|
return back()->with('success', 'Snapshot wiederhergestellt.');
|
|
}
|
|
|
|
public function destroy(Customer $vm, VmSnapshot $snapshot, SnapshotService $snapshots): RedirectResponse
|
|
{
|
|
$this->authorize('manage', $vm);
|
|
abort_unless($snapshot->customer_id === $vm->id, 404);
|
|
|
|
try {
|
|
$snapshots->delete($vm, $snapshot);
|
|
} catch (\Throwable $e) {
|
|
return back()->withErrors(['snapshot' => $e->getMessage()]);
|
|
}
|
|
|
|
return back()->with('success', 'Snapshot gelöscht.');
|
|
}
|
|
}
|