More API updates, better support for node config edits
This commit is contained in:
parent
800e2df6b2
commit
cf21fd5a4b
21 changed files with 449 additions and 125 deletions
43
app/Services/Allocations/AllocationDeletionService.php
Normal file
43
app/Services/Allocations/AllocationDeletionService.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Services\Allocations;
|
||||
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException;
|
||||
|
||||
class AllocationDeletionService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* AllocationDeletionService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(AllocationRepositoryInterface $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an allocation from the database only if it does not have a server
|
||||
* that is actively attached to it.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Allocation $allocation
|
||||
* @return int
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
|
||||
*/
|
||||
public function handle(Allocation $allocation)
|
||||
{
|
||||
if (! is_null($allocation->server_id)) {
|
||||
throw new ServerUsingAllocationException(trans('exceptions.allocations.server_using'));
|
||||
}
|
||||
|
||||
return $this->repository->delete($allocation->id);
|
||||
}
|
||||
}
|
|
@ -10,16 +10,24 @@
|
|||
namespace Pterodactyl\Services\Nodes;
|
||||
|
||||
use Pterodactyl\Models\Node;
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Traits\Services\ReturnsUpdatedModels;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||
use Pterodactyl\Exceptions\Service\Node\ConfigurationNotPersistedException;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\ConfigurationRepositoryInterface;
|
||||
|
||||
class NodeUpdateService
|
||||
{
|
||||
use ReturnsUpdatedModels;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\Daemon\ConfigurationRepositoryInterface
|
||||
*/
|
||||
|
@ -33,13 +41,16 @@ class NodeUpdateService
|
|||
/**
|
||||
* UpdateService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Pterodactyl\Contracts\Repository\Daemon\ConfigurationRepositoryInterface $configurationRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $connection,
|
||||
ConfigurationRepositoryInterface $configurationRepository,
|
||||
NodeRepositoryInterface $repository
|
||||
) {
|
||||
$this->connection = $connection;
|
||||
$this->configRepository = $configurationRepository;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
@ -62,6 +73,7 @@ class NodeUpdateService
|
|||
unset($data['reset_secret']);
|
||||
}
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
if ($this->getUpdatedModel()) {
|
||||
$response = $this->repository->update($node->id, $data);
|
||||
} else {
|
||||
|
@ -70,7 +82,16 @@ class NodeUpdateService
|
|||
|
||||
try {
|
||||
$this->configRepository->setNode($node)->update();
|
||||
$this->connection->commit();
|
||||
} catch (RequestException $exception) {
|
||||
// Failed to connect to the Daemon. Let's go ahead and save the configuration
|
||||
// and let the user know they'll need to manually update.
|
||||
if ($exception instanceof ConnectException) {
|
||||
$this->connection->commit();
|
||||
|
||||
throw new ConfigurationNotPersistedException(trans('exceptions.node.daemon_off_config_updated'));
|
||||
}
|
||||
|
||||
throw new DaemonConnectionException($exception);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue