Fixes bug introduced during admin rewrite that broke server creation

This commit is contained in:
Dane Everitt 2017-03-16 21:11:15 -04:00
parent be60299089
commit 4ad09c5435
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
4 changed files with 60 additions and 50 deletions

View File

@ -454,9 +454,10 @@ class ServersController extends Controller
* *
* @param Request $request * @param Request $request
* @param int $id * @param int $id
* @param string $method
* @return \Illuminate\Response\RedirectResponse * @return \Illuminate\Response\RedirectResponse
*/ */
public function continueDeletion(Request $request, $id, $method) public function continueDeletion(Request $request, $id, $method = 'safe')
{ {
$repo = new ServerRepository; $repo = new ServerRepository;

View File

@ -97,8 +97,8 @@ class Node extends Model
{ {
return new Client([ return new Client([
'base_uri' => sprintf('%s://%s:%s/', $this->scheme, $this->fqdn, $this->daemonListen), 'base_uri' => sprintf('%s://%s:%s/', $this->scheme, $this->fqdn, $this->daemonListen),
'timeout' => env('GUZZLE_TIMEOUT', 5.0), 'timeout' => config('pterodactyl.guzzle.timeout'),
'connect_timeout' => env('GUZZLE_CONNECT_TIMEOUT', 3.0), 'connect_timeout' => config('pterodactyl.guzzle.connect_timeout'),
'headers' => $headers, 'headers' => $headers,
]); ]);
} }

View File

@ -314,10 +314,10 @@ class ServerRepository
'io' => (int) $server->io, 'io' => (int) $server->io,
'cpu' => (int) $server->cpu, 'cpu' => (int) $server->cpu,
'disk' => (int) $server->disk, 'disk' => (int) $server->disk,
'image' => (isset($data['custom_container'])) ? $data['custom_container'] : $option->docker_image, 'image' => $server->image,
], ],
'service' => [ 'service' => [
'type' => $service->file, 'type' => $service->folder,
'option' => $option->tag, 'option' => $option->tag,
'pack' => (isset($pack)) ? $pack->uuid : null, 'pack' => (isset($pack)) ? $pack->uuid : null,
], ],
@ -701,7 +701,6 @@ class ServerRepository
$server->installed = 3; $server->installed = 3;
$server->save(); $server->save();
} }
$server->delete(); $server->delete();
return DB::commit(); return DB::commit();
@ -713,7 +712,7 @@ class ServerRepository
public function delete($id, $force = false) public function delete($id, $force = false)
{ {
$server = Models\Server::withTrashed()->with('node')->findOrFail($id); $server = Models\Server::withTrashed()->with('node', 'allocations', 'variables')->findOrFail($id);
// Handle server being restored previously or // Handle server being restored previously or
// an accidental queue. // an accidental queue.
@ -721,17 +720,34 @@ class ServerRepository
return; return;
} }
DB::beginTransaction(); // Due to MySQL lockouts if the daemon response fails, we need to
// delete the server from the daemon first. If it succeedes and then
// MySQL fails, users just need to force delete the server.
//
// If this is a force delete, continue anyways.
try { try {
// Unassign Allocations $server->node->guzzleClient([
Models\Allocation::where('server_id', $server->id)->update([ 'X-Access-Token' => $server->node->daemonSecret,
'server_id' => null, 'X-Access-Server' => $server->uuid,
]); ])->request('DELETE', '/servers');
} catch (TransferException $ex) {
if ($server->installed !== 3 && ! $force) {
throw new DisplayException($ex->getMessage());
}
} catch (\Exception $ex) {
throw $ex;
}
// Remove Variables DB::transaction(function () use ($server) {
Models\ServerVariable::where('server_id', $server->id)->delete(); $server->allocations->each(function ($item) {
$item->server_id = null;
$item->save();
});
$server->variables->each(function ($item) {
$item->delete();
});
// Remove SubUsers
foreach (Models\Subuser::with('permissions')->where('server_id', $server->id)->get() as &$subuser) { foreach (Models\Subuser::with('permissions')->where('server_id', $server->id)->get() as &$subuser) {
foreach ($subuser->permissions as &$permission) { foreach ($subuser->permissions as &$permission) {
$permission->delete(); $permission->delete();
@ -748,33 +764,14 @@ class ServerRepository
// Delete Databases // Delete Databases
// This is the one un-recoverable point where // This is the one un-recoverable point where
// transactions will not save us. // transactions will not save us.
// $repository = new DatabaseRepository;
// @TODO: move to post-deletion event as a queued task! foreach (Models\Database::select('id')->where('server_id', $server->id)->get() as $database) {
// $repository = new DatabaseRepository; $repository->drop($database->id);
// foreach (Models\Database::select('id')->where('server_id', $server->id)->get() as &$database) {
// $repository->drop($database->id);
// }
$server->node->guzzleClient([
'X-Access-Token' => $server->node->daemonSecret,
'X-Access-Server' => $server->uuid,
])->request('DELETE', '/servers');
$server->forceDelete();
DB::commit();
} catch (TransferException $ex) {
// Set installed is set to 3 when force deleting.
if ($server->installed === 3 || $force) {
$server->forceDelete();
DB::commit();
} else {
DB::rollBack();
throw $ex;
} }
} catch (\Exception $ex) {
DB::rollBack(); // Fully delete the server.
throw $ex; $server->forceDelete();
} });
} }
public function cancelDeletion($id) public function cancelDeletion($id)

View File

@ -11,10 +11,10 @@ return [
| author of custom services, and make upgrades easier by identifying | author of custom services, and make upgrades easier by identifying
| standard Pterodactyl shipped services. | standard Pterodactyl shipped services.
*/ */
'service' => [ 'service' => [
'core' => 'ptrdctyl-v040-11e6-8b77-86f30ca893d3', 'core' => 'ptrdctyl-v040-11e6-8b77-86f30ca893d3',
'author' => env('SERVICE_AUTHOR'), 'author' => env('SERVICE_AUTHOR'),
], ],
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -24,10 +24,22 @@ return [
| Certain pagination result counts can be configured here and will take | Certain pagination result counts can be configured here and will take
| effect globally. | effect globally.
*/ */
'paginate' => [ 'paginate' => [
'frontend' => [ 'frontend' => [
'servers' => 15, 'servers' => 15,
], ],
], ],
/*
|--------------------------------------------------------------------------
| Guzzle Connections
|--------------------------------------------------------------------------
|
| Configure the timeout to be used for Guzzle connections here.
*/
'guzzle' => [
'timeout' => env('GUZZLE_TIMEOUT', 5),
'connect_timeout' => env('GUZZLE_CONNECT_TIMEOUT', 3),
],
]; ];