Skip to content

Commit c4a4b84

Browse files
committed
Add service pack reference to server and send to daemon
1 parent 238f08f commit c4a4b84

File tree

4 files changed

+61
-8
lines changed

4 files changed

+61
-8
lines changed

app/Http/Controllers/Admin/ServersController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ public function postNewServer(Request $request)
168168

169169
try {
170170
$server = new ServerRepository;
171-
$response = $server->create($request->all());
171+
$response = $server->create($request->except([
172+
'_token'
173+
]));
172174
return redirect()->route('admin.servers.view', [ 'id' => $response ]);
173175
} catch (DisplayValidationException $ex) {
174176
return redirect()->route('admin.servers.new')->withErrors(json_decode($ex->getMessage()))->withInput();

app/Repositories/ServerRepository.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function create(array $data)
8686
'disk' => 'required|numeric|min:0',
8787
'service' => 'bail|required|numeric|min:1|exists:services,id',
8888
'option' => 'bail|required|numeric|min:1|exists:service_options,id',
89+
'pack' => 'bail|required|numeric|min:0'
8990
'startup' => 'string',
9091
'custom_image_name' => 'required_if:use_custom_image,on',
9192
'auto_deploy' => 'sometimes|boolean'
@@ -161,6 +162,18 @@ public function create(array $data)
161162
throw new DisplayException('The requested service option does not exist for the specified service.');
162163
}
163164

165+
// Validate the Pack
166+
if ($data['pack'] === 0) {
167+
$data['pack'] = null;
168+
}
169+
170+
if (!is_null($data['pack'])) {
171+
$pack = Models\ServicePack::where('id', $data['pack'])->where('option', $data['option'])->first();
172+
if (!$pack) {
173+
throw new DisplayException('The requested service pack does not seem to exist for this combination.');
174+
}
175+
}
176+
164177
// Load up the Service Information
165178
$service = Models\Service::find($option->parent_service);
166179

@@ -248,6 +261,7 @@ public function create(array $data)
248261
'allocation' => $allocation->id,
249262
'service' => $data['service'],
250263
'option' => $data['option'],
264+
'pack' => $data['pack'],
251265
'startup' => $data['startup'],
252266
'daemonSecret' => $uuid->generate('servers', 'daemonSecret'),
253267
'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image,
@@ -297,27 +311,28 @@ public function create(array $data)
297311
'build' => [
298312
'default' => [
299313
'ip' => $allocation->ip,
300-
'port' => (int) $allocation->port
314+
'port' => (int) $allocation->port,
301315
],
302316
'ports' => [
303-
(string) $allocation->ip => [ (int) $allocation->port ]
317+
(string) $allocation->ip => [ (int) $allocation->port ],
304318
],
305319
'env' => $environmentVariables,
306320
'memory' => (int) $server->memory,
307321
'swap' => (int) $server->swap,
308322
'io' => (int) $server->io,
309323
'cpu' => (int) $server->cpu,
310324
'disk' => (int) $server->disk,
311-
'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image
325+
'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image,
312326
],
313327
'service' => [
314328
'type' => $service->file,
315-
'option' => $option->tag
329+
'option' => $option->tag,
330+
'pack' => (isset($pack)) ? $pack->uuid : null,
316331
],
317332
'keys' => [
318-
(string) $server->daemonSecret => $this->daemonPermissions
333+
(string) $server->daemonSecret => $this->daemonPermissions,
319334
],
320-
'rebuild' => false
335+
'rebuild' => false,
321336
]
322337
]);
323338

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddPackColumn extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('servers', function (Blueprint $table) {
17+
$table->unsignedInteger('pack')->nullable()->after('option');
18+
19+
$table->foreign('pack')->references('id')->on('service_packs');
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*
26+
* @return void
27+
*/
28+
public function down()
29+
{
30+
Schema::table('servers', function (Blueprint $table) {
31+
$table->dropForeign('servers_pack_foreign');
32+
$table->dropIndex('servers_pack_foreign');
33+
$table->dropColumn('pack');
34+
});
35+
}
36+
}

resources/views/admin/servers/new.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@
451451
$.each(data.packs, function (i, item) {
452452
$('#getPack').append('<option value="' + item.uuid + '">' + item.name + ' (' + item.version + ')</option>');
453453
});
454-
$('#getPack').append('<option value="none">No Service Pack</option>').parent().parent().removeClass('hidden');
454+
$('#getPack').append('<option value="0">No Service Pack</option>').parent().parent().removeClass('hidden');
455455
456456
$.each(data.variables, function (i, item) {
457457
var isRequired = (item.required === 1) ? '<span class="label label-primary">Required</span> ' : '';

0 commit comments

Comments
 (0)