Push Messages #3

This commit is contained in:
JonatanRek 2019-10-08 17:08:54 +02:00
parent e5f1fc61d6
commit b23d653c64

View File

@ -51,10 +51,8 @@ class AutomationManager{
$run = false; $run = false;
$restart = false; $restart = false;
if ($automation['active'] == 1){ if ($automation['active'] == 1 && $automation['locked'] != 1){
Db::edit('automation', array('locked' => 1), 'WHERE automation_id = ?', array($automation['automation_id']));
if (in_array($dayNameNow, $actionDays)){ if (in_array($dayNameNow, $actionDays)){
if (in_array($onValue['type'], ['sunSet', 'sunRise', 'time','now'])) { if (in_array($onValue['type'], ['sunSet', 'sunRise', 'time','now'])) {
if ($onValue['type'] == 'sunSet') { if ($onValue['type'] == 'sunSet') {
@ -119,24 +117,22 @@ class AutomationManager{
$subscribers = NotificationManager::getSubscription(); $subscribers = NotificationManager::getSubscription();
$i = 0; $i = 0;
foreach ($subscribers as $key => $subscriber) { foreach ($subscribers as $key => $subscriber) {
// code...
$logManager->write("[NOTIFICATION] SENDING NOTIFICATION TO" . $subscriber['id'] . " was executed" . $i); $logManager->write("[NOTIFICATION] SENDING NOTIFICATION TO" . $subscriber['id'] . " was executed" . $i);
$title = 'Automatizace-'.$automation['automation_id']." was executed" . $i; $title = 'Automatizace-'.$automation['automation_id']." was executed" . $i;
$bodyFinal = var_export($subscriber);;
$notification = new Notification($serverKey); $notification = new Notification($serverKey);
$notification->to($subscriber['token']); $notification->to($subscriber['token']);
$notification->notification($title, $bodyFinal , '', ''); $notification->notification($subscriber['id'], '' , '', '');
$notification->send(); $notification->send();
$notification = null; $notification = null;
} }
$logManager->write("[AUTOMATIONS] automation id ". $automation['automation_id'] . " was executed"); $logManager->write("[AUTOMATIONS] automation id ". $automation['automation_id'] . " was executed");
Db::edit('automation', array('executed' => 1), 'WHERE automation_id = ?', array($automation['automation_id'])); Db::edit('automation', array('executed' => 1), 'WHERE automation_id = ?', array($automation['automation_id']));
} else if ($restart) { } else if ($restart) {
$logManager->write("[AUTOMATIONS] automation id ". $automation['automation_id'] . " was restarted"); $logManager->write("[AUTOMATIONS] automation id ". $automation['automation_id'] . " was restarted");
Db::edit('automation', array('executed' => 0), 'WHERE automation_id = ?', array($automation['automation_id'])); Db::edit('automation', array('executed' => 0), 'WHERE automation_id = ?', array($automation['automation_id']));
} }
Db::edit('automation', array('locked' => 0), 'WHERE automation_id = ?', array($automation['automation_id']));
} }