Skip to content

Commit 59b964d

Browse files
committed
QA: Fixing Inconsistencies with template_enabled flag
1 parent 2a857f0 commit 59b964d

5 files changed

Lines changed: 21 additions & 21 deletions

File tree

includes/database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2142,6 +2142,6 @@ function thold_setup_database() {
21422142

21432143
db_execute('UPDATE thold_data
21442144
SET thold_enabled = "on"
2145-
WHERE thold_template_id = 0 OR template_enabled = "off"');
2145+
WHERE thold_template_id = 0 OR template_enabled != "on"');
21462146
}
21472147

includes/polling.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ function thold_check_all_thresholds() {
274274
OR (
275275
thold_template_id > 0
276276
AND (
277-
template_enabled = 'off' OR (template_enabled = 'on' AND thold_enabled = 'on')
277+
template_enabled != 'on' OR (template_enabled = 'on' AND thold_enabled = 'on')
278278
)
279279
)
280280
)
@@ -296,7 +296,7 @@ function thold_check_all_thresholds() {
296296
OR (
297297
thold_template_id > 0
298298
AND (
299-
template_enabled = 'off' OR (template_enabled = 'on' AND thold_enabled = 'on')
299+
template_enabled != 'on' OR (template_enabled = 'on' AND thold_enabled = 'on')
300300
)
301301
)
302302
)
@@ -317,7 +317,7 @@ function thold_check_all_thresholds() {
317317
OR (
318318
thold_template_id > 0
319319
AND (
320-
template_enabled = 'off' OR (template_enabled = 'on' AND thold_enabled = 'on')
320+
template_enabled != 'on' OR (template_enabled = 'on' AND thold_enabled = 'on')
321321
)
322322
)
323323
)

thold.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ function list_tholds() {
591591
if (get_request_var('thold_template_id') > 0) {
592592
$sql_where .= ($sql_where == '' ? '(' : ' AND ') . '(td.thold_template_id = ' . get_request_var('thold_template_id') . ' AND td.template_enabled = "on")';
593593
} elseif (get_request_var('thold_template_id') == '-2') {
594-
$sql_where .= ($sql_where == '' ? '(' : ' AND ') . '(td.template_enabled = "off" OR td.template_enabled = "")';
594+
$sql_where .= ($sql_where == '' ? '(' : ' AND ') . '(td.template_enabled != "on")';
595595
}
596596
}
597597

@@ -968,7 +968,7 @@ function clearFilter() {
968968

969969
form_selectable_cell(filter_value($name, get_request_var('rfilter'), 'thold.php?action=edit&id=' . $thold_data['id']), $thold_data['id'], '', 'left');
970970

971-
if ((($thold_data['template_enabled'] == 'on' && $thold_data['thold_enabled'] == 'on') || ($thold_data['template_enabled'] == 'off' || $thold_data['template_enabled'] == '')) && $thold_data['thold_per_enabled'] == 'on') {
971+
if ((($thold_data['template_enabled'] == 'on' && $thold_data['thold_enabled'] == 'on') || $thold_data['template_enabled'] != 'on') && $thold_data['thold_per_enabled'] == 'on') {
972972
$enabled = __('Yes', 'thold');
973973
} elseif ($thold_data['template_enabled'] == 'on' && $thold_data['thold_enabled'] == 'off' && $thold_data['thold_per_enabled'] == '') {
974974
$enabled = __('No [Template:Thold]', 'thold');
@@ -1042,7 +1042,7 @@ function clearFilter() {
10421042
form_selectable_cell('<i>' . get_time_since_last_event($thold_data) . '</i>', $thold_data['id'], '', 'right');
10431043

10441044
if ($thold_data['thold_template_id'] != 0) {
1045-
form_selectable_cell($thold_data['template_enabled'] == 'off' || $thold_data['template_enabled'] == '' ? __('No', 'thold'):__('Yes', 'thold'), $thold_data['id'], '', 'right');
1045+
form_selectable_cell($thold_data['template_enabled'] != 'on' ? __('No', 'thold'):__('Yes', 'thold'), $thold_data['id'], '', 'right');
10461046
} else {
10471047
form_selectable_cell(__('No', 'thold'), $thold_data['id'], '', 'right');
10481048
}
@@ -1562,7 +1562,7 @@ function thold_edit() {
15621562
'method' => 'checkbox',
15631563
'default' => '',
15641564
'description' => __('Whether or not these settings will be propagated from the Threshold template.', 'thold'),
1565-
'value' => $thold_data['template_enabled'] == 'off' || $thold_data['template_enabled'] == '' ? 'off':'on',
1565+
'value' => $thold_data['template_enabled'] != 'on' ? 'off':'on',
15661566
),
15671567
'template_name' => array(
15681568
'friendly_name' => __('Template Name', 'thold'),

thold_functions.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5383,8 +5383,8 @@ function save_thold() {
53835383
array($data_template_rrd_id));
53845384
}
53855385

5386-
$template_enabled = isset_request_var('template_enabled') && get_nfilter_request_var('template_enabled') == 'on' ? 'on' : 'off';
5387-
$thold_per_enabled = isset_request_var('thold_per_enabled' ) && get_nfilter_request_var('thold_per_enabled' ) == 'on' ? 'on' : '';
5386+
$template_enabled = isset_request_var('template_enabled') && get_nfilter_request_var('template_enabled') == 'on' ? 'on' : 'off';
5387+
$thold_per_enabled = isset_request_var('thold_per_enabled') && get_nfilter_request_var('thold_per_enabled') == 'on' ? 'on' : '';
53885388

53895389
if ($template_enabled == 'on') {
53905390
if ($local_graph_id > 0 && !is_thold_allowed_graph($local_graph_id)) {
@@ -5556,7 +5556,7 @@ function save_thold() {
55565556

55575557
$save['restored_alert'] = isset_request_var('restored_alert') ? 'on':'';
55585558
$save['thold_type'] = get_request_var('thold_type');
5559-
$save['template_enabled'] = isset_request_var('template_enabled') ? 'on':'off';
5559+
$save['template_enabled'] = isset_request_var('template_enabled') && get_nfilter_request_var('template_enabled') == 'on' ? 'on':'off';
55605560

55615561
// High / Low
55625562
$save['thold_hi'] = trim_round_request_var('thold_hi', 4, 'thold_hi');
@@ -6059,10 +6059,10 @@ function thold_create_thold_save_from_template($save, $template) {
60596059
$save['snmp_event_warning_severity'] = $template['snmp_event_warning_severity'];
60606060

60616061
// Other
6062-
$save['notes'] = $template['notes'];
6063-
$save['external_id'] = $template['external_id'];
6064-
$save['format_file'] = $template['format_file'];
6065-
$save['graph_timespan'] = $template['graph_timespan'];
6062+
$save['notes'] = $template['notes'];
6063+
$save['external_id'] = $template['external_id'];
6064+
$save['format_file'] = $template['format_file'];
6065+
$save['graph_timespan'] = $template['graph_timespan'];
60666066

60676067
return $save;
60686068
}

thold_graph.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ function tholds() {
402402
if (get_request_var('thold_template_id') > 0) {
403403
$sql_where .= ($sql_where == '' ? '(' : ' AND ') . '(td.thold_template_id = ' . get_request_var('thold_template_id') . ' AND td.template_enabled = "on")';
404404
} elseif (get_request_var('thold_template_id') == '-2') {
405-
$sql_where .= ($sql_where == '' ? '(' : ' AND ') . '(td.template_enabled = "off" || td.template_enabled = "")';
405+
$sql_where .= ($sql_where == '' ? '(' : ' AND ') . '(td.template_enabled != "on")';
406406
}
407407
}
408408

@@ -614,8 +614,8 @@ function tholds() {
614614
if (api_user_realm_auth('thold.php')) {
615615
if ($thold_data['thold_per_enabled'] == 'on') {
616616
$actions_url .= '<a class="pic" href="' . html_escape($config['url_path'] . 'plugins/thold/thold_graph.php?action=disable&id=' . $thold_data['id']) . '" title="' . __esc('Disable Threshold', 'thold') . '"><i class="tholdGlyphDisable fas fa-stop-circle"></i></a>';
617-
} elseif ((($thold_data['template_enabled'] == 'on' && $thold_data['thold_enabled'] == 'on') ||
618-
($thold_data['template_enabled'] == 'off' || $thold_data['template_enabled'] == '')) && $thold_data['thold_per_enabled'] == '') {
617+
} elseif ((($thold_data['template_enabled'] == 'on' && $thold_data['thold_enabled'] == 'on') || $thold_data['template_enabled'] != 'on') &&
618+
$thold_data['thold_per_enabled'] == '') {
619619
$actions_url .= '<a class="pic" href="' . html_escape($config['url_path'] . 'plugins/thold/thold_graph.php?action=enable&id=' . $thold_data['id']) . '" title="' . __esc('Enable Threshold', 'thold') . '"><i class="tholdGlyphEnable fas fa-play-circle"></i></a>';
620620
} else {
621621
$actions_url .= '<a class="pic" href="#" title="' . __esc('To enable the Threshold, enable the Template first', 'thold') . '"><i class="deviceDisabled fas fa-play-circle"></i></a>';
@@ -692,7 +692,7 @@ function tholds() {
692692
form_selectable_cell($thold_data['name_cache'] != '' ? filter_value($thold_data['name_cache'], get_request_var('rfilter')) : __('No name set', 'thold'), $thold_data['id'], '', 'left');
693693
form_selectable_cell($thold_data['external_id'], $thold_data['id'], '', 'left');
694694

695-
if ((($thold_data['template_enabled'] == 'on' && $thold_data['thold_enabled'] == 'on') || ($thold_data['template_enabled'] == 'off' || $thold_data['template_enabled'] == '')) && $thold_data['thold_per_enabled'] == 'on') {
695+
if ((($thold_data['template_enabled'] == 'on' && $thold_data['thold_enabled'] == 'on') || $thold_data['template_enabled'] != 'on') && $thold_data['thold_per_enabled'] == 'on') {
696696
$enabled = __('Yes', 'thold');
697697
} elseif ($thold_data['template_enabled'] == 'on' && $thold_data['thold_enabled'] == 'off' && $thold_data['thold_per_enabled'] == '') {
698698
$enabled = __('No [Template:Thold]', 'thold');
@@ -1349,7 +1349,7 @@ function thold_export_log() {
13491349
if (get_request_var('thold_template_id') > 0) {
13501350
$sql_where .= ($sql_where == '' ? '' : ' AND ') . '(td.thold_template_id = ' . get_request_var('thold_template_id') . ' AND td.template_enabled = "on")';
13511351
} elseif (get_request_var('thold_template_id') == '-2') {
1352-
$sql_where .= ($sql_where == '' ? '' : ' AND ') . '(td.template_enabled = "off" OR td.template_enabled = "")';
1352+
$sql_where .= ($sql_where == '' ? '' : ' AND ') . '(td.template_enabled != "on")';
13531353
}
13541354
}
13551355

@@ -1440,7 +1440,7 @@ function thold_show_log() {
14401440
if (get_request_var('thold_template_id') > 0) {
14411441
$sql_where .= ($sql_where == '' ? '' : ' AND ') . '(td.thold_template_id = ' . get_request_var('thold_template_id') . ' AND td.template_enabled = "on")';
14421442
} elseif (get_request_var('thold_template_id') == '-2') {
1443-
$sql_where .= ($sql_where == '' ? '' : ' AND ') . '(td.template_enabled = "off" OR td.template_enabled = "")';
1443+
$sql_where .= ($sql_where == '' ? '' : ' AND ') . '(td.template_enabled != "on")';
14441444
}
14451445
}
14461446

0 commit comments

Comments
 (0)