2026-10-05 18:10:18 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Pterodactyl\Actions\Locations;
|
|
|
|
|
|
2026-10-09 06:26:45 +01:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2026-10-11 23:41:04 -04:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Contracts\Locations\UpdatesLocations;
|
|
|
|
|
use Pterodactyl\Models\Location;
|
2026-10-09 06:26:45 +01:00
|
|
|
use Pterodactyl\Services\Extensions\ExtensionFields;
|
|
|
|
|
use Pterodactyl\Services\Extensions\ValidatedExtensionValues;
|
2026-10-05 18:10:18 -04:00
|
|
|
|
2026-10-09 06:26:45 +01:00
|
|
|
final readonly class UpdateLocation implements UpdatesLocations
|
2026-10-05 18:10:18 -04:00
|
|
|
{
|
2026-10-09 06:26:45 +01:00
|
|
|
public function __construct(private ExtensionFields $extensions) {}
|
|
|
|
|
|
2026-10-11 06:17:07 -04:00
|
|
|
public function update(Location $location, array $input): Location
|
2026-10-05 18:10:18 -04:00
|
|
|
{
|
2026-10-11 23:41:04 -04:00
|
|
|
$validated = Validator::validate($input, CreateLocation::rules($location));
|
2026-10-11 06:17:07 -04:00
|
|
|
$extensions = ValidatedExtensionValues::of($input['extensions'] ?? null);
|
2026-10-09 06:26:45 +01:00
|
|
|
|
2026-10-11 23:41:04 -04:00
|
|
|
DB::transaction(function () use ($location, $validated, $extensions): void {
|
|
|
|
|
// A location given no long name, or a blank one, has none.
|
|
|
|
|
$location->update([...$validated, 'long' => filled($validated['long'] ?? null) ? $validated['long'] : null]);
|
2026-10-09 06:26:45 +01:00
|
|
|
$this->extensions->save($location, $extensions);
|
|
|
|
|
});
|
2026-10-05 18:10:18 -04:00
|
|
|
|
|
|
|
|
return $location;
|
|
|
|
|
}
|
|
|
|
|
}
|