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

@ -9,6 +9,7 @@
namespace Pterodactyl\Repositories\Eloquent;
use Illuminate\Support\Collection;
use Pterodactyl\Models\EggVariable;
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
@ -21,4 +22,20 @@ class EggVariableRepository extends EloquentRepository implements EggVariableRep
{
return EggVariable::class;
}
/**
* Return editable variables for a given egg. Editable variables must be set to
* user viewable in order to be picked up by this function.
*
* @param int $egg
* @return \Illuminate\Support\Collection
*/
public function getEditableVariables(int $egg): Collection
{
return $this->getBuilder()->where([
['egg_id', '=', $egg],
['user_viewable', '=', 1],
['user_editable', '=', 1],
])->get($this->getColumns());
}
}

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}
*/