More tests
This commit is contained in:
parent
fd24729ab9
commit
6d1b994b7d
11 changed files with 626 additions and 64 deletions
|
@ -196,6 +196,7 @@ class CreationService
|
|||
} catch (RequestException $exception) {
|
||||
$response = $exception->getResponse();
|
||||
$this->writer->warning($exception);
|
||||
$this->database->rollBack();
|
||||
|
||||
throw new DisplayException(trans('admin/server.exceptions.daemon_exception', [
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
|
|
|
@ -36,16 +36,16 @@ use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonS
|
|||
|
||||
class DeletionService
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface
|
||||
*/
|
||||
protected $daemonServerRepository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Database\DatabaseManagementService
|
||||
*/
|
||||
|
@ -74,7 +74,7 @@ class DeletionService
|
|||
/**
|
||||
* DeletionService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $database
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonServerRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $databaseRepository
|
||||
* @param \Pterodactyl\Services\Database\DatabaseManagementService $databaseManagementService
|
||||
|
@ -82,7 +82,7 @@ class DeletionService
|
|||
* @param \Illuminate\Log\Writer $writer
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $database,
|
||||
ConnectionInterface $connection,
|
||||
DaemonServerRepositoryInterface $daemonServerRepository,
|
||||
DatabaseRepositoryInterface $databaseRepository,
|
||||
DatabaseManagementService $databaseManagementService,
|
||||
|
@ -90,7 +90,7 @@ class DeletionService
|
|||
Writer $writer
|
||||
) {
|
||||
$this->daemonServerRepository = $daemonServerRepository;
|
||||
$this->database = $database;
|
||||
$this->connection = $connection;
|
||||
$this->databaseManagementService = $databaseManagementService;
|
||||
$this->databaseRepository = $databaseRepository;
|
||||
$this->repository = $repository;
|
||||
|
@ -114,7 +114,9 @@ class DeletionService
|
|||
* Delete a server from the panel and remove any associated databases from hosts.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\Server $server
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function handle($server)
|
||||
{
|
||||
|
@ -140,12 +142,12 @@ class DeletionService
|
|||
}
|
||||
}
|
||||
|
||||
$this->database->beginTransaction();
|
||||
$this->connection->beginTransaction();
|
||||
$this->databaseRepository->withColumns('id')->findWhere([['server_id', '=', $server->id]])->each(function ($item) {
|
||||
$this->databaseManagementService->delete($item->id);
|
||||
});
|
||||
|
||||
$this->repository->delete($server->id);
|
||||
$this->database->commit();
|
||||
$this->connection->commit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,6 +125,7 @@ class StartupModificationService
|
|||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function handle($server, array $data)
|
||||
{
|
||||
|
|
|
@ -53,8 +53,8 @@ class VariableCreationService
|
|||
/**
|
||||
* Create a new variable for a given service option.
|
||||
*
|
||||
* @param int $option
|
||||
* @param array $data
|
||||
* @param int|\Pterodactyl\Models\ServiceOption $option
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\ServiceVariable
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
|
@ -67,7 +67,9 @@ class VariableCreationService
|
|||
}
|
||||
|
||||
if (in_array(strtoupper(array_get($data, 'env_variable')), explode(',', ServiceVariable::RESERVED_ENV_NAMES))) {
|
||||
throw new ReservedVariableNameException(sprintf('Cannot use the protected name %s for this environment variable.'));
|
||||
throw new ReservedVariableNameException(sprintf(
|
||||
'Cannot use the protected name %s for this environment variable.', array_get($data, 'env_variable')
|
||||
));
|
||||
}
|
||||
|
||||
$options = array_get($data, 'options', []);
|
||||
|
|
|
@ -34,11 +34,16 @@ class VariableUpdateService
|
|||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface
|
||||
*/
|
||||
protected $serviceVariableRepository;
|
||||
protected $repository;
|
||||
|
||||
public function __construct(ServiceVariableRepositoryInterface $serviceVariableRepository)
|
||||
/**
|
||||
* VariableUpdateService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(ServiceVariableRepositoryInterface $repository)
|
||||
{
|
||||
$this->serviceVariableRepository = $serviceVariableRepository;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,16 +51,17 @@ class VariableUpdateService
|
|||
*
|
||||
* @param int|\Pterodactyl\Models\ServiceVariable $variable
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\ServiceVariable
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Services\ServiceVariable\ReservedVariableNameException
|
||||
*/
|
||||
public function handle($variable, array $data)
|
||||
{
|
||||
if (! $variable instanceof ServiceVariable) {
|
||||
$variable = $this->serviceVariableRepository->find($variable);
|
||||
$variable = $this->repository->find($variable);
|
||||
}
|
||||
|
||||
if (! is_null(array_get($data, 'env_variable'))) {
|
||||
|
@ -65,7 +71,7 @@ class VariableUpdateService
|
|||
]));
|
||||
}
|
||||
|
||||
$search = $this->serviceVariableRepository->withColumns('id')->findCountWhere([
|
||||
$search = $this->repository->withColumns('id')->findCountWhere([
|
||||
['env_variable', '=', array_get($data, 'env_variable')],
|
||||
['option_id', '=', $variable->option_id],
|
||||
['id', '!=', $variable->id],
|
||||
|
@ -80,9 +86,9 @@ class VariableUpdateService
|
|||
|
||||
$options = array_get($data, 'options', []);
|
||||
|
||||
return $this->serviceVariableRepository->update($variable->id, array_merge([
|
||||
'user_viewable' => in_array('user_viewable', $options, $variable->user_viewable),
|
||||
'user_editable' => in_array('user_editable', $options, $variable->user_editable),
|
||||
return $this->repository->withoutFresh()->update($variable->id, array_merge([
|
||||
'user_viewable' => in_array('user_viewable', $options),
|
||||
'user_editable' => in_array('user_editable', $options),
|
||||
], $data));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue