Skip to content

Commit 7d45379

Browse files
committed
Add back support for reinstalling a server
1 parent dfefd88 commit 7d45379

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

app/Models/Server.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ class Server extends Validable
6161
*/
6262
const RESOURCE_NAME = 'server';
6363

64+
const STATUS_INSTALLING = 0;
65+
const STATUS_INSTALLED = 1;
66+
const STATUS_INSTALL_FAILED = 2;
67+
6468
/**
6569
* The table associated with the model.
6670
*

app/Repositories/Wings/DaemonServerRepository.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Pterodactyl\Repositories\Wings;
44

5-
use BadMethodCallException;
65
use Webmozart\Assert\Assert;
76
use Pterodactyl\Models\Server;
87
use GuzzleHttp\Exception\TransferException;
@@ -13,7 +12,6 @@ class DaemonServerRepository extends DaemonRepository
1312
/**
1413
* Returns details about a server from the Daemon instance.
1514
*
16-
* @return array
1715
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
1816
*/
1917
public function getDetails(): array
@@ -89,10 +87,20 @@ public function delete(): void
8987

9088
/**
9189
* Reinstall a server on the daemon.
90+
*
91+
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
9292
*/
9393
public function reinstall(): void
9494
{
95-
throw new BadMethodCallException('Method is not implemented.');
95+
Assert::isInstanceOf($this->server, Server::class);
96+
97+
try {
98+
$this->getHttpClient()->post(sprintf(
99+
'/api/servers/%s/reinstall', $this->server->uuid
100+
));
101+
} catch (TransferException $exception) {
102+
throw new DaemonConnectionException($exception);
103+
}
96104
}
97105

98106
/**

app/Services/Servers/ReinstallServerService.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
namespace Pterodactyl\Services\Servers;
44

55
use Pterodactyl\Models\Server;
6-
use GuzzleHttp\Exception\RequestException;
76
use Illuminate\Database\ConnectionInterface;
87
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
98
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
10-
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
119

1210
class ReinstallServerService
1311
{
@@ -44,28 +42,23 @@ public function __construct(
4442
}
4543

4644
/**
47-
* @param int|\Pterodactyl\Models\Server $server
45+
* Reinstall a server on the remote daemon.
4846
*
49-
* @throws \Pterodactyl\Exceptions\DisplayException
50-
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
51-
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
47+
* @param \Pterodactyl\Models\Server $server
48+
* @return \Pterodactyl\Models\Server
49+
*
50+
* @throws \Throwable
5251
*/
53-
public function reinstall($server)
52+
public function reinstall(Server $server)
5453
{
55-
if (! $server instanceof Server) {
56-
$server = $this->repository->find($server);
57-
}
58-
59-
$this->database->beginTransaction();
60-
$this->repository->withoutFreshModel()->update($server->id, [
61-
'installed' => 0,
62-
], true, true);
54+
$this->database->transaction(function () use ($server) {
55+
$this->repository->withoutFreshModel()->update($server->id, [
56+
'installed' => Server::STATUS_INSTALLING,
57+
]);
6358

64-
try {
6559
$this->daemonServerRepository->setServer($server)->reinstall();
66-
$this->database->commit();
67-
} catch (RequestException $exception) {
68-
throw new DaemonConnectionException($exception);
69-
}
60+
});
61+
62+
return $server->refresh();
7063
}
7164
}

0 commit comments

Comments
 (0)