egg_id !== $eggId) { // Only administrators may move a server to another egg. Values the // new egg still accepts are kept, and anything submitted below // replaces the defaults the move resets. $server = $this->eggs->change($server, Egg::query()->findOrFail($eggId), keepVariables: true); } if (! empty($data['environment'])) { $egg = $server->relationLoaded('egg') && $server->egg instanceof Egg ? $server->egg : Egg::query()->findOrFail($server->egg_id); $results = $this->validatorService->setUserLevel($userLevel)->handle($egg, $data['environment']); foreach ($results as $result) { ServerVariable::query()->updateOrCreate( ['server_id' => $server->id, 'variable_id' => $result->id], ['variable_value' => $result->value ?? ''] ); } } if ($userLevel === User::USER_LEVEL_ADMIN) { $server->fill([ 'startup' => $data['startup'] ?? $server->startup, 'skip_scripts' => $data['skip_scripts'] ?? isset($data['skip_scripts']), 'image' => $data['docker_image'] ?? $server->image, ])->save(); } // Calling ->refresh() rather than ->fresh() here causes the // variables as triplicates for some reason. Not entirely sure why, // but this operation test covers the behavior and keeps it stable. $fresh = $server->fresh(); throw_if($fresh === null, LogicException::class, 'The modified server no longer exists.'); return $fresh; }); } }