2017-07-23 19:51:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Servers;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Server;
|
2017-08-05 22:26:30 +00:00
|
|
|
use GuzzleHttp\Exception\RequestException;
|
2017-07-23 19:51:18 +00:00
|
|
|
use Illuminate\Database\ConnectionInterface;
|
2019-11-25 04:19:31 +00:00
|
|
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
2017-07-23 19:51:18 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
2018-01-06 00:27:47 +00:00
|
|
|
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
2017-07-23 19:51:18 +00:00
|
|
|
|
2017-08-27 20:10:51 +00:00
|
|
|
class ReinstallServerService
|
2017-07-23 19:51:18 +00:00
|
|
|
{
|
|
|
|
/**
|
2019-11-25 04:19:31 +00:00
|
|
|
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
2017-07-23 19:51:18 +00:00
|
|
|
*/
|
2019-11-25 04:19:31 +00:00
|
|
|
private $daemonServerRepository;
|
2017-07-23 19:51:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Database\ConnectionInterface
|
|
|
|
*/
|
2019-11-25 04:19:31 +00:00
|
|
|
private $database;
|
2017-07-23 19:51:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
|
|
|
*/
|
2019-11-25 04:19:31 +00:00
|
|
|
private $repository;
|
2017-07-23 19:51:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ReinstallService constructor.
|
|
|
|
*
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Illuminate\Database\ConnectionInterface $database
|
2019-11-25 04:19:31 +00:00
|
|
|
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
2017-07-23 19:51:18 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
ConnectionInterface $database,
|
2019-11-25 04:19:31 +00:00
|
|
|
DaemonServerRepository $daemonServerRepository,
|
2018-01-06 00:27:47 +00:00
|
|
|
ServerRepositoryInterface $repository
|
2017-07-23 19:51:18 +00:00
|
|
|
) {
|
|
|
|
$this->daemonServerRepository = $daemonServerRepository;
|
|
|
|
$this->database = $database;
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param int|\Pterodactyl\Models\Server $server
|
2017-07-23 19:51:18 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2018-01-06 00:27:47 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-07-23 19:51:18 +00:00
|
|
|
*/
|
|
|
|
public function reinstall($server)
|
|
|
|
{
|
|
|
|
if (! $server instanceof Server) {
|
|
|
|
$server = $this->repository->find($server);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->database->beginTransaction();
|
2018-01-05 22:33:50 +00:00
|
|
|
$this->repository->withoutFreshModel()->update($server->id, [
|
2017-07-23 19:51:18 +00:00
|
|
|
'installed' => 0,
|
2018-02-28 01:43:47 +00:00
|
|
|
], true, true);
|
2017-07-23 19:51:18 +00:00
|
|
|
|
|
|
|
try {
|
2018-01-06 00:27:47 +00:00
|
|
|
$this->daemonServerRepository->setServer($server)->reinstall();
|
2017-07-23 19:51:18 +00:00
|
|
|
$this->database->commit();
|
|
|
|
} catch (RequestException $exception) {
|
2018-01-06 00:27:47 +00:00
|
|
|
throw new DaemonConnectionException($exception);
|
2017-07-23 19:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|