app: fix DeployServerDatabaseService
This commit is contained in:
parent
926c8563d0
commit
d1c7494933
2 changed files with 17 additions and 15 deletions
|
@ -27,21 +27,22 @@ class DeployServerDatabaseService
|
||||||
Assert::notEmpty($data['database'] ?? null);
|
Assert::notEmpty($data['database'] ?? null);
|
||||||
Assert::notEmpty($data['remote'] ?? null);
|
Assert::notEmpty($data['remote'] ?? null);
|
||||||
|
|
||||||
$hosts = DatabaseHost::query()->get()->toBase();
|
$databaseHostId = $server->node->database_host_id;
|
||||||
if ($hosts->isEmpty()) {
|
if (is_null($databaseHostId)) {
|
||||||
throw new NoSuitableDatabaseHostException();
|
if (!config('pterodactyl.client_features.databases.allow_random')) {
|
||||||
} else {
|
|
||||||
$nodeHosts = $hosts->where('node_id', $server->node_id)->toBase();
|
|
||||||
|
|
||||||
if ($nodeHosts->isEmpty() && !config('pterodactyl.client_features.databases.allow_random')) {
|
|
||||||
throw new NoSuitableDatabaseHostException();
|
throw new NoSuitableDatabaseHostException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$hosts = DatabaseHost::query()->get()->toBase();
|
||||||
|
if ($hosts->isEmpty()) {
|
||||||
|
throw new NoSuitableDatabaseHostException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$databaseHostId = $hosts->random()->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->managementService->create($server, [
|
return $this->managementService->create($server, [
|
||||||
'database_host_id' => $nodeHosts->isEmpty()
|
'database_host_id' => $databaseHostId,
|
||||||
? $hosts->random()->id
|
|
||||||
: $nodeHosts->random()->id,
|
|
||||||
'database' => DatabaseManagementService::generateUniqueDatabaseName($data['database'], $server->id),
|
'database' => DatabaseManagementService::generateUniqueDatabaseName($data['database'], $server->id),
|
||||||
'remote' => $data['remote'],
|
'remote' => $data['remote'],
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -62,7 +62,7 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
|
||||||
$server = $this->createServerModel();
|
$server = $this->createServerModel();
|
||||||
|
|
||||||
$host = DatabaseHost::factory()->create();
|
$host = DatabaseHost::factory()->create();
|
||||||
$node = Node::factory()->create(['location_id' => $server->location->id]);
|
$node = Node::factory()->create(['database_host_id' => $host->id, 'location_id' => $server->location->id]);
|
||||||
|
|
||||||
config()->set('pterodactyl.client_features.databases.allow_random', false);
|
config()->set('pterodactyl.client_features.databases.allow_random', false);
|
||||||
|
|
||||||
|
@ -96,12 +96,13 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
|
||||||
{
|
{
|
||||||
$server = $this->createServerModel();
|
$server = $this->createServerModel();
|
||||||
|
|
||||||
$node = Node::factory()->create(['location_id' => $server->location->id, 'database_host_id' => DatabaseHost::factory()->create()->id]);
|
$host1 = DatabaseHost::factory()->create();
|
||||||
$host = DatabaseHost::factory()->create();
|
$host2 = DatabaseHost::factory()->create();
|
||||||
$server->node->database_host_id = $host->id;
|
$node = Node::factory()->create(['database_host_id' => $host2->id, 'location_id' => $server->location->id]);
|
||||||
|
$server->node->database_host_id = $host2->id;
|
||||||
|
|
||||||
$this->managementService->expects('create')->with($server, [
|
$this->managementService->expects('create')->with($server, [
|
||||||
'database_host_id' => $host->id,
|
'database_host_id' => $host2->id,
|
||||||
'database' => "s{$server->id}_something",
|
'database' => "s{$server->id}_something",
|
||||||
'remote' => '%',
|
'remote' => '%',
|
||||||
])->andReturns(new Database());
|
])->andReturns(new Database());
|
||||||
|
|
Loading…
Reference in a new issue