2017-07-23 19:51:18 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-07-23 19:51:18 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-07-23 19:51:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Servers;
|
|
|
|
|
2017-07-24 00:57:43 +00:00
|
|
|
use Illuminate\Log\Writer;
|
2017-07-23 19:51:18 +00:00
|
|
|
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;
|
2017-08-05 22:26:30 +00:00
|
|
|
use Pterodactyl\Exceptions\DisplayException;
|
2017-07-23 19:51:18 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
|
|
|
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
|
|
|
|
|
2017-08-27 20:10:51 +00:00
|
|
|
class ReinstallServerService
|
2017-07-23 19:51:18 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $daemonServerRepository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Database\ConnectionInterface
|
|
|
|
*/
|
|
|
|
protected $database;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
2017-07-24 00:57:43 +00:00
|
|
|
/**
|
|
|
|
* @var \Illuminate\Log\Writer
|
|
|
|
*/
|
|
|
|
protected $writer;
|
|
|
|
|
2017-07-23 19:51:18 +00:00
|
|
|
/**
|
|
|
|
* ReinstallService constructor.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Database\ConnectionInterface $database
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonServerRepository
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
2017-07-24 00:57:43 +00:00
|
|
|
* @param \Illuminate\Log\Writer $writer
|
2017-07-23 19:51:18 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
ConnectionInterface $database,
|
|
|
|
DaemonServerRepositoryInterface $daemonServerRepository,
|
2017-07-24 00:57:43 +00:00
|
|
|
ServerRepositoryInterface $repository,
|
|
|
|
Writer $writer
|
2017-07-23 19:51:18 +00:00
|
|
|
) {
|
|
|
|
$this->daemonServerRepository = $daemonServerRepository;
|
|
|
|
$this->database = $database;
|
|
|
|
$this->repository = $repository;
|
2017-07-24 00:57:43 +00:00
|
|
|
$this->writer = $writer;
|
2017-07-23 19:51:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
*/
|
|
|
|
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,
|
|
|
|
]);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->daemonServerRepository->setNode($server->node_id)->setAccessServer($server->uuid)->reinstall();
|
|
|
|
$this->database->commit();
|
|
|
|
} catch (RequestException $exception) {
|
2017-07-24 00:57:43 +00:00
|
|
|
$response = $exception->getResponse();
|
|
|
|
$this->writer->warning($exception);
|
|
|
|
|
2017-07-23 19:51:18 +00:00
|
|
|
throw new DisplayException(trans('admin/server.exceptions.daemon_exception', [
|
2017-07-24 00:57:43 +00:00
|
|
|
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
2017-07-23 19:51:18 +00:00
|
|
|
]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|