misc_pterodactyl-panel/app/Services/Servers/ReinstallServerService.php

72 lines
2.2 KiB
PHP
Raw Normal View History

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