mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-19 14:53:45 +02:00
feat(database-hosts): allow linking of multiple nodes
This commit is contained in:
@@ -10,10 +10,7 @@ use Pterodactyl\Exceptions\Service\Database\NoSuitableDatabaseHostException;
|
||||
|
||||
class DeployServerDatabaseService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Databases\DatabaseManagementService
|
||||
*/
|
||||
private $managementService;
|
||||
private DatabaseManagementService $managementService;
|
||||
|
||||
/**
|
||||
* ServerDatabaseCreationService constructor.
|
||||
@@ -35,21 +32,22 @@ class DeployServerDatabaseService
|
||||
Assert::notEmpty($data['database'] ?? null);
|
||||
Assert::notEmpty($data['remote'] ?? null);
|
||||
|
||||
$hosts = DatabaseHost::query()->get()->toBase();
|
||||
if ($hosts->isEmpty()) {
|
||||
throw new NoSuitableDatabaseHostException();
|
||||
} else {
|
||||
$nodeHosts = $hosts->where('node_id', $server->node_id)->toBase();
|
||||
|
||||
if ($nodeHosts->isEmpty() && !config('pterodactyl.client_features.databases.allow_random')) {
|
||||
$databaseHostId = $server->node->database_host_id;
|
||||
if (is_null($databaseHostId)) {
|
||||
if (!config('pterodactyl.client_features.databases.allow_random')) {
|
||||
throw new NoSuitableDatabaseHostException();
|
||||
}
|
||||
|
||||
$hosts = DatabaseHost::query()->get()->toBase();
|
||||
if ($hosts->isEmpty()) {
|
||||
throw new NoSuitableDatabaseHostException();
|
||||
}
|
||||
|
||||
$databaseHostId = $hosts->random()->id;
|
||||
}
|
||||
|
||||
return $this->managementService->create($server, [
|
||||
'database_host_id' => $nodeHosts->isEmpty()
|
||||
? $hosts->random()->id
|
||||
: $nodeHosts->random()->id,
|
||||
'database_host_id' => $databaseHostId,
|
||||
'database' => DatabaseManagementService::generateUniqueDatabaseName($data['database'], $server->id),
|
||||
'remote' => $data['remote'],
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user