Check for resources when upgrading server

This commit is contained in:
ok236449 2022-08-24 17:52:51 +02:00
parent 30d29cdd62
commit df0d37bb81
2 changed files with 14 additions and 3 deletions

View file

@ -241,6 +241,9 @@ class ServerController extends Controller
$serverRelationships = $serverAttributes['relationships'];
$serverLocationAttributes = $serverRelationships['location']['attributes'];
//Get current product
$currentProduct = Product::where('id', $server->product_id)->first();
//Set server infos
$server->location = $serverLocationAttributes['long'] ?
$serverLocationAttributes['long'] :
@ -249,11 +252,19 @@ class ServerController extends Controller
$server->node = $serverRelationships['node']['attributes']['name'];
$server->name = $serverAttributes['name'];
$server->egg = $serverRelationships['egg']['attributes']['name'];
$products = Product::orderBy("created_at")->get();
$pteroNode = Pterodactyl::getNode($serverRelationships['node']['attributes']['id']);
$products = Product::orderBy("created_at")
->whereHas('nodes', function (Builder $builder) use ($serverRelationships) { //Only show products for that node
$builder->where('id', '=', $serverRelationships['node']['attributes']['id']);
})
->get();
// Set the each product eggs array to just contain the eggs name
foreach ($products as $product) {
$product->eggs = $product->eggs->pluck('name')->toArray();
if($product->memory-$currentProduct->memory>($pteroNode['memory']*($pteroNode['memory_overallocate']+100)/100)-$pteroNode['allocated_resources']['memory']||$product->disk-$currentProduct->disk>($pteroNode['disk']*($pteroNode['disk_overallocate']+100)/100)-$pteroNode['allocated_resources']['disk']) $product->doesNotFit = true;
}
return view('servers.settings')->with([

View file

@ -255,8 +255,8 @@
<option value="">{{__("Select the product")}}</option>
@foreach($products as $product)
@if(in_array($server->egg, $product->eggs) && $product->id != $server->product->id && $product->disabled == false)
<option value="{{ $product->id }}">{{ $product->name }} [ {{ CREDITS_DISPLAY_NAME }} {{ $product->price }} @if($product->minimum_credits!=-1) /
{{__("Required")}}: {{$product->minimum_credits}} {{ CREDITS_DISPLAY_NAME }}@endif ]</option>
<option value="{{ $product->id }}" @if($product->doesNotFit)disabled @endif>{{ $product->name }} [ {{ CREDITS_DISPLAY_NAME }} {{ $product->price }} @if($product->doesNotFit)] {{__('Server can´t fit on this node')}} @else @if($product->minimum_credits!=-1) /
{{__("Required")}}: {{$product->minimum_credits}} {{ CREDITS_DISPLAY_NAME }}@endif ] @endif</option>
@endif
@endforeach
</select>