From e11b700fbd3df34df123478d17e13f30acf1dca9 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Wed, 13 Sep 2023 11:18:50 -0700 Subject: [PATCH] Add Id as a protected member, only lookup monitor status if Id has a value --- web/includes/Monitor.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/web/includes/Monitor.php b/web/includes/Monitor.php index 3bc50a5c6..73bae535b 100644 --- a/web/includes/Monitor.php +++ b/web/includes/Monitor.php @@ -276,6 +276,8 @@ public static function getStatuses() { 'ArchivedEventDiskSpace' => array('type'=>'integer', 'default'=>null, 'do_not_update'=>1), ); + protected $Id; + public function save($data = null) { if ($data) $this->set($data); if ($this->Manufacturer() and $this->Manufacturer()->Name() and ! $this->Manufacturer->Id()) { @@ -412,17 +414,19 @@ public static function getStatuses() { } return $this->defaults[$fn]; } else if (array_key_exists($fn, $this->status_fields)) { - $sql = 'SELECT * FROM `Monitor_Status` WHERE `MonitorId`=?'; - $row = dbFetchOne($sql, NULL, array($this->{'Id'})); - if (!$row) { - Warning('Unable to load Monitor status record for Id='.$this->{'Id'}.' using '.$sql); - return null; - } else { - foreach ($row as $k => $v) { - $this->{$k} = $v; + if ($this->Id()) { + $sql = 'SELECT * FROM `Monitor_Status` WHERE `MonitorId`=?'; + $row = dbFetchOne($sql, NULL, array($this->{'Id'})); + if (!$row) { + Warning('Unable to load Monitor status record for Id='.$this->{'Id'}.' using '.$sql); + } else { + foreach ($row as $k => $v) { + $this->{$k} = $v; + } + return $this->{$fn}; } - } - return $this->{$fn}; + } # end if this->Id + return null; } else if (array_key_exists($fn, $this->summary_fields)) { $sql = 'SELECT * FROM `Event_Summaries` WHERE `MonitorId`=?'; $row = dbFetchOne($sql, NULL, array($this->{'Id'}));