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

65 lines
1.8 KiB
PHP
Raw Normal View History

<?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;
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
class ReinstallServerService
{
/**
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
*/
private $daemonServerRepository;
/**
* @var \Illuminate\Database\ConnectionInterface
*/
2020-06-25 05:18:48 +00:00
private $connection;
/**
2020-06-25 05:18:48 +00:00
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
*/
private $repository;
/**
* ReinstallService constructor.
*
2020-06-25 05:18:48 +00:00
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
2020-06-25 05:18:48 +00:00
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
*/
public function __construct(
2020-06-25 05:18:48 +00:00
ConnectionInterface $connection,
DaemonServerRepository $daemonServerRepository,
2020-06-25 05:18:48 +00:00
ServerRepository $repository
) {
$this->daemonServerRepository = $daemonServerRepository;
2020-06-25 05:18:48 +00:00
$this->connection = $connection;
$this->repository = $repository;
}
/**
* Reinstall a server on the remote daemon.
*
* @param \Pterodactyl\Models\Server $server
* @return \Pterodactyl\Models\Server
*
* @throws \Throwable
*/
public function reinstall(Server $server)
{
2020-06-25 05:18:48 +00:00
return $this->connection->transaction(function () use ($server) {
$updated = $this->repository->update($server->id, [
'installed' => Server::STATUS_INSTALLING,
], true, true);
$this->daemonServerRepository->setServer($server)->reinstall();
2020-06-25 05:18:48 +00:00
return $updated;
});
}
}