Remove ServerRepository and ServerRepositoryInterface

This commit is contained in:
Lance Pioch 2022-10-20 21:17:03 -04:00
parent 22d560de64
commit 4d7ea155b1
19 changed files with 63 additions and 146 deletions

View file

@ -7,7 +7,6 @@ use Illuminate\Http\JsonResponse;
use Pterodactyl\Facades\Activity;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Transformers\Api\Client\AllocationTransformer;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
use Pterodactyl\Services\Allocations\FindAssignableAllocationService;
@ -22,10 +21,8 @@ class NetworkAllocationController extends ClientApiController
/**
* NetworkAllocationController constructor.
*/
public function __construct(
private FindAssignableAllocationService $assignableAllocationService,
private ServerRepository $serverRepository
) {
public function __construct(private FindAssignableAllocationService $assignableAllocationService)
{
parent::__construct();
}
@ -72,7 +69,8 @@ class NetworkAllocationController extends ClientApiController
*/
public function setPrimary(SetPrimaryAllocationRequest $request, Server $server, Allocation $allocation): array
{
$this->serverRepository->update($server->id, ['allocation_id' => $allocation->id]);
$server->allocation()->associate($allocation);
$server->save();
Activity::event('server:allocation.primary')
->subject($allocation)

View file

@ -6,7 +6,6 @@ use Illuminate\Http\Response;
use Pterodactyl\Models\Server;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Facades\Activity;
use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Services\Servers\ReinstallServerService;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
@ -19,10 +18,8 @@ class SettingsController extends ClientApiController
/**
* SettingsController constructor.
*/
public function __construct(
private ServerRepository $repository,
private ReinstallServerService $reinstallServerService
) {
public function __construct(private ReinstallServerService $reinstallServerService)
{
parent::__construct();
}
@ -34,15 +31,12 @@ class SettingsController extends ClientApiController
*/
public function rename(RenameServerRequest $request, Server $server): JsonResponse
{
$this->repository->update($server->id, [
'name' => $request->input('name'),
]);
$server->name = $request->input('name');
$server->save();
if ($server->name !== $request->input('name')) {
Activity::event('server:settings.rename')
->property(['old' => $server->name, 'new' => $request->input('name')])
->log();
}
Activity::event('server:settings.rename')
->property(['old' => $server->name, 'new' => $request->input('name')])
->log();
return new JsonResponse([], Response::HTTP_NO_CONTENT);
}

View file

@ -9,7 +9,6 @@ use Pterodactyl\Facades\Activity;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\Eggs\EggConfigurationService;
use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Http\Resources\Wings\ServerConfigurationCollection;
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
@ -20,7 +19,6 @@ class ServerDetailsController extends Controller
*/
public function __construct(
protected ConnectionInterface $connection,
private ServerRepository $repository,
private ServerConfigurationStructureService $configurationStructureService,
private EggConfigurationService $eggConfigurationService
) {
@ -30,11 +28,10 @@ class ServerDetailsController extends Controller
* Returns details about the server that allows Wings to self-recover and ensure
* that the state of the server matches the Panel at all times.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function __invoke(Request $request, string $uuid): JsonResponse
{
$server = $this->repository->getByUuid($uuid);
$server = Server::findOrFailByUuid($uuid);
return new JsonResponse([
'settings' => $this->configurationStructureService->handle($server),

View file

@ -2,13 +2,13 @@
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
use Carbon\CarbonImmutable;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Pterodactyl\Models\Server;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Container\ContainerExceptionInterface;
use Pterodactyl\Events\Server\Installed as ServerInstalled;
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
use Pterodactyl\Http\Requests\Api\Remote\InstallationDataRequest;
@ -18,18 +18,16 @@ class ServerInstallController extends Controller
/**
* ServerInstallController constructor.
*/
public function __construct(private ServerRepository $repository, private EventDispatcher $eventDispatcher)
public function __construct(private EventDispatcher $eventDispatcher)
{
}
/**
* Returns installation information for a server.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function index(Request $request, string $uuid): JsonResponse
{
$server = $this->repository->getByUuid($uuid);
$server = Server::findOrFailByUuid($uuid);
$egg = $server->egg;
return new JsonResponse([
@ -42,23 +40,27 @@ class ServerInstallController extends Controller
/**
* Updates the installation state of a server.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function store(InstallationDataRequest $request, string $uuid): JsonResponse
{
$server = $this->repository->getByUuid($uuid);
$server = Server::findOrFailByUuid($uuid);
$status = $request->boolean('successful') ? null : Server::STATUS_INSTALL_FAILED;
if ($server->status === Server::STATUS_SUSPENDED) {
$status = Server::STATUS_SUSPENDED;
}
$this->repository->update($server->id, ['status' => $status, 'installed_at' => CarbonImmutable::now()], true, true);
$previouslyInstalledAt = $server->installed_at;
$server->status = $status;
$server->installed_at = now();
$server->save();
// If the server successfully installed, fire installed event.
// This logic allows individually disabling install and reinstall notifications separately.
$isInitialInstall = is_null($server->installed_at);
$isInitialInstall = is_null($previouslyInstalledAt);
if ($isInitialInstall && config()->get('pterodactyl.email.send_install_notification', true)) {
$this->eventDispatcher->dispatch(new ServerInstalled($server));
} elseif (!$isInitialInstall && config()->get('pterodactyl.email.send_reinstall_notification', true)) {

View file

@ -8,11 +8,11 @@ use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\Allocation;
use Illuminate\Support\Facades\Log;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\ServerTransfer;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\Nodes\NodeJWTService;
use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
use Pterodactyl\Repositories\Wings\DaemonTransferRepository;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
@ -24,7 +24,6 @@ class ServerTransferController extends Controller
*/
public function __construct(
private ConnectionInterface $connection,
private ServerRepository $repository,
private DaemonServerRepository $daemonServerRepository,
private DaemonTransferRepository $daemonTransferRepository,
private NodeJWTService $jwtService
@ -39,7 +38,7 @@ class ServerTransferController extends Controller
*/
public function archive(Request $request, string $uuid): JsonResponse
{
$server = $this->repository->getByUuid($uuid);
$server = Server::findOrFailByUuid($uuid);
// Unsuspend the server and don't continue the transfer.
if (!$request->input('successful')) {
@ -78,7 +77,7 @@ class ServerTransferController extends Controller
*/
public function failure(string $uuid): JsonResponse
{
$server = $this->repository->getByUuid($uuid);
$server = Server::findOrFailByUuid($uuid);
return $this->processFailedTransfer($server->transfer);
}
@ -90,7 +89,7 @@ class ServerTransferController extends Controller
*/
public function success(string $uuid): JsonResponse
{
$server = $this->repository->getByUuid($uuid);
$server = Server::findOrFailByUuid($uuid);
$transfer = $server->transfer;
/** @var \Pterodactyl\Models\Server $server */