2017-10-19 03:32:19 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Database\ConnectionInterface
|
|
|
|
*/
|
|
|
|
private $connection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Database\DatabaseManager
|
|
|
|
*/
|
|
|
|
private $databaseManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Extensions\DynamicDatabaseConnection
|
|
|
|
*/
|
|
|
|
private $dynamic;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Encryption\Encrypter
|
|
|
|
*/
|
|
|
|
private $encrypter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface
|
|
|
|
*/
|
|
|
|
private $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DatabaseHostService constructor.
|
|
|
|
*
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Illuminate\Database\ConnectionInterface $connection
|
|
|
|
* @param \Illuminate\Database\DatabaseManager $databaseManager
|
2017-10-19 03:32:19 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface $repository
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Pterodactyl\Extensions\DynamicDatabaseConnection $dynamic
|
|
|
|
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
|
2017-10-19 03:32:19 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
ConnectionInterface $connection,
|
|
|
|
DatabaseManager $databaseManager,
|
|
|
|
DatabaseHostRepositoryInterface $repository,
|
|
|
|
DynamicDatabaseConnection $dynamic,
|
|
|
|
Encrypter $encrypter
|
|
|
|
) {
|
|
|
|
$this->connection = $connection;
|
|
|
|
$this->databaseManager = $databaseManager;
|
|
|
|
$this->dynamic = $dynamic;
|
|
|
|
$this->encrypter = $encrypter;
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a database host and persist to the database.
|
|
|
|
*
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param int $hostId
|
2017-10-19 03:32:19 +00:00
|
|
|
* @param array $data
|
2019-08-03 19:33:28 +00:00
|
|
|
* @return \Pterodactyl\Models\DatabaseHost
|
2017-10-19 03:32:19 +00:00
|
|
|
*
|
2019-08-03 19:33:28 +00:00
|
|
|
* @throws \Throwable
|
2017-10-19 03:32:19 +00:00
|
|
|
*/
|
|
|
|
public function handle(int $hostId, array $data): DatabaseHost
|
|
|
|
{
|
|
|
|
if (! empty(array_get($data, 'password'))) {
|
|
|
|
$data['password'] = $this->encrypter->encrypt($data['password']);
|
|
|
|
} else {
|
|
|
|
unset($data['password']);
|
|
|
|
}
|
|
|
|
|
2019-08-03 19:33:28 +00:00
|
|
|
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');
|
2017-10-19 03:32:19 +00:00
|
|
|
|
2019-08-03 19:33:28 +00:00
|
|
|
return $host;
|
|
|
|
});
|
2017-10-19 03:32:19 +00:00
|
|
|
}
|
|
|
|
}
|