mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 06:24:44 +02:00

* Not found property rule * Make these “better” * Day 1 * Day 2 * Day 3 * Dat 4 * Remove disabled check * Day 4 continued * Run pint * Final changes hopefully * Pint fixes * Fix again * Reset these * Update app/Filament/Admin/Pages/Health.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Update app/Traits/CheckMigrationsTrait.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> --------- Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Databases\Hosts;
|
|
|
|
use App\Models\DatabaseHost;
|
|
use Illuminate\Database\DatabaseManager;
|
|
use Illuminate\Database\ConnectionInterface;
|
|
use App\Extensions\DynamicDatabaseConnection;
|
|
|
|
class HostUpdateService
|
|
{
|
|
/**
|
|
* HostUpdateService constructor.
|
|
*/
|
|
public function __construct(
|
|
private ConnectionInterface $connection,
|
|
private DatabaseManager $databaseManager,
|
|
private DynamicDatabaseConnection $dynamic,
|
|
) {}
|
|
|
|
/**
|
|
* Update a database host and persist to the database.
|
|
*
|
|
* @param array<mixed> $data
|
|
*
|
|
* @throws \Throwable
|
|
*/
|
|
public function handle(DatabaseHost|int $host, array $data): DatabaseHost
|
|
{
|
|
if (!$host instanceof DatabaseHost) {
|
|
$host = DatabaseHost::query()->findOrFail($host);
|
|
}
|
|
|
|
if (empty(array_get($data, 'password'))) {
|
|
unset($data['password']);
|
|
}
|
|
|
|
return $this->connection->transaction(function () use ($data, $host) {
|
|
$host->update($data);
|
|
|
|
$this->dynamic->set('dynamic', $host);
|
|
$this->databaseManager->connection('dynamic')->getPdo();
|
|
|
|
return $host;
|
|
});
|
|
}
|
|
}
|