CC-3044: Error in system status seen in apache log

- Added check for length > 0 before trying to get property
- Got rid of repeating code
This commit is contained in:
Yuchen Wang 2011-11-15 12:37:54 -05:00
parent 709582b47d
commit f6f58c9399
1 changed files with 11 additions and 10 deletions

View File

@ -96,24 +96,25 @@ class Application_Model_Systemstatus
} }
public static function GetPlatformInfo(){ public static function GetPlatformInfo(){
$data = array("release"=>"UNKNOWN", $keys = array("release", "machine", "memory", "swap");
"machine"=>"UNKNOWN", foreach($keys as $key) {
"memory"=>"UNKNOWN", $data[$key] = "UNKNOWN";
"swap"=>"UNKNOWN"); }
$docRoot = self::GetMonitStatus("localhost"); $docRoot = self::GetMonitStatus("localhost");
if (!is_null($docRoot)){ if (!is_null($docRoot)){
foreach ($docRoot->getElementsByTagName("platform") AS $item) foreach ($docRoot->getElementsByTagName("platform") AS $item)
{ {
$data["release"] = $item->getElementsByTagName("release")->item(0)->nodeValue; foreach($keys as $key) {
$data["machine"] = $item->getElementsByTagName("machine")->item(0)->nodeValue; $keyElement = $item->getElementsByTagName($key);
$data["memory"] = $item->getElementsByTagName("memory")->item(0)->nodeValue; if($keyElement->length > 0) {
$data["swap"] = $item->getElementsByTagName("swap")->item(0)->nodeValue; $data[$key] = $keyElement->item(0)->nodeValue;
}
}
} }
} }
return $data; return $data;
} }
public static function GetPypoStatus(){ public static function GetPypoStatus(){