Begin working on administrative server view changes

Also includes tests for the DatabaseCreation service.
This commit is contained in:
Dane Everitt 2017-07-21 21:17:42 -05:00
parent 0c513f24d5
commit 580e5ac569
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
18 changed files with 584 additions and 135 deletions

View file

@ -79,8 +79,8 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
array_set($data, $key, $value);
}
// $this->getHttpClient()->request('POST', '/servers', [
// 'json' => $data,
// ]);
return $this->getHttpClient()->request('POST', '/servers', [
'json' => $data,
]);
}
}

View file

@ -44,4 +44,12 @@ class AllocationRepository extends EloquentRepository implements AllocationRepos
{
return $this->getBuilder()->whereIn('id', $ids)->update(['server_id' => $server]);
}
/**
* {@inheritdoc}
*/
public function getAllocationsForNode($node)
{
return $this->getBuilder()->where('node_id', $node)->get();
}
}

View file

@ -37,4 +37,31 @@ class NodeRepository extends SearchableRepository implements NodeRepositoryInter
{
return Node::class;
}
/**
* {@inheritdoc}
*/
public function getNodesForLocation($location)
{
$instance = $this->getBuilder()->with('allocations')->where('location_id', $location)->get();
return $instance->map(function ($item) {
$filtered = $item->allocations->where('server_id', null)->map(function ($map) {
return collect($map)->only(['id', 'ip', 'port']);
});
$item->ports = $filtered->map(function ($map) {
return [
'id' => $map['id'],
'text' => sprintf('%s:%s', $map['ip'], $map['port']),
];
})->values();
return [
'id' => $item->id,
'text' => $item->name,
'allocations' => $item->ports,
];
})->values();
}
}

View file

@ -24,8 +24,8 @@
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Pterodactyl\Models\Server;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Repositories\Eloquent\Attributes\SearchableRepository;
@ -60,8 +60,8 @@ class ServerRepository extends SearchableRepository implements ServerRepositoryI
public function findWithVariables($id)
{
$instance = $this->getBuilder()->with('option.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();
@ -73,10 +73,10 @@ class ServerRepository extends SearchableRepository implements ServerRepositoryI
/**
* {@inheritdoc}
*/
public function getVariablesWithValues($id)
public function getVariablesWithValues($id, $returnWithObject = false)
{
$instance = $this->getBuilder()->with('variables', 'option.variables')
->find($id, $this->getColumns());
->find($id, $this->getColumns());
if (! $instance) {
throw new RecordNotFoundException();
@ -89,13 +89,39 @@ class ServerRepository extends SearchableRepository implements ServerRepositoryI
$data[$item->env_variable] = $display ?? $item->default_value;
});
if ($returnWithObject) {
return (object) [
'data' => $data,
'server' => $instance,
];
}
return $data;
}
/**
* {@inheritdoc}
*/
public function getDataForCreation($id)
{
$instance = $this->getBuilder()->with('allocation', 'allocations', 'pack', 'option.service')
->find($id, $this->getColumns());
->find($id, $this->getColumns());
if (! $instance) {
throw new RecordNotFoundException();
}
return $instance;
}
/**
* {@inheritdoc}
*/
public function getWithDatabases($id)
{
$instance = $this->getBuilder()->with('databases.host')
->where('installed', 1)
->find($id, $this->getColumns());
if (! $instance) {
throw new RecordNotFoundException();