Skip to content

Commit a75a347

Browse files
committed
Remove suspended & installing fields, replace with single status field
1 parent 4c29be2 commit a75a347

File tree

24 files changed

+115
-59
lines changed

24 files changed

+115
-59
lines changed

app/Http/Controllers/Admin/Servers/ServerViewController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function mounts(Request $request, Server $server)
207207
*/
208208
public function manage(Request $request, Server $server)
209209
{
210-
if ($server->installed > 1) {
210+
if ($server->status === Server::STATUS_INSTALL_FAILED) {
211211
throw new DisplayException(
212212
'This server is in a failed install state and cannot be recovered. Please delete and re-create the server.'
213213
);

app/Http/Controllers/Admin/ServersController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,12 @@ public function setDetails(Request $request, Server $server)
228228
*/
229229
public function toggleInstall(Server $server)
230230
{
231-
if ($server->installed > 1) {
231+
if ($server->status === Server::STATUS_INSTALL_FAILED) {
232232
throw new DisplayException(trans('admin/server.exceptions.marked_as_failed'));
233233
}
234234

235235
$this->repository->update($server->id, [
236-
'installed' => ! $server->installed,
236+
'status' => $server->isInstalled() ? Server::STATUS_INSTALLING : null,
237237
], true, true);
238238

239239
$this->alert->success(trans('admin/server.alerts.install_toggled'))->flash();

app/Http/Controllers/Api/Remote/SftpAuthenticationController.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ public function __invoke(SftpAuthenticationFormRequest $request): JsonResponse
118118

119119
// Remember, for security purposes, only reveal the existence of the server to people that
120120
// have provided valid credentials, and have permissions to know about it.
121-
if ($server->installed !== 1 || $server->suspended) {
122-
throw new BadRequestHttpException(
123-
'Server is not installed or is currently suspended.'
124-
);
121+
if ($server->isSuspended() || !$server->isInstalled()) {
122+
throw new BadRequestHttpException('Server is not installed or is currently suspended.');
125123
}
126124

127125
return new JsonResponse([

app/Http/Middleware/Admin/Servers/ServerInstalled.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function handle(Request $request, Closure $next)
2929
);
3030
}
3131

32-
if ($server->installed !== 1) {
32+
if (! $server->isInstalled()) {
3333
throw new HttpException(
3434
Response::HTTP_FORBIDDEN, 'Access to this resource is not allowed due to the current installation state.'
3535
);

app/Http/Middleware/Api/Client/Server/AuthenticateServerAccess.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function handle(Request $request, Closure $next)
6464
}
6565
}
6666

67-
if ($server->suspended && ! $request->routeIs('api:client:server.resources')) {
67+
if ($server->isSuspended() && ! $request->routeIs('api:client:server.resources')) {
6868
throw new BadRequestHttpException(
6969
'This server is currently suspended and the functionality requested is unavailable.'
7070
);

app/Http/Middleware/Server/AccessingValidServer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function handle(Request $request, Closure $next)
6363
$isApiRequest = $request->expectsJson() || $request->is(...$this->config->get('pterodactyl.json_routes', []));
6464
$server = $this->repository->getByUuid($attributes instanceof Server ? $attributes->uuid : $attributes);
6565

66-
if ($server->suspended) {
66+
if ($server->isSuspended()) {
6767
if ($isApiRequest) {
6868
throw new AccessDeniedHttpException('Server is suspended and cannot be accessed.');
6969
}
@@ -73,7 +73,7 @@ public function handle(Request $request, Closure $next)
7373

7474
// Servers can have install statuses other than 1 or 0, so don't check
7575
// for a bool-type operator here.
76-
if ($server->installed !== 1) {
76+
if (! $server->isInstalled()) {
7777
if ($isApiRequest) {
7878
throw new ConflictHttpException('Server is still completing the installation process.');
7979
}

app/Models/Server.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
* @property int $node_id
1616
* @property string $name
1717
* @property string $description
18+
* @property string|null $status
1819
* @property bool $skip_scripts
19-
* @property bool $suspended
2020
* @property int $owner_id
2121
* @property int $memory
2222
* @property int $swap
@@ -30,7 +30,6 @@
3030
* @property int $egg_id
3131
* @property string $startup
3232
* @property string $image
33-
* @property int $installed
3433
* @property int $allocation_limit
3534
* @property int $database_limit
3635
* @property int $backup_limit
@@ -64,9 +63,9 @@ class Server extends Model
6463
*/
6564
const RESOURCE_NAME = 'server';
6665

67-
const STATUS_INSTALLING = 0;
68-
const STATUS_INSTALLED = 1;
69-
const STATUS_INSTALL_FAILED = 2;
66+
const STATUS_INSTALLING = 'installing';
67+
const STATUS_INSTALL_FAILED = 'install_failed';
68+
const STATUS_SUSPENDED = 'suspended';
7069

7170
/**
7271
* The table associated with the model.
@@ -82,6 +81,7 @@ class Server extends Model
8281
* @var array
8382
*/
8483
protected $attributes = [
84+
'status' => self::STATUS_INSTALLING,
8585
'oom_disabled' => true,
8686
];
8787

@@ -104,7 +104,7 @@ class Server extends Model
104104
*
105105
* @var array
106106
*/
107-
protected $guarded = ['id', 'installed', self::CREATED_AT, self::UPDATED_AT, 'deleted_at'];
107+
protected $guarded = ['id', self::CREATED_AT, self::UPDATED_AT, 'deleted_at'];
108108

109109
/**
110110
* @var array
@@ -115,6 +115,7 @@ class Server extends Model
115115
'name' => 'required|string|min:1|max:191',
116116
'node_id' => 'required|exists:nodes,id',
117117
'description' => 'string',
118+
'status' => 'nullable|string',
118119
'memory' => 'required|numeric|min:0',
119120
'swap' => 'required|numeric|min:-1',
120121
'io' => 'required|numeric|between:10,1000',
@@ -142,7 +143,6 @@ class Server extends Model
142143
protected $casts = [
143144
'node_id' => 'integer',
144145
'skip_scripts' => 'boolean',
145-
'suspended' => 'boolean',
146146
'owner_id' => 'integer',
147147
'memory' => 'integer',
148148
'swap' => 'integer',
@@ -153,7 +153,6 @@ class Server extends Model
153153
'allocation_id' => 'integer',
154154
'nest_id' => 'integer',
155155
'egg_id' => 'integer',
156-
'installed' => 'integer',
157156
'database_limit' => 'integer',
158157
'allocation_limit' => 'integer',
159158
'backup_limit' => 'integer',
@@ -176,7 +175,12 @@ public function getAllocationMappings(): array
176175
*/
177176
public function isInstalled(): bool
178177
{
179-
return $this->installed === 1;
178+
return $this->status !== self::STATUS_INSTALLING && $this->status !== self::STATUS_INSTALL_FAILED;
179+
}
180+
181+
public function isSuspended(): bool
182+
{
183+
return $this->status === self::STATUS_SUSPENDED;
180184
}
181185

182186
/**

app/Services/Servers/ReinstallServerService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(
4444
public function handle(Server $server)
4545
{
4646
return $this->connection->transaction(function () use ($server) {
47-
$server->forceFill(['installed' => Server::STATUS_INSTALLING])->save();
47+
$server->fill(['status' => Server::STATUS_INSTALLING])->save();
4848

4949
$this->daemonServerRepository->setServer($server)->reinstall();
5050

app/Services/Servers/ServerConfigurationStructureService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected function returnCurrentFormat(Server $server)
6060
{
6161
return [
6262
'uuid' => $server->uuid,
63-
'suspended' => $server->suspended,
63+
'suspended' => $server->isSuspended(),
6464
'environment' => $this->environment->handle($server),
6565
'invocation' => $server->startup,
6666
'skip_egg_scripts' => $server->skip_scripts,
@@ -137,7 +137,7 @@ protected function returnLegacyFormat(Server $server)
137137
'skip_scripts' => $server->skip_scripts,
138138
],
139139
'rebuild' => false,
140-
'suspended' => (int)$server->suspended,
140+
'suspended' => $server->isSuspended() ? 1 : 0,
141141
];
142142
}
143143
}

app/Services/Servers/ServerCreationService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ private function createModel(array $data): Server
229229
'node_id' => Arr::get($data, 'node_id'),
230230
'name' => Arr::get($data, 'name'),
231231
'description' => Arr::get($data, 'description') ?? '',
232+
'status' => Server::STATUS_INSTALLING,
232233
'skip_scripts' => Arr::get($data, 'skip_scripts') ?? isset($data['skip_scripts']),
233-
'suspended' => false,
234234
'owner_id' => Arr::get($data, 'owner_id'),
235235
'memory' => Arr::get($data, 'memory'),
236236
'swap' => Arr::get($data, 'swap'),

0 commit comments

Comments
 (0)