Finish front-end server modification changes.

Everything is back to the point that it was before this massive code overhaul began. FInal steps before merging this into develop will be some unit tests.
This commit is contained in:
Dane Everitt 2017-10-25 22:33:28 -05:00
parent 5fb4b2cdcf
commit 508ff8cfb3
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
13 changed files with 315 additions and 198 deletions

View file

@ -67,8 +67,8 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
Assert::integerish($id, 'First argument passed to findWithVariables must be integer, received %s.');
$instance = $this->getBuilder()->with('egg.variables', 'variables')
->where($this->getModel()->getKeyName(), '=', $id)
->first($this->getColumns());
->where($this->getModel()->getKeyName(), '=', $id)
->first($this->getColumns());
if (is_null($instance)) {
throw new RecordNotFoundException();
@ -77,6 +77,36 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
return $instance;
}
/**
* Get the primary allocation for a given server. If a model is passed into
* the function, load the allocation relationship onto it. Otherwise, find and
* return the server from the database.
*
* @param int|\Pterodactyl\Models\Server $server
* @param bool $refresh
* @return \Pterodactyl\Models\Server
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getPrimaryAllocation($server, bool $refresh = false): Server
{
$instance = $server;
if (! $instance instanceof Server) {
Assert::integerish($server, 'First argument passed to getPrimaryAllocation must be instance of \Pterodactyl\Models\Server or integer, received %s.');
$instance = $this->getBuilder()->find($server, $this->getColumns());
}
if (! $instance) {
throw new RecordNotFoundException;
}
if (! $instance->relationLoaded('allocation') || $refresh) {
$instance->load('allocation');
}
return $instance;
}
/**
* {@inheritdoc}
*/