Skip to content

Commit b7c1b56

Browse files
authored
Update mailer.php
Should fix #639
1 parent 83823ac commit b7c1b56

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

www/lib/mailer.php

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -177,34 +177,31 @@ function webhook_trigger($eventName, $deviceId = null, $payload = array()) {
177177
$dow = array('M', 'T', 'W', 'R', 'F', 'S', 'U');
178178

179179
#parse start timestamp into dow/hour/minute
180-
$p['day'] = $dow[date('w', $timestamp)-1];
180+
$p['day'] = $dow[(date('w', $timestamp) + 6) % 7];
181181
$p['hour'] = date('G', $timestamp);
182182
$p['min'] = date('i', $timestamp);
183183

184-
185184
#form a query and select applicable rules
186185
$query = "SELECT * FROM notificationSchedules
187-
WHERE ";
188-
if (isset($device_id))
189-
$query .= "
190-
cameras LIKE '%|$device_id|%'
191-
AND ";
192-
$query .= "
193-
day LIKE '%{$p['day']}%'
194-
AND
195-
(
196-
(s_hr = {$p['hour']} AND s_min < {$p['min']})
197-
OR
198-
(e_hr = {$p['hour']} AND e_min > {$p['min']})
199-
OR
200-
(s_hr < {$p['hour']} AND e_hr > {$p['hour']})
201-
)
202-
AND
203-
disabled = 0
186+
WHERE ";
187+
if (isset($device_id)) {
188+
$query .= " cameras LIKE '%|$device_id|%' AND ";
189+
}
190+
$query .= " day LIKE '%{$p['day']}%' AND
191+
(
192+
(s_hr = {$p['hour']} AND s_min < {$p['min']})
193+
OR
194+
(e_hr = {$p['hour']} AND e_min > {$p['min']})
195+
OR
196+
(s_hr < {$p['hour']} AND e_hr > {$p['hour']})
197+
)
198+
AND disabled = 0
204199
";
205200
$rules = data::query($query);
206-
if (!$rules){
207-
exit('I: No matching rules');
201+
202+
# Proceed only if rules are found
203+
if ($rules) {
204+
# If there are no rules (yet) don't display anything bad.
208205
} else {
209206

210207
if ($argv[1] == "motion_event") {
@@ -298,7 +295,9 @@ function webhook_trigger($eventName, $deviceId = null, $payload = array()) {
298295
}
299296

300297
if (empty($rules_ids)){
301-
exit('I: All applicable rules exhausted limit');
298+
# exit('I: All applicable rules exhausted limit');
299+
# Don't complain if no rules are setup
300+
exit ();
302301
}
303302

304303

0 commit comments

Comments
 (0)