api(application): v2 backport
This commit is contained in:
parent
4cd0bee231
commit
67bf3e342e
172 changed files with 2922 additions and 1579 deletions
|
@ -3,6 +3,7 @@
|
|||
namespace Pterodactyl\Services\Eggs\Variables;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\EggVariable;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Traits\Services\ValidatesValidationRules;
|
||||
|
@ -34,24 +35,21 @@ class VariableUpdateService
|
|||
* Update a specific egg variable.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException
|
||||
*/
|
||||
public function handle(EggVariable $variable, array $data): mixed
|
||||
public function handle(Egg $egg, array $data): void
|
||||
{
|
||||
if (!is_null(array_get($data, 'env_variable'))) {
|
||||
if (in_array(strtoupper(array_get($data, 'env_variable')), explode(',', EggVariable::RESERVED_ENV_NAMES))) {
|
||||
throw new ReservedVariableNameException(trans('exceptions.service.variables.reserved_name', ['name' => array_get($data, 'env_variable')]));
|
||||
}
|
||||
|
||||
$search = $this->repository->setColumns('id')->findCountWhere([
|
||||
['env_variable', '=', $data['env_variable']],
|
||||
['egg_id', '=', $variable->egg_id],
|
||||
['id', '!=', $variable->id],
|
||||
]);
|
||||
$count = $egg->variables()
|
||||
->where('egg_variables.env_variable', $data['env_variable'])
|
||||
->where('egg_variables.id', '!=', $data['id'])
|
||||
->count();
|
||||
|
||||
if ($search > 0) {
|
||||
if ($count > 0) {
|
||||
throw new DisplayException(trans('exceptions.service.variables.env_not_unique', ['name' => array_get($data, 'env_variable')]));
|
||||
}
|
||||
}
|
||||
|
@ -66,13 +64,13 @@ class VariableUpdateService
|
|||
|
||||
$options = array_get($data, 'options') ?? [];
|
||||
|
||||
return $this->repository->withoutFreshModel()->update($variable->id, [
|
||||
$egg->variables()->where('egg_variables.id', $data['id'])->update([
|
||||
'name' => $data['name'] ?? '',
|
||||
'description' => $data['description'] ?? '',
|
||||
'env_variable' => $data['env_variable'] ?? '',
|
||||
'default_value' => $data['default_value'] ?? '',
|
||||
'user_viewable' => in_array('user_viewable', $options),
|
||||
'user_editable' => in_array('user_editable', $options),
|
||||
'user_viewable' => $data['user_viewable'],
|
||||
'user_editable' => $data['user_editable'],
|
||||
'rules' => $data['rules'] ?? '',
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue