Don't waste time on a service better suited to an integration test
This commit is contained in:
parent
2560163655
commit
c59a2c436b
3 changed files with 63 additions and 340 deletions
|
@ -4,7 +4,9 @@ namespace Pterodactyl\Services\Servers;
|
|||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Illuminate\Support\Arr;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\User;
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Support\Collection;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
|
@ -13,7 +15,6 @@ use Pterodactyl\Models\Objects\DeploymentObject;
|
|||
use Pterodactyl\Repositories\Eloquent\EggRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\AllocationRepository;
|
||||
use Pterodactyl\Services\Deployment\FindViableNodesService;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerVariableRepository;
|
||||
use Pterodactyl\Services\Deployment\AllocationSelectionService;
|
||||
|
@ -21,11 +22,6 @@ use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
|||
|
||||
class ServerCreationService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\AllocationRepository
|
||||
*/
|
||||
private $allocationRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Deployment\AllocationSelectionService
|
||||
*/
|
||||
|
@ -79,7 +75,6 @@ class ServerCreationService
|
|||
/**
|
||||
* CreationService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Repositories\Eloquent\AllocationRepository $allocationRepository
|
||||
* @param \Pterodactyl\Services\Deployment\AllocationSelectionService $allocationSelectionService
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
|
||||
|
@ -92,7 +87,6 @@ class ServerCreationService
|
|||
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
|
||||
*/
|
||||
public function __construct(
|
||||
AllocationRepository $allocationRepository,
|
||||
AllocationSelectionService $allocationSelectionService,
|
||||
ConnectionInterface $connection,
|
||||
DaemonServerRepository $daemonServerRepository,
|
||||
|
@ -105,7 +99,6 @@ class ServerCreationService
|
|||
VariableValidatorService $validatorService
|
||||
) {
|
||||
$this->allocationSelectionService = $allocationSelectionService;
|
||||
$this->allocationRepository = $allocationRepository;
|
||||
$this->configurationStructureService = $configurationStructureService;
|
||||
$this->connection = $connection;
|
||||
$this->findViableNodesService = $findViableNodesService;
|
||||
|
@ -149,14 +142,16 @@ class ServerCreationService
|
|||
|
||||
// Auto-configure the node based on the selected allocation
|
||||
// if no node was defined.
|
||||
if (is_null(Arr::get($data, 'node_id'))) {
|
||||
$data['node_id'] = $this->getNodeFromAllocation($data['allocation_id']);
|
||||
if (empty($data['node_id'])) {
|
||||
Assert::false(empty($data['allocation_id']), 'Expected a non-empty allocation_id in server creation data.');
|
||||
|
||||
$data['node_id'] = Allocation::query()->findOrFail($data['allocation_id'])->node_id;
|
||||
}
|
||||
|
||||
if (is_null(Arr::get($data, 'nest_id'))) {
|
||||
/** @var \Pterodactyl\Models\Egg $egg */
|
||||
$egg = $this->eggRepository->setColumns(['id', 'nest_id'])->find(Arr::get($data, 'egg_id'));
|
||||
$data['nest_id'] = $egg->nest_id;
|
||||
if (empty($data['nest_id'])) {
|
||||
Assert::false(empty($data['egg_id']), 'Expected a non-empty egg_id in server creation data.');
|
||||
|
||||
$data['nest_id'] = Egg::query()->findOrFail($data['egg_id'])->nest_id;
|
||||
}
|
||||
|
||||
$eggVariableData = $this->validatorService
|
||||
|
@ -269,7 +264,7 @@ class ServerCreationService
|
|||
$records = array_merge($records, $data['allocation_additional']);
|
||||
}
|
||||
|
||||
$this->allocationRepository->updateWhereIn('id', $records, [
|
||||
Allocation::query()->whereIn('id', $records)->update([
|
||||
'server_id' => $server->id,
|
||||
]);
|
||||
}
|
||||
|
@ -295,22 +290,6 @@ class ServerCreationService
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the node that an allocation belongs to.
|
||||
*
|
||||
* @param int $id
|
||||
* @return int
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
private function getNodeFromAllocation(int $id): int
|
||||
{
|
||||
/** @var \Pterodactyl\Models\Allocation $allocation */
|
||||
$allocation = $this->allocationRepository->setColumns(['id', 'node_id'])->find($id);
|
||||
|
||||
return $allocation->node_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a unique UUID and UUID-Short combo for a server.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue