2017-07-22 20:15:01 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Servers;
|
|
|
|
|
|
2020-12-06 12:16:12 -08:00
|
|
|
use Illuminate\Support\Arr;
|
2017-07-22 20:15:01 -05:00
|
|
|
use Pterodactyl\Models\Server;
|
2026-02-14 10:51:26 -08:00
|
|
|
use Pterodactyl\Jobs\RevokeSftpAccessJob;
|
2017-09-24 21:12:30 -05:00
|
|
|
use Illuminate\Database\ConnectionInterface;
|
2018-01-20 16:03:23 -06:00
|
|
|
use Pterodactyl\Traits\Services\ReturnsUpdatedModels;
|
2020-12-06 12:16:12 -08:00
|
|
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
2025-12-26 17:51:25 -08:00
|
|
|
use Pterodactyl\Repositories\Wings\DaemonRevocationRepository;
|
2017-07-22 20:15:01 -05:00
|
|
|
|
|
|
|
|
class DetailsModificationService
|
|
|
|
|
{
|
2018-01-20 16:03:23 -06:00
|
|
|
use ReturnsUpdatedModels;
|
2017-07-22 20:15:01 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* DetailsModificationService constructor.
|
|
|
|
|
*/
|
2025-12-26 17:51:25 -08:00
|
|
|
public function __construct(
|
|
|
|
|
private ConnectionInterface $connection,
|
|
|
|
|
private DaemonServerRepository $serverRepository,
|
|
|
|
|
private DaemonRevocationRepository $revocationRepository,
|
|
|
|
|
) {
|
2017-07-22 20:15:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the details for a single server instance.
|
|
|
|
|
*
|
2020-12-06 12:16:12 -08:00
|
|
|
* @throws \Throwable
|
2017-07-22 20:15:01 -05:00
|
|
|
*/
|
2020-12-06 12:16:12 -08:00
|
|
|
public function handle(Server $server, array $data): Server
|
2017-07-22 20:15:01 -05:00
|
|
|
{
|
2020-12-06 12:16:12 -08:00
|
|
|
return $this->connection->transaction(function () use ($data, $server) {
|
2025-12-26 17:51:25 -08:00
|
|
|
$original = $server->user;
|
2018-01-20 16:03:23 -06:00
|
|
|
|
2020-12-06 12:16:12 -08:00
|
|
|
$server->forceFill([
|
|
|
|
|
'external_id' => Arr::get($data, 'external_id'),
|
|
|
|
|
'owner_id' => Arr::get($data, 'owner_id'),
|
|
|
|
|
'name' => Arr::get($data, 'name'),
|
|
|
|
|
'description' => Arr::get($data, 'description') ?? '',
|
|
|
|
|
])->saveOrFail();
|
2017-07-22 20:15:01 -05:00
|
|
|
|
2020-12-06 12:16:12 -08:00
|
|
|
// If the owner_id value is changed we need to revoke any tokens that exist for the server
|
|
|
|
|
// on the Wings instance so that the old owner no longer has any permission to access the
|
|
|
|
|
// websockets.
|
2025-12-26 17:51:25 -08:00
|
|
|
if (! $server->refresh()->user->is($original)) {
|
2026-02-14 10:51:26 -08:00
|
|
|
RevokeSftpAccessJob::dispatch($original->uuid, $server);
|
2020-12-06 12:16:12 -08:00
|
|
|
}
|
2017-07-22 20:15:01 -05:00
|
|
|
|
2020-12-06 12:16:12 -08:00
|
|
|
return $server;
|
|
|
|
|
});
|
2017-07-22 20:15:01 -05:00
|
|
|
}
|
|
|
|
|
}
|