misc_pterodactyl-panel/app/Services/Databases/Hosts/HostUpdateService.php

48 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace Pterodactyl\Services\Databases\Hosts;
use Pterodactyl\Models\DatabaseHost;
use Illuminate\Database\DatabaseManager;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Contracts\Encryption\Encrypter;
use Pterodactyl\Extensions\DynamicDatabaseConnection;
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
class HostUpdateService
{
/**
* HostUpdateService constructor.
*/
public function __construct(
private ConnectionInterface $connection,
private DatabaseManager $databaseManager,
private DynamicDatabaseConnection $dynamic,
private Encrypter $encrypter,
private DatabaseHostRepositoryInterface $repository
) {
}
/**
* Update a database host and persist to the database.
*
* @throws \Throwable
*/
public function handle(int $hostId, array $data): DatabaseHost
{
2021-01-23 20:33:34 +00:00
if (!empty(array_get($data, 'password'))) {
$data['password'] = $this->encrypter->encrypt($data['password']);
} else {
unset($data['password']);
}
return $this->connection->transaction(function () use ($data, $hostId) {
$host = $this->repository->update($hostId, $data);
$this->dynamic->set('dynamic', $host);
$this->databaseManager->connection('dynamic')->select('SELECT 1 FROM dual');
return $host;
});
}
}