diff --git a/CHANGELOG.md b/CHANGELOG.md index dd53c2a83..313ef0b61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### Fixed * Fixes application API keys being created as a client API key. +### Changed +* Databases are now properly paginated when viewing a database host. + ## v0.7.4-h1 (Derelict Dermodactylus) ### Fixed * Being able to create servers is kind of a core aspect of the software, pushing releases late at night is not a great idea. diff --git a/app/Contracts/Repository/DatabaseHostRepositoryInterface.php b/app/Contracts/Repository/DatabaseHostRepositoryInterface.php index dfd29e9ab..a924d85a9 100644 --- a/app/Contracts/Repository/DatabaseHostRepositoryInterface.php +++ b/app/Contracts/Repository/DatabaseHostRepositoryInterface.php @@ -3,7 +3,6 @@ namespace Pterodactyl\Contracts\Repository; use Illuminate\Support\Collection; -use Pterodactyl\Models\DatabaseHost; interface DatabaseHostRepositoryInterface extends RepositoryInterface { @@ -14,15 +13,4 @@ interface DatabaseHostRepositoryInterface extends RepositoryInterface * @return \Illuminate\Support\Collection */ public function getWithViewDetails(): Collection; - - /** - * Return a database host with the databases and associated servers - * that are attached to said databases. - * - * @param int $id - * @return \Pterodactyl\Models\DatabaseHost - * - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException - */ - public function getWithServers(int $id): DatabaseHost; } diff --git a/app/Contracts/Repository/DatabaseRepositoryInterface.php b/app/Contracts/Repository/DatabaseRepositoryInterface.php index 7fc3bf045..f5d531513 100644 --- a/app/Contracts/Repository/DatabaseRepositoryInterface.php +++ b/app/Contracts/Repository/DatabaseRepositoryInterface.php @@ -1,16 +1,10 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Pterodactyl\Contracts\Repository; use Pterodactyl\Models\Database; use Illuminate\Support\Collection; +use Illuminate\Contracts\Pagination\LengthAwarePaginator; interface DatabaseRepositoryInterface extends RepositoryInterface { @@ -39,6 +33,15 @@ interface DatabaseRepositoryInterface extends RepositoryInterface */ public function getDatabasesForServer(int $server): Collection; + /** + * Return all of the databases for a given host with the server relationship loaded. + * + * @param int $host + * @param int $count + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator + */ + public function getDatabasesForHost(int $host, int $count = 25): LengthAwarePaginator; + /** * Create a new database if it does not already exist on the host with * the provided details. diff --git a/app/Http/Controllers/Admin/DatabaseController.php b/app/Http/Controllers/Admin/DatabaseController.php index d03f7050e..affb0c80e 100644 --- a/app/Http/Controllers/Admin/DatabaseController.php +++ b/app/Http/Controllers/Admin/DatabaseController.php @@ -1,11 +1,4 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Pterodactyl\Http\Controllers\Admin; @@ -19,6 +12,7 @@ use Pterodactyl\Services\Databases\Hosts\HostUpdateService; use Pterodactyl\Http\Requests\Admin\DatabaseHostFormRequest; 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; @@ -34,6 +28,11 @@ class DatabaseController extends Controller */ private $creationService; + /** + * @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface + */ + private $databaseRepository; + /** * @var \Pterodactyl\Services\Databases\Hosts\HostDeletionService */ @@ -59,6 +58,7 @@ class DatabaseController extends Controller * * @param \Prologue\Alerts\AlertsMessageBag $alert * @param \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface $repository + * @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $databaseRepository * @param \Pterodactyl\Services\Databases\Hosts\HostCreationService $creationService * @param \Pterodactyl\Services\Databases\Hosts\HostDeletionService $deletionService * @param \Pterodactyl\Services\Databases\Hosts\HostUpdateService $updateService @@ -67,6 +67,7 @@ class DatabaseController extends Controller public function __construct( AlertsMessageBag $alert, DatabaseHostRepositoryInterface $repository, + DatabaseRepositoryInterface $databaseRepository, HostCreationService $creationService, HostDeletionService $deletionService, HostUpdateService $updateService, @@ -74,6 +75,7 @@ class DatabaseController extends Controller ) { $this->alert = $alert; $this->creationService = $creationService; + $this->databaseRepository = $databaseRepository; $this->deletionService = $deletionService; $this->repository = $repository; $this->locationRepository = $locationRepository; @@ -105,7 +107,8 @@ class DatabaseController extends Controller { return view('admin.databases.view', [ 'locations' => $this->locationRepository->getAllWithNodes(), - 'host' => $this->repository->getWithServers($host), + 'host' => $this->repository->find($host), + 'databases' => $this->databaseRepository->getDatabasesForHost($host), ]); } diff --git a/app/Repositories/Eloquent/DatabaseHostRepository.php b/app/Repositories/Eloquent/DatabaseHostRepository.php index 6bfb94d70..4ed4d411e 100644 --- a/app/Repositories/Eloquent/DatabaseHostRepository.php +++ b/app/Repositories/Eloquent/DatabaseHostRepository.php @@ -4,8 +4,6 @@ namespace Pterodactyl\Repositories\Eloquent; use Illuminate\Support\Collection; use Pterodactyl\Models\DatabaseHost; -use Illuminate\Database\Eloquent\ModelNotFoundException; -use Pterodactyl\Exceptions\Repository\RecordNotFoundException; use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface; class DatabaseHostRepository extends EloquentRepository implements DatabaseHostRepositoryInterface @@ -30,22 +28,4 @@ class DatabaseHostRepository extends EloquentRepository implements DatabaseHostR { return $this->getBuilder()->withCount('databases')->with('node')->get(); } - - /** - * Return a database host with the databases and associated servers - * that are attached to said databases. - * - * @param int $id - * @return \Pterodactyl\Models\DatabaseHost - * - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException - */ - public function getWithServers(int $id): DatabaseHost - { - try { - return $this->getBuilder()->with('databases.server')->findOrFail($id, $this->getColumns()); - } catch (ModelNotFoundException $exception) { - throw new RecordNotFoundException; - } - } } diff --git a/app/Repositories/Eloquent/DatabaseRepository.php b/app/Repositories/Eloquent/DatabaseRepository.php index d24dd177e..8a8c93fd8 100644 --- a/app/Repositories/Eloquent/DatabaseRepository.php +++ b/app/Repositories/Eloquent/DatabaseRepository.php @@ -6,6 +6,7 @@ use Pterodactyl\Models\Database; use Illuminate\Support\Collection; use Illuminate\Foundation\Application; use Illuminate\Database\DatabaseManager; +use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface; use Pterodactyl\Exceptions\Repository\DuplicateDatabaseNameException; @@ -78,6 +79,20 @@ class DatabaseRepository extends EloquentRepository implements DatabaseRepositor return $this->getBuilder()->where('server_id', $server)->get($this->getColumns()); } + /** + * Return all of the databases for a given host with the server relationship loaded. + * + * @param int $host + * @param int $count + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator + */ + public function getDatabasesForHost(int $host, int $count = 25): LengthAwarePaginator + { + return $this->getBuilder()->with('server') + ->where('database_host_id', $host) + ->paginate($count, $this->getColumns()); + } + /** * Create a new database if it does not already exist on the host with * the provided details. diff --git a/resources/themes/pterodactyl/admin/databases/view.blade.php b/resources/themes/pterodactyl/admin/databases/view.blade.php index 41a2d7901..655b833fc 100644 --- a/resources/themes/pterodactyl/admin/databases/view.blade.php +++ b/resources/themes/pterodactyl/admin/databases/view.blade.php @@ -101,14 +101,14 @@