Fix data integrity exception, closes #922
This commit is contained in:
parent
e1d6980c0b
commit
cfb7415e2a
4 changed files with 116 additions and 5 deletions
|
@ -112,7 +112,9 @@ class ServerCreationService
|
|||
|
||||
/**
|
||||
* Create a server on the Panel and trigger a request to the Daemon to begin the server
|
||||
* creation process.
|
||||
* creation process. This function will attempt to set as many additional values
|
||||
* as possible given the input data. For example, if an allocation_id is passed with
|
||||
* no node_id the node_is will be picked from the allocation.
|
||||
*
|
||||
* @param array $data
|
||||
* @param \Pterodactyl\Models\Objects\DeploymentObject|null $deployment
|
||||
|
@ -138,6 +140,12 @@ class ServerCreationService
|
|||
$data['node_id'] = $allocation->node_id;
|
||||
}
|
||||
|
||||
// Auto-configure the node based on the selected allocation
|
||||
// if no node was defined.
|
||||
if (is_null(array_get($data, 'node_id'))) {
|
||||
$data['node_id'] = $this->getNodeFromAllocation($data['allocation_id']);
|
||||
}
|
||||
|
||||
if (is_null(array_get($data, 'nest_id'))) {
|
||||
$egg = $this->eggRepository->setColumns(['id', 'nest_id'])->find(array_get($data, 'egg_id'));
|
||||
$data['nest_id'] = $egg->nest_id;
|
||||
|
@ -263,4 +271,19 @@ class ServerCreationService
|
|||
$this->serverVariableRepository->insert($records);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the node that an allocation belongs to.
|
||||
*
|
||||
* @param int $allocation
|
||||
* @return int
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
private function getNodeFromAllocation(int $allocation): int
|
||||
{
|
||||
$allocation = $this->allocationRepository->setColumns(['id', 'node_id'])->find($allocation);
|
||||
|
||||
return $allocation->node_id;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue