Add build modification settings, fix exception handling to log to file
This commit is contained in:
parent
ace70a3599
commit
f842aae3d3
15 changed files with 427 additions and 50 deletions
|
@ -83,7 +83,7 @@ interface RepositoryInterface
|
|||
/**
|
||||
* Delete a given record from the database.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
* @return bool|null
|
||||
*/
|
||||
public function delete($id);
|
||||
|
@ -130,6 +130,17 @@ interface RepositoryInterface
|
|||
*/
|
||||
public function update($id, array $fields, $validate = true, $force = false);
|
||||
|
||||
/**
|
||||
* Perform a mass update where matching records are updated using whereIn.
|
||||
* This does not perform any model data validation.
|
||||
*
|
||||
* @param string $column
|
||||
* @param array $values
|
||||
* @param array $fields
|
||||
* @return int
|
||||
*/
|
||||
public function updateWhereIn($column, array $values, array $fields);
|
||||
|
||||
/**
|
||||
* Update multiple records matching the passed clauses.
|
||||
*
|
||||
|
|
|
@ -44,6 +44,7 @@ use Pterodactyl\Http\Controllers\Controller;
|
|||
use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
use Pterodactyl\Services\Database\CreationService as DatabaseCreationService;
|
||||
use Pterodactyl\Services\Servers\BuildModificationService;
|
||||
use Pterodactyl\Services\Servers\ContainerRebuildService;
|
||||
use Pterodactyl\Services\Servers\CreationService;
|
||||
use Pterodactyl\Services\Servers\DetailsModificationService;
|
||||
|
@ -62,6 +63,11 @@ class ServersController extends Controller
|
|||
*/
|
||||
protected $allocationRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\BuildModificationService
|
||||
*/
|
||||
protected $buildModificationService;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository
|
||||
*/
|
||||
|
@ -132,6 +138,7 @@ class ServersController extends Controller
|
|||
*
|
||||
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
||||
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository
|
||||
* @param \Pterodactyl\Services\Servers\BuildModificationService $buildModificationService
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
* @param \Pterodactyl\Services\Servers\ContainerRebuildService $containerRebuildService
|
||||
* @param \Pterodactyl\Services\Servers\CreationService $service
|
||||
|
@ -149,6 +156,7 @@ class ServersController extends Controller
|
|||
public function __construct(
|
||||
AlertsMessageBag $alert,
|
||||
AllocationRepositoryInterface $allocationRepository,
|
||||
BuildModificationService $buildModificationService,
|
||||
ConfigRepository $config,
|
||||
ContainerRebuildService $containerRebuildService,
|
||||
CreationService $service,
|
||||
|
@ -165,6 +173,7 @@ class ServersController extends Controller
|
|||
) {
|
||||
$this->alert = $alert;
|
||||
$this->allocationRepository = $allocationRepository;
|
||||
$this->buildModificationService = $buildModificationService;
|
||||
$this->config = $config;
|
||||
$this->containerRebuildService = $containerRebuildService;
|
||||
$this->databaseCreationService = $databaseCreationService;
|
||||
|
@ -490,39 +499,22 @@ class ServersController extends Controller
|
|||
/**
|
||||
* Update the build configuration for a server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @internal param int $id
|
||||
*/
|
||||
public function updateBuild(Request $request, $id)
|
||||
public function updateBuild(Request $request, Server $server)
|
||||
{
|
||||
$repo = new ServerRepository;
|
||||
|
||||
try {
|
||||
$repo->changeBuild($id, $request->intersect([
|
||||
$this->buildModificationService->handle($server, $request->intersect([
|
||||
'allocation_id', 'add_allocations', 'remove_allocations',
|
||||
'memory', 'swap', 'io', 'cpu', 'disk',
|
||||
]));
|
||||
]));
|
||||
$this->alert->success(trans('admin/server.alerts.build_updated'))->flash();
|
||||
|
||||
Alert::success('Server details were successfully updated.')->flash();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()
|
||||
->route('admin.servers.view.build', $id)
|
||||
->withErrors(json_decode($ex->getMessage()))
|
||||
->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (TransferException $ex) {
|
||||
Log::warning($ex);
|
||||
Alert::danger('A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.')
|
||||
->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An unhandled exception occured while attemping to add this server. This error has been logged.')
|
||||
->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.servers.view.build', $id);
|
||||
return redirect()->route('admin.servers.view.build', $server->id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -145,6 +145,14 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
|
|||
return ($this->withFresh) ? $instance->fresh() : $saved;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updateWhereIn($column, array $values, array $fields)
|
||||
{
|
||||
return $this->getBuilder()->whereIn($column, $values)->update($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
244
app/Services/Servers/BuildModificationService.php
Normal file
244
app/Services/Servers/BuildModificationService.php
Normal file
|
@ -0,0 +1,244 @@
|
|||
<?php
|
||||
/*
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Servers;
|
||||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Log\Writer;
|
||||
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
use Pterodactyl\Models\Server;
|
||||
|
||||
class BuildModificationService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface
|
||||
*/
|
||||
protected $allocationRepository;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $build = [];
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface
|
||||
*/
|
||||
protected $daemonServerRepository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* @var null|int
|
||||
*/
|
||||
protected $firstAllocationId = null;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Log\Writer
|
||||
*/
|
||||
protected $writer;
|
||||
|
||||
/**
|
||||
* BuildModificationService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository
|
||||
* @param \Illuminate\Database\ConnectionInterface $database
|
||||
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonServerRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
||||
* @param \Illuminate\Log\Writer $writer
|
||||
*/
|
||||
public function __construct(
|
||||
AllocationRepositoryInterface $allocationRepository,
|
||||
ConnectionInterface $database,
|
||||
DaemonServerRepositoryInterface $daemonServerRepository,
|
||||
ServerRepositoryInterface $repository,
|
||||
Writer $writer
|
||||
) {
|
||||
$this->allocationRepository = $allocationRepository;
|
||||
$this->daemonServerRepository = $daemonServerRepository;
|
||||
$this->database = $database;
|
||||
$this->repository = $repository;
|
||||
$this->writer = $writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set build array parameters.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setBuild($key, $value)
|
||||
{
|
||||
$this->build[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the build array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBuild()
|
||||
{
|
||||
return $this->build;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the build details for a specified server.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\Server $server
|
||||
* @param array $data
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function handle($server, array $data)
|
||||
{
|
||||
if (! $server instanceof Server) {
|
||||
$server = $this->repository->find($server);
|
||||
}
|
||||
|
||||
$data['allocation_id'] = array_get($data, 'allocation_id', $server->allocation_id);
|
||||
$this->database->beginTransaction();
|
||||
|
||||
$this->setBuild('memory', (int) array_get($data, 'memory', $server->memory));
|
||||
$this->setBuild('swap', (int) array_get($data, 'swap', $server->swap));
|
||||
$this->setBuild('io', (int) array_get($data, 'io', $server->io));
|
||||
$this->setBuild('cpu', (int) array_get($data, 'cpu', $server->cpu));
|
||||
$this->setBuild('disk', (int) array_get($data, 'disk', $server->disk));
|
||||
|
||||
$this->processAllocations($server, $data);
|
||||
$allocations = $this->allocationRepository->findWhere([
|
||||
['server_id', '=', $server->id],
|
||||
]);
|
||||
|
||||
if (isset($data['allocation_id']) && $data['allocation_id'] != $server->allocation_id) {
|
||||
try {
|
||||
$allocation = $this->allocationRepository->findFirstWhere([
|
||||
['id', '=', $data['allocation_id']],
|
||||
['server_id', '=', $server->id],
|
||||
]);
|
||||
} catch (RecordNotFoundException $ex) {
|
||||
throw new DisplayException(trans('admin/server.exceptions.default_allocation_not_found'));
|
||||
}
|
||||
|
||||
$this->setBuild('default', ['ip' => $allocation->ip, 'port' => $allocation->port]);
|
||||
}
|
||||
|
||||
$this->setBuild('ports|overwrite', $allocations->groupBy('ip')->map(function ($item) {
|
||||
return $item->pluck('port');
|
||||
})->toArray());
|
||||
|
||||
try {
|
||||
$this->daemonServerRepository->setNode($server->node_id)->setAccessServer($server->uuid)->update([
|
||||
'build' => $this->getBuild(),
|
||||
]);
|
||||
|
||||
$this->database->commit();
|
||||
} catch (RequestException $exception) {
|
||||
$response = $exception->getResponse();
|
||||
$this->writer->warning($exception);
|
||||
|
||||
throw new DisplayException(trans('admin/server.exceptions.daemon_exception', [
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the allocations being assigned in the data and ensure they are available for a server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param array $data
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
*/
|
||||
public function processAllocations(Server $server, array &$data)
|
||||
{
|
||||
if (! array_key_exists('add_allocations', $data) && ! array_key_exists('remove_allocations', $data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through allocations to add.
|
||||
if (array_key_exists('add_allocations', $data) && ! empty($data['add_allocations'])) {
|
||||
$unassigned = $this->allocationRepository->findWhere([
|
||||
['server_id', '=', null],
|
||||
['node_id', '=', $server->node_id],
|
||||
])->pluck('id')->toArray();
|
||||
|
||||
foreach ($data['add_allocations'] as $allocation) {
|
||||
if (! in_array($allocation, $unassigned)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->firstAllocationId = $this->firstAllocationId ?? $allocation;
|
||||
$toUpdate[] = [$allocation];
|
||||
}
|
||||
|
||||
if (isset($toUpdate)) {
|
||||
$this->allocationRepository->updateWhereIn('id', $toUpdate, ['server_id' => $server->id]);
|
||||
unset($toUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
// Loop through allocations to remove.
|
||||
if (array_key_exists('remove_allocations', $data) && ! empty($data['remove_allocations'])) {
|
||||
$assigned = $this->allocationRepository->findWhere([
|
||||
['server_id', '=', $server->id],
|
||||
])->pluck('id')->toArray();
|
||||
|
||||
foreach ($data['remove_allocations'] as $allocation) {
|
||||
if (! in_array($allocation, $assigned)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($allocation == $data['allocation_id']) {
|
||||
if (is_null($this->firstAllocationId)) {
|
||||
throw new DisplayException(trans('admin/server.exceptions.no_new_default_allocation'));
|
||||
}
|
||||
|
||||
$data['allocation_id'] = $this->firstAllocationId;
|
||||
}
|
||||
|
||||
$toUpdate[] = [$allocation];
|
||||
}
|
||||
|
||||
if (isset($toUpdate)) {
|
||||
$this->allocationRepository->updateWhereIn('id', $toUpdate, ['server_id' => null]);
|
||||
unset($toUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@
|
|||
namespace Pterodactyl\Services\Servers;
|
||||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Log\Writer;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
@ -42,18 +43,26 @@ class ContainerRebuildService
|
|||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Log\Writer
|
||||
*/
|
||||
protected $writer;
|
||||
|
||||
/**
|
||||
* ContainerRebuildService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonServerRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
||||
* @param \Illuminate\Log\Writer $writer
|
||||
*/
|
||||
public function __construct(
|
||||
DaemonServerRepositoryInterface $daemonServerRepository,
|
||||
ServerRepositoryInterface $repository
|
||||
ServerRepositoryInterface $repository,
|
||||
Writer $writer
|
||||
) {
|
||||
$this->daemonServerRepository = $daemonServerRepository;
|
||||
$this->repository = $repository;
|
||||
$this->writer = $writer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,8 +81,11 @@ class ContainerRebuildService
|
|||
try {
|
||||
$this->daemonServerRepository->setNode($server->node_id)->setAccessServer($server->uuid)->rebuild();
|
||||
} catch (RequestException $exception) {
|
||||
$response = $exception->getResponse();
|
||||
$this->writer->warning($exception);
|
||||
|
||||
throw new DisplayException(trans('admin/server.exceptions.daemon_exception', [
|
||||
'code' => $exception->getResponse()->getStatusCode(),
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
|
||||
namespace Pterodactyl\Services\Servers;
|
||||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Log\Writer;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
|
@ -80,6 +83,11 @@ class CreationService
|
|||
*/
|
||||
protected $validatorService;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Log\Writer
|
||||
*/
|
||||
protected $writer;
|
||||
|
||||
/**
|
||||
* CreationService constructor.
|
||||
*
|
||||
|
@ -92,6 +100,7 @@ class CreationService
|
|||
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $userRepository
|
||||
* @param \Pterodactyl\Services\Servers\UsernameGenerationService $usernameService
|
||||
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
|
||||
* @param \Illuminate\Log\Writer $writer
|
||||
*/
|
||||
public function __construct(
|
||||
AllocationRepositoryInterface $allocationRepository,
|
||||
|
@ -102,7 +111,8 @@ class CreationService
|
|||
ServerVariableRepositoryInterface $serverVariableRepository,
|
||||
UserRepositoryInterface $userRepository,
|
||||
UsernameGenerationService $usernameService,
|
||||
VariableValidatorService $validatorService
|
||||
VariableValidatorService $validatorService,
|
||||
Writer $writer
|
||||
) {
|
||||
$this->allocationRepository = $allocationRepository;
|
||||
$this->daemonServerRepository = $daemonServerRepository;
|
||||
|
@ -113,6 +123,7 @@ class CreationService
|
|||
$this->userRepository = $userRepository;
|
||||
$this->usernameService = $usernameService;
|
||||
$this->validatorService = $validatorService;
|
||||
$this->writer = $writer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,6 +132,7 @@ class CreationService
|
|||
* @param array $data
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function create(array $data)
|
||||
|
@ -178,9 +190,17 @@ class CreationService
|
|||
$this->serverVariableRepository->insert($records);
|
||||
|
||||
// Create the server on the daemon & commit it to the database.
|
||||
$this->daemonServerRepository->setNode($server->node_id)->create($server->id);
|
||||
try {
|
||||
$this->daemonServerRepository->setNode($server->node_id)->create($server->id);
|
||||
$this->database->commit();
|
||||
} catch (RequestException $exception) {
|
||||
$response = $exception->getResponse();
|
||||
$this->writer->warning($exception);
|
||||
|
||||
$this->database->commit();
|
||||
throw new DisplayException(trans('admin/server.exceptions.daemon_exception', [
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]));
|
||||
}
|
||||
|
||||
return $server;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace Pterodactyl\Services\Servers;
|
|||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use Illuminate\Log\Writer;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
|
@ -48,21 +49,29 @@ class DetailsModificationService
|
|||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Log\Writer
|
||||
*/
|
||||
protected $writer;
|
||||
|
||||
/**
|
||||
* DetailsModificationService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\DatabaseManager $database
|
||||
* @param \Pterodactyl\Repositories\Daemon\ServerRepository $daemonServerRepository
|
||||
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
|
||||
* @param \Illuminate\Log\Writer $writer
|
||||
*/
|
||||
public function __construct(
|
||||
DatabaseManager $database,
|
||||
DaemonServerRepository $daemonServerRepository,
|
||||
ServerRepository $repository
|
||||
ServerRepository $repository,
|
||||
Writer $writer
|
||||
) {
|
||||
$this->database = $database;
|
||||
$this->daemonServerRepository = $daemonServerRepository;
|
||||
$this->repository = $repository;
|
||||
$this->writer = $writer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,8 +123,11 @@ class DetailsModificationService
|
|||
|
||||
return $this->database->commit();
|
||||
} catch (RequestException $exception) {
|
||||
$response = $exception->getResponse();
|
||||
$this->writer->warning($exception);
|
||||
|
||||
throw new DisplayException(trans('admin/server.exceptions.daemon_exception', [
|
||||
'code' => $exception->getResponse()->getStatusCode(),
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +137,6 @@ class DetailsModificationService
|
|||
*
|
||||
* @param int|\Pterodactyl\Models\Server $server
|
||||
* @param string $image
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
|
@ -148,8 +159,11 @@ class DetailsModificationService
|
|||
|
||||
$this->database->commit();
|
||||
} catch (RequestException $exception) {
|
||||
$response = $exception->getResponse();
|
||||
$this->writer->warning($exception);
|
||||
|
||||
throw new DisplayException(trans('admin/server.exceptions.daemon_exception', [
|
||||
'code' => $exception->getResponse()->getStatusCode(),
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
namespace Pterodactyl\Services\Servers;
|
||||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Log\Writer;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
|
@ -48,21 +49,29 @@ class ReinstallService
|
|||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Log\Writer
|
||||
*/
|
||||
protected $writer;
|
||||
|
||||
/**
|
||||
* ReinstallService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $database
|
||||
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonServerRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
||||
* @param \Illuminate\Log\Writer $writer
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $database,
|
||||
DaemonServerRepositoryInterface $daemonServerRepository,
|
||||
ServerRepositoryInterface $repository
|
||||
ServerRepositoryInterface $repository,
|
||||
Writer $writer
|
||||
) {
|
||||
$this->daemonServerRepository = $daemonServerRepository;
|
||||
$this->database = $database;
|
||||
$this->repository = $repository;
|
||||
$this->writer = $writer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,8 +95,11 @@ class ReinstallService
|
|||
$this->daemonServerRepository->setNode($server->node_id)->setAccessServer($server->uuid)->reinstall();
|
||||
$this->database->commit();
|
||||
} catch (RequestException $exception) {
|
||||
$response = $exception->getResponse();
|
||||
$this->writer->warning($exception);
|
||||
|
||||
throw new DisplayException(trans('admin/server.exceptions.daemon_exception', [
|
||||
'code' => $exception->getResponse()->getStatusCode(),
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace Pterodactyl\Services\Servers;
|
|||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Log\Writer;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
@ -48,21 +49,29 @@ class SuspensionService
|
|||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Log\Writer
|
||||
*/
|
||||
protected $writer;
|
||||
|
||||
/**
|
||||
* SuspensionService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $database
|
||||
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonServerRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
||||
* @param \Illuminate\Log\Writer $writer
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $database,
|
||||
DaemonServerRepositoryInterface $daemonServerRepository,
|
||||
ServerRepositoryInterface $repository
|
||||
ServerRepositoryInterface $repository,
|
||||
Writer $writer
|
||||
) {
|
||||
$this->daemonServerRepository = $daemonServerRepository;
|
||||
$this->database = $database;
|
||||
$this->repository = $repository;
|
||||
$this->writer = $writer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,8 +115,11 @@ class SuspensionService
|
|||
|
||||
return true;
|
||||
} catch (RequestException $exception) {
|
||||
$response = $exception->getResponse();
|
||||
$this->writer->warning($exception);
|
||||
|
||||
throw new DisplayException(trans('admin/server.exceptions.daemon_exception', [
|
||||
'code' => $exception->getResponse()->getStatusCode(),
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue