Skip to content

Commit 3acc7b3

Browse files
committed
Allow deleting default allocation and setting new default at the same time.
1 parent 7762206 commit 3acc7b3

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1515

1616
### Changed
1717
* Deleting a server safely now continues even if the daemon reports a `HTTP/404` missing server error (requires `Daemon@0.4.0-beta.2.1`)
18+
* Changed behavior when modifying server allocation information. You can now remove the default allocation assuming you assing a new allocation at the same time. Reduces the number of steps to change the default allocation for a server.
1819

1920
### Added
2021
* Server listing and view in Admin CP now shows the SFTP username/Docker container name.

app/Repositories/ServerRepository.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -518,34 +518,42 @@ public function changeBuild($id, array $data)
518518
}
519519

520520
$newPorts = false;
521-
// Remove Assignments
522-
if (isset($data['remove_allocations'])) {
523-
foreach ($data['remove_allocations'] as $allocation) {
524-
// Can't remove the assigned IP/Port combo
525-
if ((int) $allocation === $server->allocation_id) {
521+
$firstNewAllocation = null;
522+
// Add Assignments
523+
if (isset($data['add_allocations'])) {
524+
foreach ($data['add_allocations'] as $allocation) {
525+
$model = Models\Allocation::where('id', $allocation)->whereNull('server_id')->first();
526+
if (! $model) {
526527
continue;
527528
}
528529

529530
$newPorts = true;
530-
Models\Allocation::where('id', $allocation)->where('server_id', $server->id)->update([
531-
'server_id' => null,
531+
$firstNewAllocation = (is_null($firstNewAllocation)) ? $model->id : $firstNewAllocation;
532+
$model->update([
533+
'server_id' => $server->id,
532534
]);
533535
}
534536

535537
$server->load('allocations');
536538
}
537539

538-
// Add Assignments
539-
if (isset($data['add_allocations'])) {
540-
foreach ($data['add_allocations'] as $allocation) {
541-
$model = Models\Allocation::where('id', $allocation)->whereNull('server_id')->first();
542-
if (! $model) {
543-
continue;
540+
// Remove Assignments
541+
if (isset($data['remove_allocations'])) {
542+
foreach ($data['remove_allocations'] as $allocation) {
543+
// Can't remove the assigned IP/Port combo
544+
if ((int) $allocation === $server->allocation_id) {
545+
// No New Allocation
546+
if (is_null($firstNewAllocation)) {
547+
continue;
548+
}
549+
550+
// New Allocation, set as the default.
551+
$server->allocation_id = $firstNewAllocation;
544552
}
545553

546554
$newPorts = true;
547-
$model->update([
548-
'server_id' => $server->id,
555+
Models\Allocation::where('id', $allocation)->where('server_id', $server->id)->update([
556+
'server_id' => null,
549557
]);
550558
}
551559

resources/themes/pterodactyl/admin/servers/view/build.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
<div>
131131
<select name="remove_allocations[]" class="form-control" multiple id="pRemoveAllocations">
132132
@foreach ($assigned as $assignment)
133-
<option value="{{ $assignment->id }}" @if($server->allocation_id === $assignment->id)disabled @endif>{{ $assignment->alias }}:{{ $assignment->port }}</option>
133+
<option value="{{ $assignment->id }}">{{ $assignment->alias }}:{{ $assignment->port }}</option>
134134
@endforeach
135135
</select>
136136
</div>

0 commit comments

Comments
 (0)