Boy132 d555c42644
Update all dependencies (#712)
* update composer.lock

* run pint

* fix phpstan

* update migrations (sqlite `dropForeign`)

* fix migrations

* Reset these back for now

* Alphabetize the rules

* run `php artisan filament:upgrade`

---------

Co-authored-by: Lance Pioch <git@lance.sh>
2024-11-22 09:27:57 +01:00

46 lines
1.1 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.
*
* @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;
});
}
}