2017-07-02 21:29:58 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
|
|
|
|
2018-01-04 22:49:50 -06:00
|
|
|
use Illuminate\Support\Collection;
|
2017-08-05 17:26:30 -05:00
|
|
|
use Pterodactyl\Models\DatabaseHost;
|
2018-01-04 22:49:50 -06:00
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
2017-07-02 21:29:58 -05:00
|
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
2017-08-05 17:26:30 -05:00
|
|
|
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
|
2017-07-02 21:29:58 -05:00
|
|
|
|
2017-07-15 11:52:34 -05:00
|
|
|
class DatabaseHostRepository extends EloquentRepository implements DatabaseHostRepositoryInterface
|
2017-07-02 21:29:58 -05:00
|
|
|
{
|
|
|
|
/**
|
2018-01-04 22:49:50 -06:00
|
|
|
* Return the model backing this repository.
|
|
|
|
*
|
|
|
|
* @return string
|
2017-07-02 21:29:58 -05:00
|
|
|
*/
|
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return DatabaseHost::class;
|
|
|
|
}
|
|
|
|
|
2017-08-08 23:24:55 -05:00
|
|
|
/**
|
2018-01-04 22:49:50 -06:00
|
|
|
* Return database hosts with a count of databases and the node
|
|
|
|
* information for which it is attached.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Support\Collection
|
2017-08-08 23:24:55 -05:00
|
|
|
*/
|
2018-01-04 22:49:50 -06:00
|
|
|
public function getWithViewDetails(): Collection
|
2017-08-08 23:24:55 -05:00
|
|
|
{
|
|
|
|
return $this->getBuilder()->withCount('databases')->with('node')->get();
|
|
|
|
}
|
|
|
|
|
2017-08-26 19:58:24 -05:00
|
|
|
/**
|
2018-01-04 22:49:50 -06:00
|
|
|
* 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
|
2017-08-26 19:58:24 -05:00
|
|
|
*/
|
2018-01-04 22:49:50 -06:00
|
|
|
public function getWithServers(int $id): DatabaseHost
|
2017-08-15 23:16:00 -05:00
|
|
|
{
|
2018-01-04 22:49:50 -06:00
|
|
|
try {
|
|
|
|
return $this->getBuilder()->with('databases.server')->findOrFail($id, $this->getColumns());
|
|
|
|
} catch (ModelNotFoundException $exception) {
|
|
|
|
throw new RecordNotFoundException;
|
2017-08-15 23:16:00 -05:00
|
|
|
}
|
|
|
|
}
|
2017-07-02 21:29:58 -05:00
|
|
|
}
|