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

55 lines
1.5 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;
/**
* ReinstallService constructor.
*
2020-06-25 05:18:48 +00:00
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
*/
public function __construct(
2020-06-25 05:18:48 +00:00
ConnectionInterface $connection,
2020-10-06 04:54:29 +00:00
DaemonServerRepository $daemonServerRepository
) {
$this->daemonServerRepository = $daemonServerRepository;
2020-06-25 05:18:48 +00:00
$this->connection = $connection;
}
/**
* Reinstall a server on the remote daemon.
*
* @param \Pterodactyl\Models\Server $server
* @return \Pterodactyl\Models\Server
*
* @throws \Throwable
*/
2020-10-06 04:54:29 +00:00
public function handle(Server $server)
{
2020-06-25 05:18:48 +00:00
return $this->connection->transaction(function () use ($server) {
2020-10-06 04:54:29 +00:00
$server->forceFill(['installed' => Server::STATUS_INSTALLING])->save();
$this->daemonServerRepository->setServer($server)->reinstall();
2020-10-06 04:54:29 +00:00
return $server->refresh();
2020-06-25 05:18:48 +00:00
});
}
}