Skip to content

Commit 4ad09c5

Browse files
committed
Fixes bug introduced during admin rewrite that broke server creation
1 parent be60299 commit 4ad09c5

File tree

4 files changed

+59
-49
lines changed

4 files changed

+59
-49
lines changed

app/Http/Controllers/Admin/ServersController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,10 @@ public function cancelDeletion(Request $request, $id)
454454
*
455455
* @param Request $request
456456
* @param int $id
457+
* @param string $method
457458
* @return \Illuminate\Response\RedirectResponse
458459
*/
459-
public function continueDeletion(Request $request, $id, $method)
460+
public function continueDeletion(Request $request, $id, $method = 'safe')
460461
{
461462
$repo = new ServerRepository;
462463

app/Models/Node.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ public function guzzleClient($headers = [])
9797
{
9898
return new Client([
9999
'base_uri' => sprintf('%s://%s:%s/', $this->scheme, $this->fqdn, $this->daemonListen),
100-
'timeout' => env('GUZZLE_TIMEOUT', 5.0),
101-
'connect_timeout' => env('GUZZLE_CONNECT_TIMEOUT', 3.0),
100+
'timeout' => config('pterodactyl.guzzle.timeout'),
101+
'connect_timeout' => config('pterodactyl.guzzle.connect_timeout'),
102102
'headers' => $headers,
103103
]);
104104
}

app/Repositories/ServerRepository.php

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,10 @@ public function create(array $data)
314314
'io' => (int) $server->io,
315315
'cpu' => (int) $server->cpu,
316316
'disk' => (int) $server->disk,
317-
'image' => (isset($data['custom_container'])) ? $data['custom_container'] : $option->docker_image,
317+
'image' => $server->image,
318318
],
319319
'service' => [
320-
'type' => $service->file,
320+
'type' => $service->folder,
321321
'option' => $option->tag,
322322
'pack' => (isset($pack)) ? $pack->uuid : null,
323323
],
@@ -701,7 +701,6 @@ public function queueDeletion($id, $force = false)
701701
$server->installed = 3;
702702
$server->save();
703703
}
704-
705704
$server->delete();
706705

707706
return DB::commit();
@@ -713,25 +712,42 @@ public function queueDeletion($id, $force = false)
713712

714713
public function delete($id, $force = false)
715714
{
716-
$server = Models\Server::withTrashed()->with('node')->findOrFail($id);
715+
$server = Models\Server::withTrashed()->with('node', 'allocations', 'variables')->findOrFail($id);
717716

718717
// Handle server being restored previously or
719718
// an accidental queue.
720719
if (! $server->trashed()) {
721720
return;
722721
}
723722

724-
DB::beginTransaction();
723+
// Due to MySQL lockouts if the daemon response fails, we need to
724+
// delete the server from the daemon first. If it succeedes and then
725+
// MySQL fails, users just need to force delete the server.
726+
//
727+
// If this is a force delete, continue anyways.
725728
try {
726-
// Unassign Allocations
727-
Models\Allocation::where('server_id', $server->id)->update([
728-
'server_id' => null,
729-
]);
729+
$server->node->guzzleClient([
730+
'X-Access-Token' => $server->node->daemonSecret,
731+
'X-Access-Server' => $server->uuid,
732+
])->request('DELETE', '/servers');
733+
} catch (TransferException $ex) {
734+
if ($server->installed !== 3 && ! $force) {
735+
throw new DisplayException($ex->getMessage());
736+
}
737+
} catch (\Exception $ex) {
738+
throw $ex;
739+
}
740+
741+
DB::transaction(function () use ($server) {
742+
$server->allocations->each(function ($item) {
743+
$item->server_id = null;
744+
$item->save();
745+
});
730746

731-
// Remove Variables
732-
Models\ServerVariable::where('server_id', $server->id)->delete();
747+
$server->variables->each(function ($item) {
748+
$item->delete();
749+
});
733750

734-
// Remove SubUsers
735751
foreach (Models\Subuser::with('permissions')->where('server_id', $server->id)->get() as &$subuser) {
736752
foreach ($subuser->permissions as &$permission) {
737753
$permission->delete();
@@ -748,33 +764,14 @@ public function delete($id, $force = false)
748764
// Delete Databases
749765
// This is the one un-recoverable point where
750766
// transactions will not save us.
751-
//
752-
// @TODO: move to post-deletion event as a queued task!
753-
// $repository = new DatabaseRepository;
754-
// foreach (Models\Database::select('id')->where('server_id', $server->id)->get() as &$database) {
755-
// $repository->drop($database->id);
756-
// }
757-
758-
$server->node->guzzleClient([
759-
'X-Access-Token' => $server->node->daemonSecret,
760-
'X-Access-Server' => $server->uuid,
761-
])->request('DELETE', '/servers');
767+
$repository = new DatabaseRepository;
768+
foreach (Models\Database::select('id')->where('server_id', $server->id)->get() as $database) {
769+
$repository->drop($database->id);
770+
}
762771

772+
// Fully delete the server.
763773
$server->forceDelete();
764-
DB::commit();
765-
} catch (TransferException $ex) {
766-
// Set installed is set to 3 when force deleting.
767-
if ($server->installed === 3 || $force) {
768-
$server->forceDelete();
769-
DB::commit();
770-
} else {
771-
DB::rollBack();
772-
throw $ex;
773-
}
774-
} catch (\Exception $ex) {
775-
DB::rollBack();
776-
throw $ex;
777-
}
774+
});
778775
}
779776

780777
public function cancelDeletion($id)

config/pterodactyl.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
| author of custom services, and make upgrades easier by identifying
1212
| standard Pterodactyl shipped services.
1313
*/
14-
'service' => [
15-
'core' => 'ptrdctyl-v040-11e6-8b77-86f30ca893d3',
16-
'author' => env('SERVICE_AUTHOR'),
17-
],
14+
'service' => [
15+
'core' => 'ptrdctyl-v040-11e6-8b77-86f30ca893d3',
16+
'author' => env('SERVICE_AUTHOR'),
17+
],
1818

1919
/*
2020
|--------------------------------------------------------------------------
@@ -24,10 +24,22 @@
2424
| Certain pagination result counts can be configured here and will take
2525
| effect globally.
2626
*/
27-
'paginate' => [
28-
'frontend' => [
29-
'servers' => 15,
30-
],
31-
],
27+
'paginate' => [
28+
'frontend' => [
29+
'servers' => 15,
30+
],
31+
],
32+
33+
/*
34+
|--------------------------------------------------------------------------
35+
| Guzzle Connections
36+
|--------------------------------------------------------------------------
37+
|
38+
| Configure the timeout to be used for Guzzle connections here.
39+
*/
40+
'guzzle' => [
41+
'timeout' => env('GUZZLE_TIMEOUT', 5),
42+
'connect_timeout' => env('GUZZLE_CONNECT_TIMEOUT', 3),
43+
],
3244

3345
];

0 commit comments

Comments
 (0)