Small fix to not throw error if details is already empty (#9086)

This commit is contained in:
Neil Lathwood
2018-08-29 15:34:23 +01:00
committed by Tony Murray
parent f2253d70fd
commit b411f6c5d8

View File

@@ -214,7 +214,10 @@ function RunRules($device_id)
// NOCHG here doesn't mean no change full stop. It means no change to the alert state
// So we update the details column with any fresh changes to the alert output we might have.
$alert_log = dbFetchRow('SELECT alert_log.id, alert_log.details FROM alert_log,alert_rules WHERE alert_log.rule_id = alert_rules.id && alert_log.device_id = ? && alert_log.rule_id = ? && alert_rules.disabled = 0 ORDER BY alert_log.id DESC LIMIT 1', array($device_id, $rule['id']));
$details = json_decode(gzuncompress($alert_log['details']), true);
$details = [];
if (!empty($alert_log['details'])) {
$details = json_decode(gzuncompress($alert_log['details']), true);
}
$details['contacts'] = GetContacts($qry);
$details['rule'] = $qry;
$details = gzcompress(json_encode($details), 9);
@@ -478,7 +481,10 @@ function DescribeAlert($alert)
return false;
}
$extra = json_decode(gzuncompress($id['details']), true);
$extra = [];
if (!empty($id['details'])) {
$extra = json_decode(gzuncompress($id['details']), true);
}
// Reset count to 0 so alerts will continue
$extra['count'] = 0;
@@ -689,7 +695,9 @@ function loadAlerts($where)
$alert['alert_id'] = $alert_status['id'];
$alert['state'] = $alert_status['state'];
$alert['note'] = $alert_status['note'];
$alert['details'] = json_decode(gzuncompress($alert['details']), true);
if (!empty($alert['details'])) {
$alert['details'] = json_decode(gzuncompress($alert['details']), true);
}
$alerts[] = $alert;
}
}