Fill startup & image from egg if missing in request (#384)
This commit is contained in:
		
							parent
							
								
									0da184c56e
								
							
						
					
					
						commit
						6916b89638
					
				| @ -28,8 +28,8 @@ class StoreServerRequest extends ApplicationApiRequest | |||||||
|             'description' => array_merge(['nullable'], $rules['description']), |             'description' => array_merge(['nullable'], $rules['description']), | ||||||
|             'user' => $rules['owner_id'], |             'user' => $rules['owner_id'], | ||||||
|             'egg' => $rules['egg_id'], |             'egg' => $rules['egg_id'], | ||||||
|             'docker_image' => $rules['image'], |             'docker_image' => 'sometimes|string', | ||||||
|             'startup' => $rules['startup'], |             'startup' => 'sometimes|string', | ||||||
|             'environment' => 'present|array', |             'environment' => 'present|array', | ||||||
|             'skip_scripts' => 'sometimes|boolean', |             'skip_scripts' => 'sometimes|boolean', | ||||||
|             'oom_killer' => 'sometimes|boolean', |             'oom_killer' => 'sometimes|boolean', | ||||||
|  | |||||||
| @ -20,10 +20,10 @@ class UpdateServerStartupRequest extends ApplicationApiRequest | |||||||
|         $data = Server::getRulesForUpdate($this->parameter('server', Server::class)); |         $data = Server::getRulesForUpdate($this->parameter('server', Server::class)); | ||||||
| 
 | 
 | ||||||
|         return [ |         return [ | ||||||
|             'startup' => $data['startup'], |             'startup' => 'sometimes|string', | ||||||
|             'environment' => 'present|array', |             'environment' => 'present|array', | ||||||
|             'egg' => $data['egg_id'], |             'egg' => $data['egg_id'], | ||||||
|             'image' => $data['image'], |             'image' => 'sometimes|string', | ||||||
|             'skip_scripts' => 'present|boolean', |             'skip_scripts' => 'present|boolean', | ||||||
|         ]; |         ]; | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -17,6 +17,7 @@ use App\Repositories\Daemon\DaemonServerRepository; | |||||||
| use App\Services\Deployment\FindViableNodesService; | use App\Services\Deployment\FindViableNodesService; | ||||||
| use App\Services\Deployment\AllocationSelectionService; | use App\Services\Deployment\AllocationSelectionService; | ||||||
| use App\Exceptions\Http\Connection\DaemonConnectionException; | use App\Exceptions\Http\Connection\DaemonConnectionException; | ||||||
|  | use App\Models\Egg; | ||||||
| 
 | 
 | ||||||
| class ServerCreationService | class ServerCreationService | ||||||
| { | { | ||||||
| @ -50,6 +51,13 @@ class ServerCreationService | |||||||
|             $data['oom_killer'] = !$data['oom_disabled']; |             $data['oom_killer'] = !$data['oom_disabled']; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         /** @var Egg $egg */ | ||||||
|  |         $egg = Egg::query()->findOrFail($data['egg_id']); | ||||||
|  | 
 | ||||||
|  |         // Fill missing fields from egg
 | ||||||
|  |         $data['image'] = $data['image'] ?? collect($egg->docker_images)->first(); | ||||||
|  |         $data['startup'] = $data['startup'] ?? $egg->startup; | ||||||
|  | 
 | ||||||
|         // If a deployment object has been passed we need to get the allocation
 |         // If a deployment object has been passed we need to get the allocation
 | ||||||
|         // that the server should use, and assign the node from that allocation.
 |         // that the server should use, and assign the node from that allocation.
 | ||||||
|         if ($deployment instanceof DeploymentObject) { |         if ($deployment instanceof DeploymentObject) { | ||||||
|  | |||||||
| @ -76,6 +76,10 @@ class StartupModificationService | |||||||
|             $server = $server->forceFill([ |             $server = $server->forceFill([ | ||||||
|                 'egg_id' => $egg->id, |                 'egg_id' => $egg->id, | ||||||
|             ]); |             ]); | ||||||
|  | 
 | ||||||
|  |             // Fill missing fields from egg
 | ||||||
|  |             $data['docker_image'] = $data['docker_image'] ?? collect($egg->docker_images)->first(); | ||||||
|  |             $data['startup'] = $data['startup'] ?? $egg->startup; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         $server->fill([ |         $server->fill([ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Boy132
						Boy132