2026-10-05 18:10:18 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Requests\Api\Admin\Servers;
|
|
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
|
use Illuminate\Validation\Validator;
|
2026-10-11 09:37:29 -04:00
|
|
|
use Pterodactyl\Actions\Transfers\InitiateTransfer;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Enum\Permissions;
|
|
|
|
|
use Pterodactyl\Models\Allocation;
|
|
|
|
|
use Pterodactyl\Models\Server;
|
2026-10-11 10:00:29 -04:00
|
|
|
use Pterodactyl\Validation\Concerns\ValidatesArrayExistence;
|
2026-10-05 18:10:18 -04:00
|
|
|
|
|
|
|
|
class TransferServerRequest extends ServerWriteRequest
|
|
|
|
|
{
|
|
|
|
|
use ValidatesArrayExistence;
|
|
|
|
|
|
|
|
|
|
public function permissions(): array
|
|
|
|
|
{
|
|
|
|
|
return [Permissions::AdminServersUpdate];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validation rules for transferring a server to another node.
|
|
|
|
|
*
|
|
|
|
|
* @return ValidationRules
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
2026-10-11 09:37:29 -04:00
|
|
|
return InitiateTransfer::rules($this->parameter('server', Server::class));
|
2026-10-05 18:10:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-10-11 09:37:29 -04:00
|
|
|
* Chosen allocations must exist, belong to the target node and be unassigned.
|
2026-10-05 18:10:18 -04:00
|
|
|
*
|
|
|
|
|
* @return list<Closure(Validator): void>
|
|
|
|
|
*/
|
|
|
|
|
public function after(): array
|
|
|
|
|
{
|
|
|
|
|
return [function (Validator $validator): void {
|
|
|
|
|
$this->validateArrayExistence($validator, 'allocation_additional', Allocation::query());
|
2026-10-11 09:37:29 -04:00
|
|
|
InitiateTransfer::validateAllocations($validator);
|
2026-10-05 18:10:18 -04:00
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-10-11 09:37:29 -04:00
|
|
|
* The validated additional allocation ids, as integers.
|
2026-10-05 18:10:18 -04:00
|
|
|
*
|
2026-10-11 09:37:29 -04:00
|
|
|
* @return list<int>
|
2026-10-05 18:10:18 -04:00
|
|
|
*/
|
2026-10-11 09:37:29 -04:00
|
|
|
public function additionalAllocations(): array
|
2026-10-05 18:10:18 -04:00
|
|
|
{
|
2026-10-11 09:37:29 -04:00
|
|
|
$validated = $this->safe();
|
2026-10-05 18:10:18 -04:00
|
|
|
|
2026-10-11 09:37:29 -04:00
|
|
|
return array_map(fn (int|string $key): int => $validated->integer('allocation_additional.'.$key), array_keys($validated->array('allocation_additional')));
|
2026-10-05 18:10:18 -04:00
|
|
|
}
|
|
|
|
|
}
|