Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion app/Http/Controllers/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ private function getUpgradeOptions(Server $server, array $serverInfo): \Illumina
$currentEgg = $serverInfo['egg'];

//$currentProductEggs = $currentProduct->eggs->pluck('id')->toArray();
$user = Auth::user();

return Product::orderBy('price', 'asc')
->with('nodes')->with('eggs')
Expand All @@ -406,7 +407,7 @@ private function getUpgradeOptions(Server $server, array $serverInfo): \Illumina
$builder->where('id', $currentEgg);
})
->get()
->map(function ($product) use ($currentProduct, $pteroNode) {
->map(function ($product) use ($currentProduct, $pteroNode, $user) {
$product->eggs = $product->eggs->pluck('name')->toArray();

$memoryDiff = $product->memory - $currentProduct->memory;
Expand All @@ -420,6 +421,12 @@ private function getUpgradeOptions(Server $server, array $serverInfo): \Illumina
$product->doesNotFit = true;
}

// Check server limit for the product
$productCount = $user->servers()->where("product_id", $product->id)->count();
if ($productCount >= $product->serverlimit && $product->serverlimit != 0) {
$product->doesNotFit = true;
}

return $product;
});
}
Expand Down Expand Up @@ -448,6 +455,15 @@ public function upgrade(Server $server, Request $request): RedirectResponse
->with('error', __('Selected product not found'));
}

// Check server limit for the new product
if ($oldProduct->id !== $newProduct->id) {
$productCount = $user->servers()->where("product_id", $newProduct->id)->count();
if ($productCount >= $newProduct->serverlimit && $newProduct->serverlimit != 0) {
return redirect()->route('servers.show', ['server' => $server->id])
->with('error', __('You can not create any more Servers with this product!'));
}
}

if (!$this->validateUpgrade($server, $oldProduct, $newProduct)) {
return redirect()->route('servers.show', ['server' => $server->id])
->with('error', __('Insufficient resources or credits for upgrade'));
Expand Down Expand Up @@ -515,6 +531,14 @@ private function validateUpgrade(Server $server, Product $oldProduct, Product $n
return false;
}

// Check server limit for the new product
if ($oldProduct->id !== $newProduct->id) {
$productCount = $user->servers()->where("product_id", $newProduct->id)->count();
if ($productCount >= $newProduct->serverlimit && $newProduct->serverlimit != 0) {
return false;
}
}

return true;
}

Expand Down
Loading