Commit version 24.12.13800
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Observium
|
||||
*
|
||||
@ -7,25 +6,37 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage update
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
foreach (dbFetchRows("SELECT * FROM `alert_tests` ". $where, $args) as $entry)
|
||||
{
|
||||
$conditions = json_decode($entry['conditions'], TRUE);
|
||||
|
||||
for ($i = 0; $i < count($conditions); $i++)
|
||||
{
|
||||
if ($conditions[$i]['value'] == '' && $conditions[$i]['metric'] == '' && $conditions[$i]['condition'] == '')
|
||||
{
|
||||
// Remove invalid condition entry
|
||||
unset($conditions[$i]);
|
||||
}
|
||||
}
|
||||
// Check if $conditions is an array before proceeding
|
||||
if ($conditions = safe_json_decode($entry['conditions'])) {
|
||||
|
||||
// Use a temporary array to store valid conditions
|
||||
$validConditions = [];
|
||||
|
||||
foreach ($conditions as $condition) {
|
||||
// Check if all values are empty
|
||||
if ($condition['value'] !== '' || $condition['metric'] !== '' || $condition['condition'] !== '') {
|
||||
// If not all values are empty, add to valid conditions
|
||||
$validConditions[] = $condition;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the database with the valid conditions only
|
||||
dbUpdate(array('conditions' => safe_json_encode($validConditions)), 'alert_tests', '`alert_test_id` = ?', array($entry['alert_test_id']));
|
||||
|
||||
echo('.');
|
||||
} else {
|
||||
// Handle the case where $conditions is not an array (e.g., null or false)
|
||||
// Depending on your application logic, you might want to log this or take other actions
|
||||
print_debug("Invalid JSON in alert_tests for alert_test_id: " . $entry['alert_test_id']);
|
||||
echo('E');
|
||||
}
|
||||
|
||||
dbUpdate(array('conditions' => json_encode($conditions)), 'alert_tests', '`alert_test_id` = ?', array($entry['alert_test_id']));
|
||||
echo('.');
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
||||
Reference in New Issue
Block a user