Skip to content

Commit 33880ce

Browse files
authored
Merge pull request #640 from bluecherrydvr/mailer-fix
2 parents 2079c3d + 68f3c0f commit 33880ce

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

www/lib/mailer.php

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -177,34 +177,30 @@ 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+
if (!$rules) {
203+
# If there are no rules (yet) don't display anything bad.
208204
} else {
209205

210206
if ($argv[1] == "motion_event") {
@@ -298,7 +294,9 @@ function webhook_trigger($eventName, $deviceId = null, $payload = array()) {
298294
}
299295

300296
if (empty($rules_ids)){
301-
exit('I: All applicable rules exhausted limit');
297+
# exit('I: All applicable rules exhausted limit');
298+
# Don't complain if no rules are setup
299+
exit ();
302300
}
303301

304302

0 commit comments

Comments
 (0)