Add back support for reinstalling a server

This commit is contained in:
Dane Everitt 2020-04-03 13:46:45 -07:00
parent dfefd8845b
commit 7d45379f31
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
3 changed files with 28 additions and 23 deletions

View File

@ -61,6 +61,10 @@ class Server extends Validable
*/ */
const RESOURCE_NAME = 'server'; const RESOURCE_NAME = 'server';
const STATUS_INSTALLING = 0;
const STATUS_INSTALLED = 1;
const STATUS_INSTALL_FAILED = 2;
/** /**
* The table associated with the model. * The table associated with the model.
* *

View File

@ -2,7 +2,6 @@
namespace Pterodactyl\Repositories\Wings; namespace Pterodactyl\Repositories\Wings;
use BadMethodCallException;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use GuzzleHttp\Exception\TransferException; use GuzzleHttp\Exception\TransferException;
@ -13,7 +12,6 @@ class DaemonServerRepository extends DaemonRepository
/** /**
* Returns details about a server from the Daemon instance. * Returns details about a server from the Daemon instance.
* *
* @return array
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/ */
public function getDetails(): array public function getDetails(): array
@ -89,10 +87,20 @@ class DaemonServerRepository extends DaemonRepository
/** /**
* Reinstall a server on the daemon. * Reinstall a server on the daemon.
*
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/ */
public function reinstall(): void public function reinstall(): void
{ {
throw new BadMethodCallException('Method is not implemented.'); Assert::isInstanceOf($this->server, Server::class);
try {
$this->getHttpClient()->post(sprintf(
'/api/servers/%s/reinstall', $this->server->uuid
));
} catch (TransferException $exception) {
throw new DaemonConnectionException($exception);
}
} }
/** /**

View File

@ -3,11 +3,9 @@
namespace Pterodactyl\Services\Servers; namespace Pterodactyl\Services\Servers;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Repositories\Wings\DaemonServerRepository; use Pterodactyl\Repositories\Wings\DaemonServerRepository;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class ReinstallServerService class ReinstallServerService
{ {
@ -44,28 +42,23 @@ class ReinstallServerService
} }
/** /**
* @param int|\Pterodactyl\Models\Server $server * Reinstall a server on the remote daemon.
* *
* @throws \Pterodactyl\Exceptions\DisplayException * @param \Pterodactyl\Models\Server $server
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @return \Pterodactyl\Models\Server
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException *
* @throws \Throwable
*/ */
public function reinstall($server) public function reinstall(Server $server)
{ {
if (! $server instanceof Server) { $this->database->transaction(function () use ($server) {
$server = $this->repository->find($server); $this->repository->withoutFreshModel()->update($server->id, [
} 'installed' => Server::STATUS_INSTALLING,
]);
$this->database->beginTransaction();
$this->repository->withoutFreshModel()->update($server->id, [
'installed' => 0,
], true, true);
try {
$this->daemonServerRepository->setServer($server)->reinstall(); $this->daemonServerRepository->setServer($server)->reinstall();
$this->database->commit(); });
} catch (RequestException $exception) {
throw new DaemonConnectionException($exception); return $server->refresh();
}
} }
} }