diff --git a/app/Contracts/Repository/DatabaseHostRepositoryInterface.php b/app/Contracts/Repository/DatabaseHostRepositoryInterface.php deleted file mode 100644 index 01f1ca4b4..000000000 --- a/app/Contracts/Repository/DatabaseHostRepositoryInterface.php +++ /dev/null @@ -1,14 +0,0 @@ -repository->find($host); + $host = DatabaseHost::query()->findOrFail($host); } $this->config->set('database.connections.' . $connection, [ diff --git a/app/Http/Controllers/Admin/DatabaseController.php b/app/Http/Controllers/Admin/DatabaseController.php index e0dc0dc57..a11ec9182 100644 --- a/app/Http/Controllers/Admin/DatabaseController.php +++ b/app/Http/Controllers/Admin/DatabaseController.php @@ -12,11 +12,11 @@ use Illuminate\View\Factory as ViewFactory; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Services\Databases\Hosts\HostUpdateService; use Pterodactyl\Http\Requests\Admin\DatabaseHostFormRequest; +use Pterodactyl\Exceptions\Service\HasActiveServersException; use Pterodactyl\Services\Databases\Hosts\HostCreationService; use Pterodactyl\Services\Databases\Hosts\HostDeletionService; use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface; use Pterodactyl\Contracts\Repository\LocationRepositoryInterface; -use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface; class DatabaseController extends Controller { @@ -25,7 +25,6 @@ class DatabaseController extends Controller */ public function __construct( private AlertsMessageBag $alert, - private DatabaseHostRepositoryInterface $repository, private DatabaseRepositoryInterface $databaseRepository, private HostCreationService $creationService, private HostDeletionService $deletionService, @@ -40,22 +39,25 @@ class DatabaseController extends Controller */ public function index(): View { + $hosts = DatabaseHost::query() + ->withCount('databases') + ->with('node') + ->get(); + return $this->view->make('admin.databases.index', [ 'locations' => $this->locationRepository->getAllWithNodes(), - 'hosts' => $this->repository->getWithViewDetails(), + 'hosts' => $hosts, ]); } /** * Display database host to user. - * - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ public function view(int $host): View { return $this->view->make('admin.databases.view', [ 'locations' => $this->locationRepository->getAllWithNodes(), - 'host' => $this->repository->find($host), + 'host' => DatabaseHost::query()->findOrFail($host), 'databases' => $this->databaseRepository->getDatabasesForHost($host), ]); } @@ -118,7 +120,7 @@ class DatabaseController extends Controller /** * Handle request to delete a database host. * - * @throws \Pterodactyl\Exceptions\Service\HasActiveServersException + * @throws HasActiveServersException */ public function delete(int $host): RedirectResponse { diff --git a/app/Http/Controllers/Admin/Servers/ServerViewController.php b/app/Http/Controllers/Admin/Servers/ServerViewController.php index 7cf64a2f5..bffeddf9a 100644 --- a/app/Http/Controllers/Admin/Servers/ServerViewController.php +++ b/app/Http/Controllers/Admin/Servers/ServerViewController.php @@ -7,6 +7,7 @@ use Illuminate\View\View; use Illuminate\Http\Request; use Pterodactyl\Models\Nest; use Pterodactyl\Models\Server; +use Pterodactyl\Models\DatabaseHost; use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Services\Servers\EnvironmentService; @@ -17,7 +18,6 @@ use Pterodactyl\Repositories\Eloquent\MountRepository; use Pterodactyl\Repositories\Eloquent\ServerRepository; use Pterodactyl\Traits\Controllers\JavascriptInjection; use Pterodactyl\Repositories\Eloquent\LocationRepository; -use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository; class ServerViewController extends Controller { @@ -27,7 +27,6 @@ class ServerViewController extends Controller * ServerViewController constructor. */ public function __construct( - private DatabaseHostRepository $databaseHostRepository, private LocationRepository $locationRepository, private MountRepository $mountRepository, private NestRepository $nestRepository, @@ -97,7 +96,7 @@ class ServerViewController extends Controller public function database(Request $request, Server $server): View { return $this->view->make('admin.servers.view.database', [ - 'hosts' => $this->databaseHostRepository->all(), + 'hosts' => DatabaseHost::all(), 'server' => $server, ]); } diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index 3d2c55ac4..9450ad1ef 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -25,7 +25,6 @@ use Pterodactyl\Services\Databases\DatabasePasswordService; use Pterodactyl\Services\Servers\DetailsModificationService; use Pterodactyl\Services\Servers\StartupModificationService; use Pterodactyl\Contracts\Repository\NestRepositoryInterface; -use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository; use Pterodactyl\Services\Databases\DatabaseManagementService; use Illuminate\Contracts\Config\Repository as ConfigRepository; use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; @@ -48,7 +47,6 @@ class ServersController extends Controller protected DatabaseManagementService $databaseManagementService, protected DatabasePasswordService $databasePasswordService, protected DatabaseRepositoryInterface $databaseRepository, - protected DatabaseHostRepository $databaseHostRepository, protected ServerDeletionService $deletionService, protected DetailsModificationService $detailsModificationService, protected ReinstallServerService $reinstallService, diff --git a/app/Providers/RepositoryServiceProvider.php b/app/Providers/RepositoryServiceProvider.php index 8a0434f52..4842fe2f9 100644 --- a/app/Providers/RepositoryServiceProvider.php +++ b/app/Providers/RepositoryServiceProvider.php @@ -23,7 +23,6 @@ use Pterodactyl\Contracts\Repository\NestRepositoryInterface; use Pterodactyl\Contracts\Repository\NodeRepositoryInterface; use Pterodactyl\Contracts\Repository\TaskRepositoryInterface; use Pterodactyl\Contracts\Repository\UserRepositoryInterface; -use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository; use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface; use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; use Pterodactyl\Repositories\Eloquent\ServerVariableRepository; @@ -35,7 +34,6 @@ use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface; use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface; use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface; use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface; -use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface; use Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface; class RepositoryServiceProvider extends ServiceProvider @@ -49,7 +47,6 @@ class RepositoryServiceProvider extends ServiceProvider $this->app->bind(AllocationRepositoryInterface::class, AllocationRepository::class); $this->app->bind(ApiKeyRepositoryInterface::class, ApiKeyRepository::class); $this->app->bind(DatabaseRepositoryInterface::class, DatabaseRepository::class); - $this->app->bind(DatabaseHostRepositoryInterface::class, DatabaseHostRepository::class); $this->app->bind(EggRepositoryInterface::class, EggRepository::class); $this->app->bind(EggVariableRepositoryInterface::class, EggVariableRepository::class); $this->app->bind(LocationRepositoryInterface::class, LocationRepository::class); diff --git a/app/Repositories/Eloquent/DatabaseHostRepository.php b/app/Repositories/Eloquent/DatabaseHostRepository.php deleted file mode 100644 index 2c2b9dcde..000000000 --- a/app/Repositories/Eloquent/DatabaseHostRepository.php +++ /dev/null @@ -1,27 +0,0 @@ -getBuilder()->withCount('databases')->with('node')->get(); - } -} diff --git a/app/Services/Databases/Hosts/HostCreationService.php b/app/Services/Databases/Hosts/HostCreationService.php index d33a15856..919bbe403 100644 --- a/app/Services/Databases/Hosts/HostCreationService.php +++ b/app/Services/Databases/Hosts/HostCreationService.php @@ -7,7 +7,6 @@ use Illuminate\Database\DatabaseManager; use Illuminate\Database\ConnectionInterface; use Illuminate\Contracts\Encryption\Encrypter; use Pterodactyl\Extensions\DynamicDatabaseConnection; -use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface; class HostCreationService { @@ -18,8 +17,7 @@ class HostCreationService private ConnectionInterface $connection, private DatabaseManager $databaseManager, private DynamicDatabaseConnection $dynamic, - private Encrypter $encrypter, - private DatabaseHostRepositoryInterface $repository + private Encrypter $encrypter ) { } @@ -31,7 +29,8 @@ class HostCreationService public function handle(array $data): DatabaseHost { return $this->connection->transaction(function () use ($data) { - $host = $this->repository->create([ + /** @var DatabaseHost $host */ + $host = DatabaseHost::query()->create([ 'password' => $this->encrypter->encrypt(array_get($data, 'password')), 'name' => array_get($data, 'name'), 'host' => array_get($data, 'host'), diff --git a/app/Services/Databases/Hosts/HostDeletionService.php b/app/Services/Databases/Hosts/HostDeletionService.php index 4a06af8da..7c782dc75 100644 --- a/app/Services/Databases/Hosts/HostDeletionService.php +++ b/app/Services/Databases/Hosts/HostDeletionService.php @@ -2,9 +2,9 @@ namespace Pterodactyl\Services\Databases\Hosts; +use Pterodactyl\Models\DatabaseHost; use Pterodactyl\Exceptions\Service\HasActiveServersException; use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface; -use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface; class HostDeletionService { @@ -12,8 +12,7 @@ class HostDeletionService * HostDeletionService constructor. */ public function __construct( - private DatabaseRepositoryInterface $databaseRepository, - private DatabaseHostRepositoryInterface $repository + private DatabaseRepositoryInterface $databaseRepository ) { } @@ -21,7 +20,7 @@ class HostDeletionService * Delete a specified host from the Panel if no databases are * attached to it. * - * @throws \Pterodactyl\Exceptions\Service\HasActiveServersException + * @throws HasActiveServersException */ public function handle(int $host): int { @@ -30,6 +29,11 @@ class HostDeletionService throw new HasActiveServersException(trans('exceptions.databases.delete_has_databases')); } - return $this->repository->delete($host); + $host = DatabaseHost::query()->find($host); + if ($host) { + return $host->delete(); + } + + return true; } } diff --git a/app/Services/Databases/Hosts/HostUpdateService.php b/app/Services/Databases/Hosts/HostUpdateService.php index 363deb1b3..8edfa82dc 100644 --- a/app/Services/Databases/Hosts/HostUpdateService.php +++ b/app/Services/Databases/Hosts/HostUpdateService.php @@ -7,7 +7,6 @@ use Illuminate\Database\DatabaseManager; use Illuminate\Database\ConnectionInterface; use Illuminate\Contracts\Encryption\Encrypter; use Pterodactyl\Extensions\DynamicDatabaseConnection; -use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface; class HostUpdateService { @@ -18,8 +17,7 @@ class HostUpdateService private ConnectionInterface $connection, private DatabaseManager $databaseManager, private DynamicDatabaseConnection $dynamic, - private Encrypter $encrypter, - private DatabaseHostRepositoryInterface $repository + private Encrypter $encrypter ) { } @@ -37,7 +35,9 @@ class HostUpdateService } 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->databaseManager->connection('dynamic')->select('SELECT 1 FROM dual');