Don't require Wings API call to pass in order to update server details
This commit is contained in:
		
							parent
							
								
									7330a747b7
								
							
						
					
					
						commit
						d8d1eacb42
					
				| @ -33,6 +33,8 @@ class BuildModificationService | ||||
|      * BuildModificationService constructor. | ||||
|      * | ||||
|      * @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $structureService | ||||
|      * @param \Illuminate\Database\ConnectionInterface $connection | ||||
|      * @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository | ||||
|      */ | ||||
|     public function __construct( | ||||
|         ServerConfigurationStructureService $structureService, | ||||
| @ -56,34 +58,37 @@ class BuildModificationService | ||||
|     { | ||||
|         $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) { | ||||
|             try { | ||||
|                 Allocation::query()->where('id', $data['allocation_id'])->where('server_id', $server->id)->firstOrFail(); | ||||
|             } catch (ModelNotFoundException $ex) { | ||||
|                 throw new DisplayException('The requested default allocation is not currently assigned to this server.'); | ||||
|             if (isset($data['allocation_id']) && $data['allocation_id'] != $server->allocation_id) { | ||||
|                 try { | ||||
|                     Allocation::query()->where('id', $data['allocation_id'])->where('server_id', $server->id)->firstOrFail(); | ||||
|                 } catch (ModelNotFoundException $ex) { | ||||
|                     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
 | ||||
|         // them correctly on the server model.
 | ||||
|         $merge = Arr::only($data, ['oom_disabled', 'memory', 'swap', 'io', 'cpu', 'threads', 'disk', 'allocation_id']); | ||||
|             // If any of these values are passed through in the data array go ahead and set
 | ||||
|             // them correctly on the server model.
 | ||||
|             $merge = Arr::only($data, ['oom_disabled', 'memory', 'swap', 'io', 'cpu', 'threads', 'disk', 'allocation_id']); | ||||
| 
 | ||||
|         $server->forceFill(array_merge($merge, [ | ||||
|             'database_limit' => Arr::get($data, 'database_limit', 0) ?? null, | ||||
|             'allocation_limit' => Arr::get($data, 'allocation_limit', 0) ?? null, | ||||
|             'backup_limit' => Arr::get($data, 'backup_limit', 0) ?? 0, | ||||
|         ]))->saveOrFail(); | ||||
|             $server->forceFill(array_merge($merge, [ | ||||
|                 'database_limit' => Arr::get($data, 'database_limit', 0) ?? null, | ||||
|                 'allocation_limit' => Arr::get($data, 'allocation_limit', 0) ?? null, | ||||
|                 'backup_limit' => Arr::get($data, 'backup_limit', 0) ?? 0, | ||||
|             ]))->saveOrFail(); | ||||
| 
 | ||||
|         $server = $server->fresh(); | ||||
|             return $server->refresh(); | ||||
|         }); | ||||
| 
 | ||||
|         $updateData = $this->structureService->handle($server); | ||||
| 
 | ||||
|         // 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.
 | ||||
|         // Ideally this request succeedes so we can apply resource modifications on the fly
 | ||||
|         // but if it fails it isn't the end of the world.
 | ||||
|         // Ideally this request succeedes so we can apply resource modifications on the fly, but
 | ||||
|         // if it fails we can just continue on as normal.
 | ||||
|         if (!empty($updateData['build'])) { | ||||
|             try { | ||||
|                 $this->daemonServerRepository->setServer($server)->update([ | ||||
| @ -94,8 +99,6 @@ class BuildModificationService | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         $this->connection->commit(); | ||||
| 
 | ||||
|         return $server; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dane Everitt
						Dane Everitt