diff --git a/app/Extensions/DynamicDatabaseConnection.php b/app/Extensions/DynamicDatabaseConnection.php index 147f78064e..5830bf6782 100644 --- a/app/Extensions/DynamicDatabaseConnection.php +++ b/app/Extensions/DynamicDatabaseConnection.php @@ -15,7 +15,7 @@ class DynamicDatabaseConnection /** * Adds a dynamic database connection entry to the runtime config. */ - public function set(string $connection, DatabaseHost|int $host, string $database = 'mysql'): void + public static function set(string $connection, DatabaseHost|int $host, string $database = 'mysql'): void { if (!$host instanceof DatabaseHost) { $host = DatabaseHost::query()->findOrFail($host); diff --git a/app/Services/Databases/DatabaseManagementService.php b/app/Services/Databases/DatabaseManagementService.php index 8ec783328e..73f128e2e8 100644 --- a/app/Services/Databases/DatabaseManagementService.php +++ b/app/Services/Databases/DatabaseManagementService.php @@ -31,7 +31,6 @@ class DatabaseManagementService public function __construct( protected ConnectionInterface $connection, - protected DynamicDatabaseConnection $dynamic, ) {} /** @@ -91,7 +90,7 @@ public function create(Server $server, array $data): Database return $this->connection->transaction(function () use ($data) { $database = $this->createModel($data); - $this->dynamic->set('dynamic', $data['database_host_id']); + DynamicDatabaseConnection::set('dynamic', $data['database_host_id']); $database->createDatabase($database->database); $database->createUser( @@ -114,7 +113,7 @@ public function create(Server $server, array $data): Database */ public function delete(Database $database): ?bool { - $this->dynamic->set('dynamic', $database->database_host_id); + DynamicDatabaseConnection::set('dynamic', $database->database_host_id); $database->dropDatabase($database->database); $database->dropUser($database->username, $database->remote); diff --git a/app/Services/Databases/DatabasePasswordService.php b/app/Services/Databases/DatabasePasswordService.php index 110c5abe5c..78f93bbd08 100644 --- a/app/Services/Databases/DatabasePasswordService.php +++ b/app/Services/Databases/DatabasePasswordService.php @@ -14,7 +14,6 @@ class DatabasePasswordService */ public function __construct( private ConnectionInterface $connection, - private DynamicDatabaseConnection $dynamic, ) {} /** @@ -29,7 +28,7 @@ public function handle(Database|int $database): void $password = Utilities::randomStringWithSpecialCharacters(24); $this->connection->transaction(function () use ($database, $password) { - $this->dynamic->set('dynamic', $database->database_host_id); + DynamicDatabaseConnection::set('dynamic', $database->database_host_id); $database->update([ 'password' => $password, diff --git a/app/Services/Databases/Hosts/HostCreationService.php b/app/Services/Databases/Hosts/HostCreationService.php index ff38cb5c97..33a003f74d 100644 --- a/app/Services/Databases/Hosts/HostCreationService.php +++ b/app/Services/Databases/Hosts/HostCreationService.php @@ -15,7 +15,6 @@ class HostCreationService public function __construct( private ConnectionInterface $connection, private DatabaseManager $databaseManager, - private DynamicDatabaseConnection $dynamic, ) {} /** @@ -38,7 +37,7 @@ public function handle(array $data): DatabaseHost $host->nodes()->sync(array_get($data, 'node_ids', [])); // Confirm access using the provided credentials before saving data. - $this->dynamic->set('dynamic', $host); + DynamicDatabaseConnection::set('dynamic', $host); $this->databaseManager->connection('dynamic')->getPdo(); return $host; diff --git a/app/Services/Databases/Hosts/HostUpdateService.php b/app/Services/Databases/Hosts/HostUpdateService.php index 18d9f28383..eea067f347 100644 --- a/app/Services/Databases/Hosts/HostUpdateService.php +++ b/app/Services/Databases/Hosts/HostUpdateService.php @@ -15,7 +15,6 @@ class HostUpdateService public function __construct( private ConnectionInterface $connection, private DatabaseManager $databaseManager, - private DynamicDatabaseConnection $dynamic, ) {} /** @@ -36,7 +35,7 @@ public function handle(DatabaseHost|int $host, array $data): DatabaseHost return $this->connection->transaction(function () use ($data, $host) { $host->update($data); - $this->dynamic->set('dynamic', $host); + DynamicDatabaseConnection::set('dynamic', $host); $this->databaseManager->connection('dynamic')->getPdo(); return $host;