Replace egg relations method

This commit is contained in:
Lance Pioch 2022-10-20 20:19:18 -04:00
parent 5331fd2cdb
commit f45b7b5996
3 changed files with 7 additions and 26 deletions

View file

@ -8,11 +8,6 @@ use Illuminate\Contracts\Pagination\LengthAwarePaginator;
interface ServerRepositoryInterface extends RepositoryInterface interface ServerRepositoryInterface extends RepositoryInterface
{ {
/**
* Load the egg relations onto the server model.
*/
public function loadEggRelations(Server $server, bool $refresh = false): Server;
/** /**
* Return a collection of servers with their associated data for rebuild operations. * Return a collection of servers with their associated data for rebuild operations.
*/ */

View file

@ -5,15 +5,15 @@ namespace Pterodactyl\Http\Controllers\Api\Remote;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Models\Server;
use Pterodactyl\Services\Servers\EnvironmentService; use Pterodactyl\Services\Servers\EnvironmentService;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class EggInstallController extends Controller class EggInstallController extends Controller
{ {
/** /**
* EggInstallController constructor. * EggInstallController constructor.
*/ */
public function __construct(private EnvironmentService $environment, private ServerRepositoryInterface $repository) public function __construct(private EnvironmentService $environment)
{ {
} }
@ -21,19 +21,17 @@ class EggInstallController extends Controller
* Handle request to get script and installation information for a server * Handle request to get script and installation information for a server
* that is being created on the node. * that is being created on the node.
* *
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function index(Request $request, string $uuid): JsonResponse public function index(Request $request, string $uuid): JsonResponse
{ {
$node = $request->attributes->get('node'); $node = $request->attributes->get('node');
/** @var \Pterodactyl\Models\Server $server */ /** @var Server $server */
$server = $this->repository->findFirstWhere([ $server = Server::with('egg.scriptFrom')
['uuid', '=', $uuid], ->where('uuid', $uuid)
['node_id', '=', $node->id], ->where('node_id', $node->id)
]); ->firstOrFail();
$this->repository->loadEggRelations($server);
$egg = $server->getRelation('egg'); $egg = $server->getRelation('egg');
return response()->json([ return response()->json([

View file

@ -20,18 +20,6 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
return Server::class; return Server::class;
} }
/**
* Load the egg relations onto the server model.
*/
public function loadEggRelations(Server $server, bool $refresh = false): Server
{
if (!$server->relationLoaded('egg') || $refresh) {
$server->load('egg.scriptFrom');
}
return $server;
}
/** /**
* Return a collection of servers with their associated data for rebuild operations. * Return a collection of servers with their associated data for rebuild operations.
*/ */