Remove DatabaseHost Repository
This commit is contained in:
parent
449f875d20
commit
9d3a6ae494
@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Contracts\Repository;
|
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
|
|
||||||
interface DatabaseHostRepositoryInterface extends RepositoryInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Return database hosts with a count of databases and the node
|
|
||||||
* information for which it is attached.
|
|
||||||
*/
|
|
||||||
public function getWithViewDetails(): Collection;
|
|
||||||
}
|
|
@ -5,7 +5,6 @@ namespace App\Extensions;
|
|||||||
use App\Models\DatabaseHost;
|
use App\Models\DatabaseHost;
|
||||||
use Illuminate\Contracts\Encryption\Encrypter;
|
use Illuminate\Contracts\Encryption\Encrypter;
|
||||||
use Illuminate\Config\Repository as ConfigRepository;
|
use Illuminate\Config\Repository as ConfigRepository;
|
||||||
use App\Contracts\Repository\DatabaseHostRepositoryInterface;
|
|
||||||
|
|
||||||
class DynamicDatabaseConnection
|
class DynamicDatabaseConnection
|
||||||
{
|
{
|
||||||
@ -19,7 +18,6 @@ class DynamicDatabaseConnection
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
protected ConfigRepository $config,
|
protected ConfigRepository $config,
|
||||||
protected Encrypter $encrypter,
|
protected Encrypter $encrypter,
|
||||||
protected DatabaseHostRepositoryInterface $repository
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +29,7 @@ class DynamicDatabaseConnection
|
|||||||
public function set(string $connection, DatabaseHost|int $host, string $database = 'mysql'): void
|
public function set(string $connection, DatabaseHost|int $host, string $database = 'mysql'): void
|
||||||
{
|
{
|
||||||
if (!$host instanceof DatabaseHost) {
|
if (!$host instanceof DatabaseHost) {
|
||||||
$host = $this->repository->find($host);
|
$host = DatabaseHost::query()->findOrFail($host);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->config->set('database.connections.' . $connection, [
|
$this->config->set('database.connections.' . $connection, [
|
||||||
|
@ -13,7 +13,6 @@ use App\Services\Databases\Hosts\HostUpdateService;
|
|||||||
use App\Http\Requests\Admin\DatabaseHostFormRequest;
|
use App\Http\Requests\Admin\DatabaseHostFormRequest;
|
||||||
use App\Services\Databases\Hosts\HostCreationService;
|
use App\Services\Databases\Hosts\HostCreationService;
|
||||||
use App\Services\Databases\Hosts\HostDeletionService;
|
use App\Services\Databases\Hosts\HostDeletionService;
|
||||||
use App\Contracts\Repository\DatabaseHostRepositoryInterface;
|
|
||||||
|
|
||||||
class DatabaseController extends Controller
|
class DatabaseController extends Controller
|
||||||
{
|
{
|
||||||
@ -22,7 +21,6 @@ class DatabaseController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private AlertsMessageBag $alert,
|
private AlertsMessageBag $alert,
|
||||||
private DatabaseHostRepositoryInterface $repository,
|
|
||||||
private HostCreationService $creationService,
|
private HostCreationService $creationService,
|
||||||
private HostDeletionService $deletionService,
|
private HostDeletionService $deletionService,
|
||||||
private HostUpdateService $updateService,
|
private HostUpdateService $updateService,
|
||||||
@ -35,9 +33,14 @@ class DatabaseController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index(): View
|
public function index(): View
|
||||||
{
|
{
|
||||||
|
$hosts = DatabaseHost::query()
|
||||||
|
->withCount('databases')
|
||||||
|
->with('node')
|
||||||
|
->get();
|
||||||
|
|
||||||
return $this->view->make('admin.databases.index', [
|
return $this->view->make('admin.databases.index', [
|
||||||
'nodes' => Node::all(),
|
'nodes' => Node::all(),
|
||||||
'hosts' => $this->repository->getWithViewDetails(),
|
'hosts' => $hosts,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Admin\Servers;
|
namespace App\Http\Controllers\Admin\Servers;
|
||||||
|
|
||||||
|
use App\Models\DatabaseHost;
|
||||||
use App\Models\Egg;
|
use App\Models\Egg;
|
||||||
use App\Models\Node;
|
use App\Models\Node;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
@ -13,7 +14,6 @@ use App\Services\Servers\EnvironmentService;
|
|||||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||||
use App\Repositories\Eloquent\MountRepository;
|
use App\Repositories\Eloquent\MountRepository;
|
||||||
use App\Traits\Controllers\JavascriptInjection;
|
use App\Traits\Controllers\JavascriptInjection;
|
||||||
use App\Repositories\Eloquent\DatabaseHostRepository;
|
|
||||||
|
|
||||||
class ServerViewController extends Controller
|
class ServerViewController extends Controller
|
||||||
{
|
{
|
||||||
@ -23,7 +23,6 @@ class ServerViewController extends Controller
|
|||||||
* ServerViewController constructor.
|
* ServerViewController constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private DatabaseHostRepository $databaseHostRepository,
|
|
||||||
private MountRepository $mountRepository,
|
private MountRepository $mountRepository,
|
||||||
private EnvironmentService $environmentService,
|
private EnvironmentService $environmentService,
|
||||||
private ViewFactory $view
|
private ViewFactory $view
|
||||||
@ -85,7 +84,7 @@ class ServerViewController extends Controller
|
|||||||
public function database(Request $request, Server $server): View
|
public function database(Request $request, Server $server): View
|
||||||
{
|
{
|
||||||
return $this->view->make('admin.servers.view.database', [
|
return $this->view->make('admin.servers.view.database', [
|
||||||
'hosts' => $this->databaseHostRepository->all(),
|
'hosts' => DatabaseHost::all(),
|
||||||
'server' => $server,
|
'server' => $server,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ use App\Services\Servers\BuildModificationService;
|
|||||||
use App\Services\Databases\DatabasePasswordService;
|
use App\Services\Databases\DatabasePasswordService;
|
||||||
use App\Services\Servers\DetailsModificationService;
|
use App\Services\Servers\DetailsModificationService;
|
||||||
use App\Services\Servers\StartupModificationService;
|
use App\Services\Servers\StartupModificationService;
|
||||||
use App\Repositories\Eloquent\DatabaseHostRepository;
|
|
||||||
use App\Services\Databases\DatabaseManagementService;
|
use App\Services\Databases\DatabaseManagementService;
|
||||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||||
use App\Services\Servers\ServerConfigurationStructureService;
|
use App\Services\Servers\ServerConfigurationStructureService;
|
||||||
@ -42,7 +41,6 @@ class ServersController extends Controller
|
|||||||
protected DaemonServerRepository $daemonServerRepository,
|
protected DaemonServerRepository $daemonServerRepository,
|
||||||
protected DatabaseManagementService $databaseManagementService,
|
protected DatabaseManagementService $databaseManagementService,
|
||||||
protected DatabasePasswordService $databasePasswordService,
|
protected DatabasePasswordService $databasePasswordService,
|
||||||
protected DatabaseHostRepository $databaseHostRepository,
|
|
||||||
protected ServerDeletionService $deletionService,
|
protected ServerDeletionService $deletionService,
|
||||||
protected DetailsModificationService $detailsModificationService,
|
protected DetailsModificationService $detailsModificationService,
|
||||||
protected ReinstallServerService $reinstallService,
|
protected ReinstallServerService $reinstallService,
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use App\Repositories\Eloquent\DatabaseHostRepository;
|
|
||||||
use App\Contracts\Repository\DatabaseHostRepositoryInterface;
|
|
||||||
|
|
||||||
class RepositoryServiceProvider extends ServiceProvider
|
class RepositoryServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@ -14,6 +12,5 @@ class RepositoryServiceProvider extends ServiceProvider
|
|||||||
public function register(): void
|
public function register(): void
|
||||||
{
|
{
|
||||||
// Eloquent Repositories
|
// Eloquent Repositories
|
||||||
$this->app->bind(DatabaseHostRepositoryInterface::class, DatabaseHostRepository::class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Repositories\Eloquent;
|
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use App\Models\DatabaseHost;
|
|
||||||
use App\Contracts\Repository\DatabaseHostRepositoryInterface;
|
|
||||||
|
|
||||||
class DatabaseHostRepository extends EloquentRepository implements DatabaseHostRepositoryInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Return the model backing this repository.
|
|
||||||
*/
|
|
||||||
public function model(): string
|
|
||||||
{
|
|
||||||
return DatabaseHost::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return database hosts with a count of databases and the node
|
|
||||||
* information for which it is attached.
|
|
||||||
*/
|
|
||||||
public function getWithViewDetails(): Collection
|
|
||||||
{
|
|
||||||
return $this->getBuilder()->withCount('databases')->with('node')->get();
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,7 +7,6 @@ use Illuminate\Database\DatabaseManager;
|
|||||||
use Illuminate\Database\ConnectionInterface;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
use Illuminate\Contracts\Encryption\Encrypter;
|
use Illuminate\Contracts\Encryption\Encrypter;
|
||||||
use App\Extensions\DynamicDatabaseConnection;
|
use App\Extensions\DynamicDatabaseConnection;
|
||||||
use App\Contracts\Repository\DatabaseHostRepositoryInterface;
|
|
||||||
|
|
||||||
class HostCreationService
|
class HostCreationService
|
||||||
{
|
{
|
||||||
@ -19,7 +18,6 @@ class HostCreationService
|
|||||||
private DatabaseManager $databaseManager,
|
private DatabaseManager $databaseManager,
|
||||||
private DynamicDatabaseConnection $dynamic,
|
private DynamicDatabaseConnection $dynamic,
|
||||||
private Encrypter $encrypter,
|
private Encrypter $encrypter,
|
||||||
private DatabaseHostRepositoryInterface $repository
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +29,7 @@ class HostCreationService
|
|||||||
public function handle(array $data): DatabaseHost
|
public function handle(array $data): DatabaseHost
|
||||||
{
|
{
|
||||||
return $this->connection->transaction(function () use ($data) {
|
return $this->connection->transaction(function () use ($data) {
|
||||||
$host = $this->repository->create([
|
$host = DatabaseHost::query()->create([
|
||||||
'password' => $this->encrypter->encrypt(array_get($data, 'password')),
|
'password' => $this->encrypter->encrypt(array_get($data, 'password')),
|
||||||
'name' => array_get($data, 'name'),
|
'name' => array_get($data, 'name'),
|
||||||
'host' => array_get($data, 'host'),
|
'host' => array_get($data, 'host'),
|
||||||
|
@ -7,7 +7,6 @@ use Illuminate\Database\DatabaseManager;
|
|||||||
use Illuminate\Database\ConnectionInterface;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
use Illuminate\Contracts\Encryption\Encrypter;
|
use Illuminate\Contracts\Encryption\Encrypter;
|
||||||
use App\Extensions\DynamicDatabaseConnection;
|
use App\Extensions\DynamicDatabaseConnection;
|
||||||
use App\Contracts\Repository\DatabaseHostRepositoryInterface;
|
|
||||||
|
|
||||||
class HostUpdateService
|
class HostUpdateService
|
||||||
{
|
{
|
||||||
@ -19,7 +18,6 @@ class HostUpdateService
|
|||||||
private DatabaseManager $databaseManager,
|
private DatabaseManager $databaseManager,
|
||||||
private DynamicDatabaseConnection $dynamic,
|
private DynamicDatabaseConnection $dynamic,
|
||||||
private Encrypter $encrypter,
|
private Encrypter $encrypter,
|
||||||
private DatabaseHostRepositoryInterface $repository
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +35,9 @@ class HostUpdateService
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $this->connection->transaction(function () use ($data, $hostId) {
|
return $this->connection->transaction(function () use ($data, $hostId) {
|
||||||
$host = $this->repository->update($hostId, $data);
|
/** @var DatabaseHost $host */
|
||||||
|
$host = DatabaseHost::query()->findOrFail($hostId);
|
||||||
|
$host->update($data);
|
||||||
$this->dynamic->set('dynamic', $host);
|
$this->dynamic->set('dynamic', $host);
|
||||||
$this->databaseManager->connection('dynamic')->select('SELECT 1 FROM dual');
|
$this->databaseManager->connection('dynamic')->select('SELECT 1 FROM dual');
|
||||||
|
|
||||||
|
@ -200,7 +200,6 @@ return [
|
|||||||
App\Providers\EventServiceProvider::class,
|
App\Providers\EventServiceProvider::class,
|
||||||
App\Providers\HashidsServiceProvider::class,
|
App\Providers\HashidsServiceProvider::class,
|
||||||
App\Providers\RouteServiceProvider::class,
|
App\Providers\RouteServiceProvider::class,
|
||||||
App\Providers\RepositoryServiceProvider::class,
|
|
||||||
App\Providers\ViewComposerServiceProvider::class,
|
App\Providers\ViewComposerServiceProvider::class,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user