From a03add7e4f355e33439f082c28b611792a2e10da Mon Sep 17 00:00:00 2001 From: Emmet Young Date: Thu, 1 Dec 2016 03:01:22 +1100 Subject: [PATCH] Allow API to set a custom ID for server creation. (#187) * Allow API to set a custom ID for server creation. Useful when dealing with billing systems such as WHMCS * Correct API code changes based on feedback. --- app/Repositories/ServerRepository.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index 47b1a4a97..19b4abd05 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -88,7 +88,8 @@ class ServerRepository 'option' => 'bail|required|numeric|min:1|exists:service_options,id', 'startup' => 'string', 'custom_image_name' => 'required_if:use_custom_image,on', - 'auto_deploy' => 'sometimes|boolean' + 'auto_deploy' => 'sometimes|boolean', + 'custom_id' => 'sometimes|required|numeric|unique:servers,id', ]); $validator->sometimes('node', 'bail|required|numeric|min:1|exists:nodes,id', function ($input) { @@ -232,6 +233,11 @@ class ServerRepository $server = new Models\Server; $genUuid = $uuid->generate('servers', 'uuid'); $genShortUuid = $uuid->generateShort('servers', 'uuidShort', $genUuid); + + if (isset($data['custom_id'])) { + $server->id = $data['custom_id']; + } + $server->fill([ 'uuid' => $genUuid, 'uuidShort' => $genShortUuid, @@ -994,4 +1000,4 @@ class ServerRepository } -} +} \ No newline at end of file