Begin working on administrative server view changes
Also includes tests for the DatabaseCreation service.
This commit is contained in:
parent
0c513f24d5
commit
580e5ac569
18 changed files with 584 additions and 135 deletions
|
@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue