2017-07-23 19:51:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Servers;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Illuminate\Database\ConnectionInterface;
|
2020-06-25 05:18:48 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
2019-11-25 04:19:31 +00:00
|
|
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
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
|
|
|
|
*/
|
2020-06-25 05:18:48 +00:00
|
|
|
private $connection;
|
2017-07-23 19:51:18 +00:00
|
|
|
|
|
|
|
/**
|
2020-06-25 05:18:48 +00:00
|
|
|
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
|
2017-07-23 19:51:18 +00:00
|
|
|
*/
|
2019-11-25 04:19:31 +00:00
|
|
|
private $repository;
|
2017-07-23 19:51:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ReinstallService constructor.
|
|
|
|
*
|
2020-06-25 05:18:48 +00:00
|
|
|
* @param \Illuminate\Database\ConnectionInterface $connection
|
2019-11-25 04:19:31 +00:00
|
|
|
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
|
2020-06-25 05:18:48 +00:00
|
|
|
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
|
2017-07-23 19:51:18 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2020-06-25 05:18:48 +00:00
|
|
|
ConnectionInterface $connection,
|
2019-11-25 04:19:31 +00:00
|
|
|
DaemonServerRepository $daemonServerRepository,
|
2020-06-25 05:18:48 +00:00
|
|
|
ServerRepository $repository
|
2017-07-23 19:51:18 +00:00
|
|
|
) {
|
|
|
|
$this->daemonServerRepository = $daemonServerRepository;
|
2020-06-25 05:18:48 +00:00
|
|
|
$this->connection = $connection;
|
2017-07-23 19:51:18 +00:00
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-04-03 20:46:45 +00:00
|
|
|
* Reinstall a server on the remote daemon.
|
2017-07-23 19:51:18 +00:00
|
|
|
*
|
2020-04-03 20:46:45 +00:00
|
|
|
* @param \Pterodactyl\Models\Server $server
|
|
|
|
* @return \Pterodactyl\Models\Server
|
|
|
|
*
|
|
|
|
* @throws \Throwable
|
2017-07-23 19:51:18 +00:00
|
|
|
*/
|
2020-04-03 20:46:45 +00:00
|
|
|
public function reinstall(Server $server)
|
2017-07-23 19:51:18 +00:00
|
|
|
{
|
2020-06-25 05:18:48 +00:00
|
|
|
return $this->connection->transaction(function () use ($server) {
|
|
|
|
$updated = $this->repository->update($server->id, [
|
2020-04-03 20:46:45 +00:00
|
|
|
'installed' => Server::STATUS_INSTALLING,
|
|
|
|
]);
|
2017-07-23 19:51:18 +00:00
|
|
|
|
2018-01-06 00:27:47 +00:00
|
|
|
$this->daemonServerRepository->setServer($server)->reinstall();
|
2020-04-03 20:46:45 +00:00
|
|
|
|
2020-06-25 05:18:48 +00:00
|
|
|
return $updated;
|
|
|
|
});
|
2017-07-23 19:51:18 +00:00
|
|
|
}
|
|
|
|
}
|