Add server deletion to a queue.

This action allows servers to be deleted, but only be soft-deleted for
10 minutes. After that time period the server will be completely
removed from the database and daemon. This allows some safety if a
server is accidentally deleted.

Force deleting a server will still work. If the daemon is in-accessible
the server will fail to be deleted. When server is soft-deleted admins
can still view its information page in the admin CP, however the server
will be suspended and inaccessible on the front-end or though the
daemon.

Admins can manually delete the server ahead of the delete timer, or if
it failed to delete previously they can do an immediate retry.
This commit is contained in:
Dane Everitt 2016-10-27 20:05:29 -04:00
parent dbec99498d
commit 6fd7c78f0c
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
12 changed files with 377 additions and 38 deletions

View file

@ -51,7 +51,7 @@ class ServersController extends Controller
public function getIndex(Request $request)
{
$query = Models\Server::select(
$query = Models\Server::withTrashed()->select(
'servers.*',
'nodes.name as a_nodeName',
'users.email as a_ownerEmail',
@ -84,7 +84,7 @@ class ServersController extends Controller
$servers = $query->paginate(20);
} catch (\Exception $ex) {
Alert::warning('There was an error with the search parameters provided.');
$servers = Models\Server::select(
$servers = Models\Server::withTrashed()->select(
'servers.*',
'nodes.name as a_nodeName',
'users.email as a_ownerEmail',
@ -112,7 +112,7 @@ class ServersController extends Controller
public function getView(Request $request, $id)
{
$server = Models\Server::select(
$server = Models\Server::withTrashed()->select(
'servers.*',
'nodes.name as a_nodeName',
'users.email as a_ownerEmail',
@ -394,7 +394,7 @@ class ServersController extends Controller
try {
$server = new ServerRepository;
$server->deleteServer($id, $force);
Alert::success('Server was successfully deleted from the panel and the daemon.')->flash();
Alert::success('Server has been marked for deletion on the system.')->flash();
return redirect()->route('admin.servers');
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
@ -510,4 +510,31 @@ class ServersController extends Controller
}
}
public function postQueuedDeletionHandler(Request $request, $id)
{
try {
$repo = new ServerRepository;
if (!is_null($request->input('cancel'))) {
$repo->cancelDeletion($id);
Alert::success('Server deletion has been cancelled. This server will remain suspended until you unsuspend it.')->flash();
return redirect()->route('admin.servers.view', $id);
} else if(!is_null($request->input('delete'))) {
$repo->deleteNow($id);
Alert::success('Server was successfully deleted from the system.')->flash();
return redirect()->route('admin.servers');
} else if(!is_null($request->input('force_delete'))) {
$repo->deleteNow($id, true);
Alert::success('Server was successfully force deleted from the system.')->flash();
return redirect()->route('admin.servers');
}
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
return redirect()->route('admin.servers.view', $id);
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled error occured while attempting to perform this action.')->flash();
return redirect()->route('admin.servers.view', $id);
}
}
}