Don't require Wings API call to pass in order to update server details

This commit is contained in:
Dane Everitt 2021-08-29 13:19:24 -07:00
parent 7330a747b7
commit d8d1eacb42
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -33,6 +33,8 @@ class BuildModificationService
* BuildModificationService constructor. * BuildModificationService constructor.
* *
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $structureService * @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $structureService
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
*/ */
public function __construct( public function __construct(
ServerConfigurationStructureService $structureService, ServerConfigurationStructureService $structureService,
@ -56,34 +58,37 @@ class BuildModificationService
{ {
$this->connection->beginTransaction(); $this->connection->beginTransaction();
$this->processAllocations($server, $data); /** @var \Pterodactyl\Models\Server $server */
$server = $this->connection->transaction(function() use ($server, $data) {
$this->processAllocations($server, $data);
if (isset($data['allocation_id']) && $data['allocation_id'] != $server->allocation_id) { if (isset($data['allocation_id']) && $data['allocation_id'] != $server->allocation_id) {
try { try {
Allocation::query()->where('id', $data['allocation_id'])->where('server_id', $server->id)->firstOrFail(); Allocation::query()->where('id', $data['allocation_id'])->where('server_id', $server->id)->firstOrFail();
} catch (ModelNotFoundException $ex) { } catch (ModelNotFoundException $ex) {
throw new DisplayException('The requested default allocation is not currently assigned to this server.'); throw new DisplayException('The requested default allocation is not currently assigned to this server.');
}
} }
}
// If any of these values are passed through in the data array go ahead and set // If any of these values are passed through in the data array go ahead and set
// them correctly on the server model. // them correctly on the server model.
$merge = Arr::only($data, ['oom_disabled', 'memory', 'swap', 'io', 'cpu', 'threads', 'disk', 'allocation_id']); $merge = Arr::only($data, ['oom_disabled', 'memory', 'swap', 'io', 'cpu', 'threads', 'disk', 'allocation_id']);
$server->forceFill(array_merge($merge, [ $server->forceFill(array_merge($merge, [
'database_limit' => Arr::get($data, 'database_limit', 0) ?? null, 'database_limit' => Arr::get($data, 'database_limit', 0) ?? null,
'allocation_limit' => Arr::get($data, 'allocation_limit', 0) ?? null, 'allocation_limit' => Arr::get($data, 'allocation_limit', 0) ?? null,
'backup_limit' => Arr::get($data, 'backup_limit', 0) ?? 0, 'backup_limit' => Arr::get($data, 'backup_limit', 0) ?? 0,
]))->saveOrFail(); ]))->saveOrFail();
$server = $server->fresh(); return $server->refresh();
});
$updateData = $this->structureService->handle($server); $updateData = $this->structureService->handle($server);
// Because Wings always fetches an updated configuration from the Panel when booting // Because Wings always fetches an updated configuration from the Panel when booting
// a server this type of exception can be safely "ignored" and just written to the logs. // a server this type of exception can be safely "ignored" and just written to the logs.
// Ideally this request succeedes so we can apply resource modifications on the fly // Ideally this request succeedes so we can apply resource modifications on the fly, but
// but if it fails it isn't the end of the world. // if it fails we can just continue on as normal.
if (!empty($updateData['build'])) { if (!empty($updateData['build'])) {
try { try {
$this->daemonServerRepository->setServer($server)->update([ $this->daemonServerRepository->setServer($server)->update([
@ -94,8 +99,6 @@ class BuildModificationService
} }
} }
$this->connection->commit();
return $server; return $server;
} }