Skip to content

Commit 3ee9cae

Browse files
committed
Updates
* Diagnostic script: added php and web-server details * Simple Devices: PHP8 fix * Simple Devices: counter fix
1 parent 5ef2a08 commit 3ee9cae

File tree

3 files changed

+72
-25
lines changed

3 files changed

+72
-25
lines changed

Diff for: diagnostic.php

+10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ function collectData()
6666
}
6767
$result['OS'] = $os;
6868
$result['locale'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
69+
$result['PHP']['version'] = phpversion();
70+
$result['PHP']['extensions'] = get_loaded_extensions();
71+
72+
$server_keys = array('SERVER_SOFTWARE','GATEWAY_INTERFACE','DOCUMENT_ROOT','FCGI_ROLE','USER','HOME','HTTP_HOST');
73+
foreach($server_keys as $key) {
74+
if (isset($_SERVER[$key])) {
75+
$result['SERVER'][$key]=$_SERVER[$key];
76+
}
77+
}
78+
6979

7080
$cycles = array();
7181
if ($lib_dir = opendir("./scripts")) {

Diff for: modules/devices/SCounters_valueUpdated.php

+61-24
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,74 @@
44
$new_value = (float)$params['NEW_VALUE'];
55
$old_value = (float)$params['OLD_VALUE'];
66

7+
$timer_name = $ot . '_counter_update_h';
8+
clearTimeOut($timer_name);
9+
10+
$timer_name = $ot . '_counter_update_d';
11+
clearTimeOut($timer_name);
12+
13+
$timer_name = $ot . '_counter_update_m';
14+
clearTimeOut($timer_name);
15+
16+
if ($new_value != $old_value) {
17+
18+
// HOUR
19+
$timer_name = $ot . '_counter_update_h';
20+
$when_start = strtotime(date('Y-m-d H:59:59')) + 1;
21+
$timeout = $when_start - time() + 1;
22+
setTimeOut($timer_name, "DebMes('H: Updating $ot.value to $new_value','counter_update');setGlobal('$ot.value', '" . $new_value . "');", $timeout);
23+
$prev_timeout = $timeout;
24+
25+
// DAY
26+
$timer_name = $ot . '_counter_update_d';
27+
$when_start = strtotime(date('Y-m-d 23:59:59')) + 1;
28+
$timeout = $when_start - time() + 1;
29+
if ($prev_timeout != $timeout) {
30+
setTimeOut($timer_name, "DebMes('D: Updating $ot.value to $new_value','counter_update');setGlobal('$ot.value', '" . $new_value . "');", $timeout);
31+
$prev_timeout = $timeout;
32+
}
33+
34+
// MONTH
35+
$timer_name = $ot . '_counter_update_m';
36+
$when_start = strtotime(date('Y-m-t 23:59:59')) + 1;
37+
$timeout = $when_start - time() + 1;
38+
if ($prev_timeout != $timeout) {
39+
setTimeOut($timer_name, "DebMes('M: Updating $ot.value to $new_value','counter_update');setGlobal('$ot.value', '" . $new_value . "');", $timeout);
40+
}
41+
42+
}
43+
744
$this->callMethodSafe('keepAlive');
845
$this->callMethodSafe('statusUpdated');
946
$this->callMethodSafe('logicAction');
1047

1148
$history_values = array(
12-
'valueHour'=>date('Y-m-d H:00:00'),
13-
'valueDay'=>date('Y-m-d 00:00:00'),
14-
'valueMonth'=>date('Y-m-01 00:00:00')
49+
'valueHour' => date('Y-m-d H:00:00'),
50+
'valueDay' => date('Y-m-d 00:00:00'),
51+
'valueMonth' => date('Y-m-01 00:00:00')
1552
);
1653

17-
foreach ($history_values as $history_value=>$time) {
18-
$value_id = (int)getHistoryValueId($ot . '.' . $history_value);
19-
if (defined('SEPARATE_HISTORY_STORAGE') && SEPARATE_HISTORY_STORAGE == 1) {
20-
$table_name = createHistoryTable($value_id);
21-
} else {
22-
$table_name = 'phistory';
23-
}
24-
$val1 = SQLSelectOne("SELECT ID, VALUE FROM pvalues WHERE ID='" . $value_id . "' AND UPDATED>=('" . $time . "')");
25-
if ($val1['ID']) {
26-
SQLExec("DELETE FROM $table_name WHERE VALUE_ID=$value_id AND ADDED>=('" . $time . "')");
27-
$set_value = $val1['VALUE'] + ($new_value - $old_value);
28-
$set_value = round($set_value, 3);
29-
$this->setProperty($history_value, $set_value);
30-
} else {
31-
$set_value = $new_value - $old_value;
32-
$set_value = round($set_value, 3);
33-
$this->setProperty($history_value, $set_value);
34-
//DebMes($history_value . ' ' . $time . ' - id - ' . $value_id . ' - new - ' . $new_value . ' - old - ' . $old_value, $ot);
35-
}
54+
foreach ($history_values as $history_value => $time) {
55+
$value_id = (int)getHistoryValueId($ot . '.' . $history_value);
56+
if (defined('SEPARATE_HISTORY_STORAGE') && SEPARATE_HISTORY_STORAGE == 1) {
57+
$table_name = createHistoryTable($value_id);
58+
} else {
59+
$table_name = 'phistory';
60+
}
61+
$val1 = SQLSelectOne("SELECT ID, VALUE FROM pvalues WHERE ID='" . $value_id . "' AND UPDATED>=('" . $time . "')");
62+
if ($val1['ID']) {
63+
SQLExec("DELETE FROM $table_name WHERE VALUE_ID=$value_id AND ADDED>=('" . $time . "')");
64+
$set_value = $val1['VALUE'] + ($new_value - $old_value);
65+
$set_value = round($set_value, 2);
66+
$this->setProperty($history_value, $set_value);
67+
} else {
68+
$set_value = $new_value - $old_value;
69+
$set_value = round($set_value, 2);
70+
$this->setProperty($history_value, $set_value);
71+
//DebMes($history_value . ' ' . $time . ' - id - ' . $value_id . ' - new - ' . $new_value . ' - old - ' . $old_value, $ot);
72+
}
3673
}
3774

38-
include_once(dirname(__FILE__).'/devices.class.php');
39-
$dv=new devices();
75+
include_once(dirname(__FILE__) . '/devices.class.php');
76+
$dv = new devices();
4077
$dv->checkLinkedDevicesAction($this->object_title, $new_value);

Diff for: modules/devices/devices_search.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
$out['SORTBY'] = $sortby_devices;
114114
// SEARCH RESULTS
115115
$res = SQLSelect("SELECT devices.*, locations.TITLE as LOCATION_TITLE FROM devices LEFT JOIN locations ON devices.LOCATION_ID=locations.ID WHERE $qry ORDER BY " . $sortby_devices);
116-
if ($res[0]['ID']) {
116+
if (isset($res[0])) {
117117
//paging($res, 100, $out); // search result paging
118118
$total = count($res);
119119
$out['TOTAL_FOUND'] = $total;

0 commit comments

Comments
 (0)