diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index 310af7b97..c15a4a658 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -168,7 +168,9 @@ class ServersController extends Controller try { $server = new ServerRepository; - $response = $server->create($request->all()); + $response = $server->create($request->except([ + '_token' + ])); return redirect()->route('admin.servers.view', [ 'id' => $response ]); } catch (DisplayValidationException $ex) { return redirect()->route('admin.servers.new')->withErrors(json_decode($ex->getMessage()))->withInput(); diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index 47b1a4a97..5d25f0e68 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -86,6 +86,7 @@ class ServerRepository 'disk' => 'required|numeric|min:0', 'service' => 'bail|required|numeric|min:1|exists:services,id', 'option' => 'bail|required|numeric|min:1|exists:service_options,id', + 'pack' => 'bail|required|numeric|min:0' 'startup' => 'string', 'custom_image_name' => 'required_if:use_custom_image,on', 'auto_deploy' => 'sometimes|boolean' @@ -161,6 +162,18 @@ class ServerRepository throw new DisplayException('The requested service option does not exist for the specified service.'); } + // Validate the Pack + if ($data['pack'] === 0) { + $data['pack'] = null; + } + + if (!is_null($data['pack'])) { + $pack = Models\ServicePack::where('id', $data['pack'])->where('option', $data['option'])->first(); + if (!$pack) { + throw new DisplayException('The requested service pack does not seem to exist for this combination.'); + } + } + // Load up the Service Information $service = Models\Service::find($option->parent_service); @@ -248,6 +261,7 @@ class ServerRepository 'allocation' => $allocation->id, 'service' => $data['service'], 'option' => $data['option'], + 'pack' => $data['pack'], 'startup' => $data['startup'], 'daemonSecret' => $uuid->generate('servers', 'daemonSecret'), 'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image, @@ -297,10 +311,10 @@ class ServerRepository 'build' => [ 'default' => [ 'ip' => $allocation->ip, - 'port' => (int) $allocation->port + 'port' => (int) $allocation->port, ], 'ports' => [ - (string) $allocation->ip => [ (int) $allocation->port ] + (string) $allocation->ip => [ (int) $allocation->port ], ], 'env' => $environmentVariables, 'memory' => (int) $server->memory, @@ -308,16 +322,17 @@ class ServerRepository 'io' => (int) $server->io, 'cpu' => (int) $server->cpu, 'disk' => (int) $server->disk, - 'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image + 'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image, ], 'service' => [ 'type' => $service->file, - 'option' => $option->tag + 'option' => $option->tag, + 'pack' => (isset($pack)) ? $pack->uuid : null, ], 'keys' => [ - (string) $server->daemonSecret => $this->daemonPermissions + (string) $server->daemonSecret => $this->daemonPermissions, ], - 'rebuild' => false + 'rebuild' => false, ] ]); diff --git a/database/migrations/2016_11_27_142519_add_pack_column.php b/database/migrations/2016_11_27_142519_add_pack_column.php new file mode 100644 index 000000000..f2c2f0964 --- /dev/null +++ b/database/migrations/2016_11_27_142519_add_pack_column.php @@ -0,0 +1,36 @@ +unsignedInteger('pack')->nullable()->after('option'); + + $table->foreign('pack')->references('id')->on('service_packs'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('servers', function (Blueprint $table) { + $table->dropForeign('servers_pack_foreign'); + $table->dropIndex('servers_pack_foreign'); + $table->dropColumn('pack'); + }); + } +} diff --git a/resources/views/admin/servers/new.blade.php b/resources/views/admin/servers/new.blade.php index 276a10958..5d831ce6f 100644 --- a/resources/views/admin/servers/new.blade.php +++ b/resources/views/admin/servers/new.blade.php @@ -451,7 +451,7 @@ $(document).ready(function () { $.each(data.packs, function (i, item) { $('#getPack').append(''); }); - $('#getPack').append('').parent().parent().removeClass('hidden'); + $('#getPack').append('').parent().parent().removeClass('hidden'); $.each(data.variables, function (i, item) { var isRequired = (item.required === 1) ? 'Required ' : '';