PMCORE-2195 Migrate to queue job - Cron File: sendnotificationscron.php
This commit is contained in:
committed by
Julio Cesar Laura Avendaño
parent
0020d75ca3
commit
5bee4352b5
@@ -16,6 +16,9 @@ use Exception;
|
||||
use G;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use ldapadvancedClassCron;
|
||||
use NotificationQueue;
|
||||
use ProcessMaker\BusinessModel\Light\PushMessageAndroid;
|
||||
use ProcessMaker\BusinessModel\Light\PushMessageIOS;
|
||||
use ProcessMaker\Core\JobsManager;
|
||||
use ProcessMaker\Plugins\PluginRegistry;
|
||||
use Propel;
|
||||
@@ -488,4 +491,56 @@ class Task
|
||||
};
|
||||
$this->runTask($job);
|
||||
}
|
||||
|
||||
/**
|
||||
* This execute the sending of notifications.
|
||||
*/
|
||||
function sendNotifications()
|
||||
{
|
||||
$job = function() {
|
||||
try {
|
||||
$this->setExecutionMessage("Resending Notifications");
|
||||
$this->setExecutionResultMessage("PROCESSING");
|
||||
$notQueue = new NotificationQueue();
|
||||
$notQueue->checkIfCasesOpenForResendingNotification();
|
||||
$notificationsAndroid = $notQueue->loadStatusDeviceType('pending', 'android');
|
||||
if ($notificationsAndroid) {
|
||||
$this->setExecutionMessage("|-- Send Android's Notifications");
|
||||
$n = 0;
|
||||
foreach ($notificationsAndroid as $key => $item) {
|
||||
$notification = new PushMessageAndroid();
|
||||
$notification->setSettingNotification();
|
||||
$notification->setDevices(unserialize($item['DEV_UID']));
|
||||
$response['android'] = $notification->send($item['NOT_MSG'], unserialize($item['NOT_DATA']));
|
||||
$notQueue = new NotificationQueue();
|
||||
$notQueue->changeStatusSent($item['NOT_UID']);
|
||||
$n += $notification->getNumberDevices();
|
||||
}
|
||||
$this->setExecutionResultMessage("Processed $n");
|
||||
}
|
||||
$notificationsApple = $notQueue->loadStatusDeviceType('pending', 'apple');
|
||||
if ($notificationsApple) {
|
||||
$this->setExecutionMessage("|-- Send Apple Notifications");
|
||||
$n = 0;
|
||||
foreach ($notificationsApple as $key => $item) {
|
||||
$notification = new PushMessageIOS();
|
||||
$notification->setSettingNotification();
|
||||
$notification->setDevices(unserialize($item['DEV_UID']));
|
||||
$response['apple'] = $notification->send($item['NOT_MSG'], unserialize($item['NOT_DATA']));
|
||||
$notQueue = new NotificationQueue();
|
||||
$notQueue->changeStatusSent($item['NOT_UID']);
|
||||
$n += $notification->getNumberDevices();
|
||||
}
|
||||
$this->setExecutionResultMessage("Processed $n");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->setExecutionResultMessage("WITH ERRORS", "error");
|
||||
if ($this->asynchronous === false) {
|
||||
eprintln(" '-" . $e->getMessage(), "red");
|
||||
}
|
||||
$this->saveLog("ExecuteSendNotifications", "error", "Error when sending notifications " . $e->getMessage());
|
||||
}
|
||||
};
|
||||
$this->runTask($job);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user