Remove deletion queue for servers. Just immediately delete.

This commit is contained in:
Dane Everitt 2017-03-31 22:12:31 -04:00
parent 2dec659dd1
commit 536865b22a
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
16 changed files with 32 additions and 294 deletions

View file

@ -17,6 +17,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
* Subuser permissions are now stored in `Permission::list()` to make views way cleaner and make adding to views significantly cleaner.
* `[pre.7]` — Sidebar for file manager now is a single link rather than a dropdown.
* Attempting to reset a password for an account that does not exist no longer returns an error, rather it displays a success message. Failed resets trigger a `Pterodactyl\Events\Auth\FailedPasswordReset` event that can be caught if needed to perform other actions.
* Servers are no longer queued for deletion due to the general hassle and extra logic required.
## v0.6.0-pre.7 (Courageous Carniadactylus)
### Fixed

View file

@ -219,7 +219,7 @@ class ServerController extends BaseController
$repo = new ServerRepository;
try {
$repo->deleteServer($id, $force);
$repo->delete($id, is_null($force));
return $this->response->noContent();
} catch (DisplayException $ex) {

View file

@ -46,9 +46,7 @@ class ServersController extends Controller
*/
public function index(Request $request)
{
$servers = Models\Server::withTrashed()->with(
'node', 'user', 'allocation'
);
$servers = Models\Server::with('node', 'user', 'allocation');
if (! is_null($request->input('query'))) {
$servers->search($request->input('query'));
@ -146,7 +144,7 @@ class ServersController extends Controller
*/
public function viewIndex(Request $request, $id)
{
return view('admin.servers.view.index', ['server' => Models\Server::withTrashed()->findOrFail($id)]);
return view('admin.servers.view.index', ['server' => Models\Server::findOrFail($id)]);
}
/**
@ -238,7 +236,7 @@ class ServersController extends Controller
*/
public function viewDelete(Request $request, $id)
{
return view('admin.servers.view.delete', ['server' => Models\Server::withTrashed()->findOrFail($id)]);
return view('admin.servers.view.delete', ['server' => Models\Server::findOrFail($id)]);
}
/**
@ -420,49 +418,7 @@ class ServersController extends Controller
$repo = new ServerRepository;
try {
$repo->queueDeletion($id, ($request->input('is_force') > 0));
Alert::success('Server has been marked for deletion on the system.')->flash();
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled exception occured while attemping to delete this server. This error has been logged.')->flash();
}
return redirect()->route('admin.servers.view.delete', $id);
}
/**
* Cancels a pending server deletion request.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\RedirectResponse
*/
public function cancelDeletion(Request $request, $id)
{
$repo = new ServerRepository;
$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.delete', $id);
}
/**
* Skips the queue and continues the server deletion process.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @param string $method
* @return \Illuminate\Http\RedirectResponse
*/
public function continueDeletion(Request $request, $id, $method = 'safe')
{
$repo = new ServerRepository;
try {
$repo->delete($id, (isset($method) && $method === 'force'));
$repo->delete($id, $request->has('force_delete'));
Alert::success('Server was successfully deleted from the system.')->flash();
return redirect()->route('admin.servers');

View file

@ -1,64 +0,0 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Jobs;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Pterodactyl\Repositories\ServerRepository;
class DeleteServer extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
/**
* ID of server to be deleted.
*
* @var int
*/
protected $id;
/**
* Create a new job instance.
*
* @param int $id
* @return void
*/
public function __construct($id)
{
$this->id = $id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$repo = new ServerRepository;
$repo->delete($this->id);
}
}

View file

@ -1,64 +0,0 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Jobs;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Pterodactyl\Repositories\ServerRepository;
class SuspendServer extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
/**
* ID of associated server model.
*
* @var int
*/
protected $id;
/**
* Create a new job instance.
*
* @param int $id
* @return void
*/
public function __construct($id)
{
$this->id = $id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$repo = new ServerRepository;
$repo->suspend($this->id, true);
}
}

View file

@ -30,12 +30,11 @@ use Carbon;
use Javascript;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Nicolaslopezj\Searchable\SearchableTrait;
class Server extends Model
{
use Notifiable, SearchableTrait, SoftDeletes;
use Notifiable, SearchableTrait;
/**
* The table associated with the model.

View file

@ -78,8 +78,6 @@ class ServerObserver
public function deleting(Server $server)
{
event(new Events\Server\Deleting($server));
$this->dispatch((new SuspendServer($server->id))->onQueue(config('pterodactyl.queues.high')));
}
/**
@ -91,12 +89,6 @@ class ServerObserver
public function deleted(Server $server)
{
event(new Events\Server\Deleted($server));
$this->dispatch(
(new DeleteServer($server->id))
->delay(Carbon::now()->addMinutes(config('pterodactyl.tasks.delete_server')))
->onQueue(config('pterodactyl.queues.standard'))
);
}
/**

View file

@ -719,25 +719,6 @@ class ServerRepository
});
}
/**
* Queue a server for deletion.
*
* @param int $id
* @param bool $force
* @return void
*/
public function queueDeletion($id, $force = false)
{
$server = Models\Server::findOrFail($id);
DB::transaction(function () use ($force, $server) {
$server->installed = $force ? 3 : $server->installed;
$server->save();
$server->delete();
});
}
/**
* Delete a server from the system permanetly.
*
@ -749,13 +730,7 @@ class ServerRepository
*/
public function delete($id, $force = false)
{
$server = Models\Server::withTrashed()->with('node', 'allocations', 'variables')->findOrFail($id);
// Handle server being restored previously or
// an accidental queue.
if (! $server->trashed()) {
return;
}
$server = Models\Server::with('node', 'allocations', 'variables')->findOrFail($id);
// Due to MySQL lockouts if the daemon response fails, we need to
// delete the server from the daemon first. If it succeedes and then
@ -768,7 +743,7 @@ class ServerRepository
'X-Access-Server' => $server->uuid,
])->request('DELETE', '/servers');
} catch (TransferException $ex) {
if ($server->installed !== 3 && ! $force) {
if (! $force) {
throw new DisplayException($ex->getMessage());
}
} catch (\Exception $ex) {
@ -807,25 +782,10 @@ class ServerRepository
}
// Fully delete the server.
$server->forceDelete();
$server->delete();
});
}
/**
* Cancel the deletion of a server.
*
* @param int $id
* @return void
*/
public function cancelDeletion($id)
{
$server = Models\Server::withTrashed()->findOrFail($id);
$server->restore();
$server->installed = 1;
$server->save();
}
/**
* Toggle the install status of a serve.
*
@ -856,7 +816,7 @@ class ServerRepository
*/
public function suspend($id, $deleted = false)
{
$server = Models\Server::withTrashed()->with('node')->findOrFail($id);
$server = Models\Server::with('node')->findOrFail($id);
DB::beginTransaction();

View file

@ -70,10 +70,8 @@
<code>{{ $server->allocation->alias }}:{{ $server->allocation->port }}</code>
</td>
<td class="text-center">
@if($server->suspended && ! $server->trashed())
@if($server->suspended)
<span class="label bg-maroon">Suspended</span>
@elseif($server->trashed())
<span class="label label-danger">Pending Deletion</span>
@elseif(! $server->installed)
<span class="label label-warning">Installing</span>
@else
@ -85,9 +83,11 @@
</tbody>
</table>
</div>
<div class="box-footer with-border">
<div class="col-md-12 text-center">{!! $servers->render() !!}</div>
</div>
@if($servers->hasPages())
<div class="box-footer with-border">
<div class="col-md-12 text-center">{!! $servers->render() !!}</div>
</div>
@endif
</div>
</div>
</div>

View file

@ -39,15 +39,13 @@
<div class="nav-tabs-custom nav-tabs-floating">
<ul class="nav nav-tabs">
<li><a href="{{ route('admin.servers.view', $server->id) }}">About</a></li>
@if(! $server->trashed() && $server->installed === 1)
@if($server->installed === 1)
<li><a href="{{ route('admin.servers.view.details', $server->id) }}">Details</a></li>
<li class="active"><a href="{{ route('admin.servers.view.build', $server->id) }}">Build Configuration</a></li>
<li><a href="{{ route('admin.servers.view.startup', $server->id) }}">Startup</a></li>
<li><a href="{{ route('admin.servers.view.database', $server->id) }}">Database</a></li>
@endif
@if(! $server->trashed())
<li><a href="{{ route('admin.servers.view.manage', $server->id) }}">Manage</a></li>
@endif
<li><a href="{{ route('admin.servers.view.manage', $server->id) }}">Manage</a></li>
<li class="tab-danger"><a href="{{ route('admin.servers.view.delete', $server->id) }}">Delete</a></li>
</ul>
</div>

View file

@ -39,15 +39,13 @@
<div class="nav-tabs-custom nav-tabs-floating">
<ul class="nav nav-tabs">
<li><a href="{{ route('admin.servers.view', $server->id) }}">About</a></li>
@if(! $server->trashed() && $server->installed === 1)
@if($server->installed === 1)
<li><a href="{{ route('admin.servers.view.details', $server->id) }}">Details</a></li>
<li><a href="{{ route('admin.servers.view.build', $server->id) }}">Build Configuration</a></li>
<li><a href="{{ route('admin.servers.view.startup', $server->id) }}">Startup</a></li>
<li class="active"><a href="{{ route('admin.servers.view.database', $server->id) }}">Database</a></li>
@endif
@if(! $server->trashed())
<li><a href="{{ route('admin.servers.view.manage', $server->id) }}">Manage</a></li>
@endif
<li><a href="{{ route('admin.servers.view.manage', $server->id) }}">Manage</a></li>
<li class="tab-danger"><a href="{{ route('admin.servers.view.delete', $server->id) }}">Delete</a></li>
</ul>
</div>

View file

@ -39,48 +39,19 @@
<div class="nav-tabs-custom nav-tabs-floating">
<ul class="nav nav-tabs">
<li><a href="{{ route('admin.servers.view', $server->id) }}">About</a></li>
@if(! $server->trashed() && $server->installed === 1)
@if($server->installed === 1)
<li><a href="{{ route('admin.servers.view.details', $server->id) }}">Details</a></li>
<li><a href="{{ route('admin.servers.view.build', $server->id) }}">Build Configuration</a></li>
<li><a href="{{ route('admin.servers.view.startup', $server->id) }}">Startup</a></li>
<li><a href="{{ route('admin.servers.view.database', $server->id) }}">Database</a></li>
@endif
@if(! $server->trashed())
<li><a href="{{ route('admin.servers.view.manage', $server->id) }}">Manage</a></li>
@endif
<li><a href="{{ route('admin.servers.view.manage', $server->id) }}">Manage</a></li>
<li class="tab-danger active"><a href="{{ route('admin.servers.view.delete', $server->id) }}">Delete</a></li>
</ul>
</div>
</div>
</div>
<div class="row">
@if($server->trashed())
<div class="col-xs-12">
<div class="box box-danger">
<div class="box-header with-border">
<h3 class="box-title">Marked for Deletion</h3>
</div>
<div class="box-body">
<p>This server is currently marked for deletion by the system <strong>{{ Carbon::parse($server->deleted_at)->addMinutes(config('pterodactyl.tasks.delete_server'))->diffForHumans() }}</strong>.</p>
<p class="text-danger small">Deleting a server is an irreversible action. <strong>All server data</strong> (including files and users) will be removed from the system.</p>
</div>
<div class="box-footer">
<form action="{{ route('admin.servers.view.delete.cancel', $server->id) }}" method="POST" style="display:inline;">
{!! csrf_field() !!}
<button type="submit" class="btn btn-default btn-sm">Cancel Deletion Request</button>
</form>
<form data-action="delete" action="{{ route('admin.servers.view.delete.continue', ['id' => $server->id, 'force' => 'force']) }}" method="POST" style="display:inline;">
{!! csrf_field() !!}
<button type="submit" class="btn btn-danger btn-sm pull-right"><strong>Forcibly</strong> Delete Now</button>
</form>
<form data-action="delete" action="{{ route('admin.servers.view.delete.continue', $server->id) }}" method="POST" style="display:inline">
{!! csrf_field() !!}
<button type="submit" class="btn btn-danger btn-sm pull-right" style="margin-right:10px;">Safely Delete Now</button>
</form>
</div>
</div>
</div>
@endif
<div class="col-xs-6">
<div class="box">
<div class="box-header with-border">
@ -93,7 +64,6 @@
<div class="box-footer">
<form action="{{ route('admin.servers.view.delete', $server->id) }}" method="POST">
{!! csrf_field() !!}
<input type="hidden" name="is_force" value="0" />
<button type="submit" class="btn btn-danger">Safely Delete This Server</button>
</form>
</div>
@ -111,7 +81,7 @@
<div class="box-footer">
<form action="{{ route('admin.servers.view.delete', $server->id) }}" method="POST">
{!! csrf_field() !!}
<input type="hidden" name="is_force" value="1" />
<input type="hidden" name="force_delete" value="1" />
<button type="submit" class="btn btn-danger">Forcibly Delete This Server</button>
</form>
</div>

View file

@ -39,15 +39,13 @@
<div class="nav-tabs-custom nav-tabs-floating">
<ul class="nav nav-tabs">
<li><a href="{{ route('admin.servers.view', $server->id) }}">About</a></li>
@if(! $server->trashed() && $server->installed === 1)
@if($server->installed === 1)
<li class="active"><a href="{{ route('admin.servers.view.details', $server->id) }}">Details</a></li>
<li><a href="{{ route('admin.servers.view.build', $server->id) }}">Build Configuration</a></li>
<li><a href="{{ route('admin.servers.view.startup', $server->id) }}">Startup</a></li>
<li><a href="{{ route('admin.servers.view.database', $server->id) }}">Database</a></li>
@endif
@if(! $server->trashed())
<li><a href="{{ route('admin.servers.view.manage', $server->id) }}">Manage</a></li>
@endif
<li><a href="{{ route('admin.servers.view.manage', $server->id) }}">Manage</a></li>
<li class="tab-danger"><a href="{{ route('admin.servers.view.delete', $server->id) }}">Delete</a></li>
</ul>
</div>

View file

@ -38,15 +38,13 @@
<div class="nav-tabs-custom nav-tabs-floating">
<ul class="nav nav-tabs">
<li class="active"><a href="{{ route('admin.servers.view', $server->id) }}">About</a></li>
@if(! $server->trashed() && $server->installed === 1)
@if($server->installed === 1)
<li><a href="{{ route('admin.servers.view.details', $server->id) }}">Details</a></li>
<li><a href="{{ route('admin.servers.view.build', $server->id) }}">Build Configuration</a></li>
<li><a href="{{ route('admin.servers.view.startup', $server->id) }}">Startup</a></li>
<li><a href="{{ route('admin.servers.view.database', $server->id) }}">Database</a></li>
@endif
@if(! $server->trashed())
<li><a href="{{ route('admin.servers.view.manage', $server->id) }}">Manage</a></li>
@endif
<li><a href="{{ route('admin.servers.view.manage', $server->id) }}">Manage</a></li>
<li class="tab-danger"><a href="{{ route('admin.servers.view.delete', $server->id) }}">Delete</a></li>
</ul>
</div>

View file

@ -39,15 +39,13 @@
<div class="nav-tabs-custom nav-tabs-floating">
<ul class="nav nav-tabs">
<li><a href="{{ route('admin.servers.view', $server->id) }}">About</a></li>
@if(! $server->trashed() && $server->installed === 1)
@if($server->installed === 1)
<li><a href="{{ route('admin.servers.view.details', $server->id) }}">Details</a></li>
<li><a href="{{ route('admin.servers.view.build', $server->id) }}">Build Configuration</a></li>
<li><a href="{{ route('admin.servers.view.startup', $server->id) }}">Startup</a></li>
<li><a href="{{ route('admin.servers.view.database', $server->id) }}">Database</a></li>
@endif
@if(! $server->trashed())
<li class="active"><a href="{{ route('admin.servers.view.manage', $server->id) }}">Manage</a></li>
@endif
<li class="active"><a href="{{ route('admin.servers.view.manage', $server->id) }}">Manage</a></li>
<li class="tab-danger"><a href="{{ route('admin.servers.view.delete', $server->id) }}">Delete</a></li>
</ul>
</div>

View file

@ -39,15 +39,13 @@
<div class="nav-tabs-custom nav-tabs-floating">
<ul class="nav nav-tabs">
<li><a href="{{ route('admin.servers.view', $server->id) }}">About</a></li>
@if(! $server->trashed() && $server->installed === 1)
@if($server->installed === 1)
<li><a href="{{ route('admin.servers.view.details', $server->id) }}">Details</a></li>
<li><a href="{{ route('admin.servers.view.build', $server->id) }}">Build Configuration</a></li>
<li class="active"><a href="{{ route('admin.servers.view.startup', $server->id) }}">Startup</a></li>
<li><a href="{{ route('admin.servers.view.database', $server->id) }}">Database</a></li>
@endif
@if(! $server->trashed())
<li><a href="{{ route('admin.servers.view.manage', $server->id) }}">Manage</a></li>
@endif
<li><a href="{{ route('admin.servers.view.manage', $server->id) }}">Manage</a></li>
<li class="tab-danger"><a href="{{ route('admin.servers.view.delete', $server->id) }}">Delete</a></li>
</ul>
</div>