From 454d21946a5dc8f22dac4cc7bb4a6fa66ce28622 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Thu, 23 May 2013 21:52:26 +0200 Subject: [PATCH] Only attempt to iterate through VPS list query results when the result isn't empty --- frontend/modules/client/vps/list.php | 51 ++++++++++++++-------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/frontend/modules/client/vps/list.php b/frontend/modules/client/vps/list.php index a2ddec5..9aaa799 100644 --- a/frontend/modules/client/vps/list.php +++ b/frontend/modules/client/vps/list.php @@ -15,36 +15,37 @@ if(!isset($_CVM)) { die("Unauthorized."); } if($sLoggedIn === true) { - $result = $database->CachedQuery("SELECT * FROM containers WHERE `UserId` = :UserId", array(":UserId" => $sUser->sId)); - $sVpsList = array(); - foreach($result->data as $row) + if($result = $database->CachedQuery("SELECT * FROM containers WHERE `UserId` = :UserId", array(":UserId" => $sUser->sId))) { - $sVps = new Vps($row); - - try - { - $sStatus = $sVps->sStatusText; - } - catch (SshException $e) + foreach($result->data as $row) { - $sStatus = "unknown"; + $sVps = new Vps($row); + + try + { + $sStatus = $sVps->sStatusText; + } + catch (SshException $e) + { + $sStatus = "unknown"; + } + + $sVpsList[] = array( + 'id' => $sVps->sId, + 'hostname' => $sVps->sHostname, + 'node' => $sVps->sNode->sName, + 'node-hostname' => $sVps->sNode->sHostname, + 'template' => $sVps->sTemplate->sName, + 'diskspace' => number_format($sVps->sDiskSpace / 1024), + 'diskspace-unit' => "GB", + 'guaranteed-ram' => $sVps->sGuaranteedRam, + 'guaranteed-ram-unit' => "MB", + 'status' => $sStatus, + 'virtualization-type' => $sVps->sVirtualizationType + ); } - - $sVpsList[] = array( - 'id' => $sVps->sId, - 'hostname' => $sVps->sHostname, - 'node' => $sVps->sNode->sName, - 'node-hostname' => $sVps->sNode->sHostname, - 'template' => $sVps->sTemplate->sName, - 'diskspace' => number_format($sVps->sDiskSpace / 1024), - 'diskspace-unit' => "GB", - 'guaranteed-ram' => $sVps->sGuaranteedRam, - 'guaranteed-ram-unit' => "MB", - 'status' => $sStatus, - 'virtualization-type' => $sVps->sVirtualizationType - ); } $sMainContents = Templater::AdvancedParse("{$sTheme}/client/vps/list", $locale->strings, array(