(Notification) La aplicación crashea cuando se abre una notificación luego de derivar a un subproceso de tipo sincrono

HOR-998
(Notification) La aplicación crashea cuando se abre una notificación luego de derivar a un subproceso de tipo sincrono

HOR-998
(Notification) La aplicación crashea cuando se abre una notificación luego de derivar a un subproceso de tipo sincrono
This commit is contained in:
Dheeyi William
2016-06-27 12:10:04 -04:00
parent 7aac0a3712
commit b90c4555bb
4 changed files with 98 additions and 116 deletions

View File

@@ -1401,6 +1401,7 @@ class Derivation
{ {
$iAppThreadIndex = $appFields['DEL_THREAD']; $iAppThreadIndex = $appFields['DEL_THREAD'];
$delType = 'NORMAL'; $delType = 'NORMAL';
$sendNotificationsMobile = false;
if (is_numeric( $nextDel['DEL_PRIORITY'] )) { if (is_numeric( $nextDel['DEL_PRIORITY'] )) {
$nextDel['DEL_PRIORITY'] = (isset( $nextDel['DEL_PRIORITY'] ) ? ($nextDel['DEL_PRIORITY'] >= 1 && $nextDel['DEL_PRIORITY'] <= 5 ? $nextDel['DEL_PRIORITY'] : '3') : '3'); $nextDel['DEL_PRIORITY'] = (isset( $nextDel['DEL_PRIORITY'] ) ? ($nextDel['DEL_PRIORITY'] >= 1 && $nextDel['DEL_PRIORITY'] <= 5 ? $nextDel['DEL_PRIORITY'] : '3') : '3');
@@ -1523,6 +1524,8 @@ class Derivation
} }
} }
$sendNotificationsMobile = $this->sendNotificationsMobile($aOldFields, $aSP, $aNewCase['INDEX']);
//If not is SYNCHRONOUS derivate one more time //If not is SYNCHRONOUS derivate one more time
if ($aSP['SP_SYNCHRONOUS'] == 0) { if ($aSP['SP_SYNCHRONOUS'] == 0) {
$this->case->setDelInitDate( $currentDelegation['APP_UID'], $iNewDelIndex ); $this->case->setDelInitDate( $currentDelegation['APP_UID'], $iNewDelIndex );
@@ -1553,6 +1556,10 @@ class Derivation
} }
} }
} //end switch } //end switch
if($iNewDelIndex !== 0 && !$sendNotificationsMobile){
$sendNotificationsMobile = $this->sendNotificationsMobile($appFields, $nextDel, $iNewDelIndex);
}
return $iNewDelIndex; return $iNewDelIndex;
} }
@@ -1800,5 +1807,24 @@ class Derivation
} }
} }
} }
/**
* @param $appFields
* @param $nextDel
* @param $iNewDelIndex
* @return bool
*/
private function sendNotificationsMobile($appFields, $nextDel, $iNewDelIndex)
{
try {
$notificationMobile = new \ProcessMaker\BusinessModel\Light\NotificationDevice();
if ($notificationMobile->checkMobileNotifications()) {
$notificationMobile->routeCaseNotificationDevice($appFields, $nextDel, $iNewDelIndex);
}
return true;
} catch (Exception $e) {
\G::log(G::loadTranslation('ID_NOTIFICATION_ERROR') . '|' . $e->getMessage(), PATH_DATA, "mobile.log");
}
}
} }

View File

@@ -2518,20 +2518,6 @@ class wsBase
$oCase->sendNotifications( $appdel['TAS_UID'], $nextDelegations, $appFields['APP_DATA'], $caseId, $delIndex, $sFromName ); $oCase->sendNotifications( $appdel['TAS_UID'], $nextDelegations, $appFields['APP_DATA'], $caseId, $delIndex, $sFromName );
// Send notifications Mobile - Start
try {
$notificationMobile = new \ProcessMaker\BusinessModel\Light\NotificationDevice();
if ($notificationMobile->checkMobileNotifications()) {
$oLight = new \ProcessMaker\BusinessModel\Light();
$nextIndex = $oLight->getInformationDerivatedCase($appFields['APP_UID'], $delIndex);
$notificationMobile->routeCaseNotification($userId, $_SESSION["PROCESS"], $appdel['TAS_UID'],
$appFields, $nextDelegations, $nextIndex, $delIndex);
}
} catch (Exception $e) {
\G::log(G::loadTranslation( 'ID_NOTIFICATION_ERROR' ) . '|' . $e->getMessage() , PATH_DATA, "mobile.log");
}
// Send notifications Mobile - End
//Save data - Start //Save data - Start
//$appFields = $oCase->loadCase($caseId); //$appFields = $oCase->loadCase($caseId);
//$oCase->updateCase($caseId, $appFields); //$oCase->updateCase($caseId, $appFields);

View File

@@ -194,21 +194,6 @@ try {
G::SendTemporalMessage( G::loadTranslation( 'ID_NOTIFICATION_ERROR' ) . ' - ' . $e->getMessage(), 'warning', 'string', null, '100%' ); G::SendTemporalMessage( G::loadTranslation( 'ID_NOTIFICATION_ERROR' ) . ' - ' . $e->getMessage(), 'warning', 'string', null, '100%' );
} }
// Send notifications - End // Send notifications - End
// Send notifications Mobile - Start
try {
$notificationMobile = new \ProcessMaker\BusinessModel\Light\NotificationDevice();
if ($notificationMobile->checkMobileNotifications()) {
$oLight = new \ProcessMaker\BusinessModel\Light();
$nextIndex = $oLight->getInformationDerivatedCase($appFields['APP_UID'], $appFields['DEL_INDEX']);
$notificationMobile->routeCaseNotification($_SESSION['USER_LOGGED'], $_SESSION['PROCESS'], $_SESSION['TASK'],
$appFields, $_POST['form']['TASKS'], $nextIndex, $appFields['DEL_INDEX']);
}
} catch (Exception $e) {
\G::log(G::loadTranslation( 'ID_NOTIFICATION_ERROR' ) . '|' . $e->getMessage() , PATH_DATA, "mobile.log");
}
// Send notifications Mobile - End
// Events - Start // Events - Start
$oEvent = new Event(); $oEvent = new Event();

View File

@@ -154,107 +154,92 @@ class NotificationDevice
} }
/** /**
* Send Message each user id * @param $appFields
* * @param $nextDel
* @param array $request_data * @param $iNewDelIndex
* @author Ronald Quenta <ronald.quenta@processmaker.com> * @return array
* * @throws \Exception
*/ */
public function routeCaseNotification($currentUserId, $processId, $currentTaskId, $appFields, $aTasks, public function routeCaseNotificationDevice($appFields, $nextDel, $iNewDelIndex)
$nextIndex, $currentDelIndex)
{ {
try { try {
$response = array(); $response = array();
$typeList = 'todo'; $typeList = 'todo';
foreach ($aTasks as $aTask) { $arrayTaskUser = array();
$arrayTaskUser = array(); switch ($nextDel["TAS_ASSIGN_TYPE"]) {
switch ($aTask["TAS_ASSIGN_TYPE"]) { case "SELF_SERVICE":
case "SELF_SERVICE": $arrayTaskUser = $this->getTaskUserSelfService($nextDel["TAS_UID"], $appFields);
$arrayTaskUser = $this->getTaskUserSelfService($aTask["TAS_UID"], $appFields); $typeList = 'unassigned';
$typeList = 'unassigned'; break;
break; default:
default: if (isset($nextDel["USR_UID"]) && !empty($nextDel["USR_UID"])) {
if (isset($aTask["USR_UID"]) && !empty($aTask["USR_UID"])) { $arrayTaskUser = $nextDel["USR_UID"];
$arrayTaskUser = $aTask["USR_UID"]; }
} break;
break; }
$userIds = $arrayTaskUser;
$message = '#' . $appFields['APP_NUMBER'] . ' : ' . $appFields['APP_TITLE'];
$data = array(
'processId' => $appFields['PRO_UID'],
'taskId' => $nextDel["TAS_UID"],
'caseId' => $appFields['APP_UID'],
'caseTitle' => $appFields['APP_TITLE'],
'delIndex' => $iNewDelIndex,
'typeList' => $typeList
);
if ($userIds) {
$oNoti = new \NotificationDevice();
if (is_array($userIds)) {
$devices = $oNoti->loadUsersArrayId($userIds);
} else {
$devices = $oNoti->loadByUsersId($userIds);
$lists = new \ProcessMaker\BusinessModel\Lists();
$counter = $lists->getCounters($userIds);
$light = new \ProcessMaker\Services\Api\Light();
$result = $light->parserCountersCases($counter);
$data['counters'] = $result;
} }
$delIndex = null; $devicesAndroidIds = array();
foreach ($nextIndex as $nIndex) { $devicesAppleIds = array();
if ($aTask['TAS_UID'] == $nIndex['TAS_UID']) { foreach ($devices as $dev) {
$delIndex = $nIndex['DEL_INDEX']; switch ($dev['DEV_TYPE']) {
break; case "apple":
$devicesAppleIds[] = $dev['DEV_REG_ID'];
break;
case "android":
$devicesAndroidIds[] = $dev['DEV_REG_ID'];
break;
} }
} }
if (count($devicesAppleIds) > 0) {
$userIds = $arrayTaskUser; $arrayData = array();
$message = '#'. $appFields['APP_NUMBER'] . ' : '.$appFields['APP_TITLE']; $arrayData['NOT_FROM'] = $appFields['APP_CUR_USER'];
$data = array( $arrayData['DEV_TYPE'] = 'apple';
'processId' => $processId, $arrayData['DEV_UID'] = serialize($devicesAppleIds);
'taskId' => $aTask["TAS_UID"], $arrayData['NOT_MSG'] = $message;
'caseId' => $appFields['APP_UID'], $arrayData['NOT_DATA'] = serialize($data);
'caseTitle' => $appFields['APP_TITLE'], $arrayData['NOT_STATUS'] = "pending";
'delIndex' => $delIndex, $notQueue = new \NotificationQueue();
'typeList' => $typeList $notQueue->create($arrayData);
); }
if (count($devicesAndroidIds) > 0) {
if ($userIds) { $arrayData = array();
$oNoti = new \NotificationDevice(); $arrayData['NOT_FROM'] = $appFields['APP_CUR_USER'];
$devices = array(); $arrayData['DEV_TYPE'] = 'android';
if (is_array($userIds)) { $arrayData['DEV_UID'] = serialize($devicesAndroidIds);
$devices = $oNoti->loadUsersArrayId($userIds); $arrayData['NOT_MSG'] = $message;
} else { $arrayData['NOT_DATA'] = serialize($data);
$devices = $oNoti->loadByUsersId($userIds); $arrayData['NOT_STATUS'] = "pending";
$lists = new \ProcessMaker\BusinessModel\Lists(); $notQueue = new \NotificationQueue();
$counter = $lists->getCounters($userIds); $notQueue->create($arrayData);
$light = new \ProcessMaker\Services\Api\Light();
$result = $light->parserCountersCases($counter);
$data['counters'] = $result;
}
$devicesAndroidIds = array();
$devicesAppleIds = array();
foreach ($devices as $dev) {
switch ($dev['DEV_TYPE']) {
case "apple":
$devicesAppleIds[] = $dev['DEV_REG_ID'];
break;
case "android":
$devicesAndroidIds[] = $dev['DEV_REG_ID'];
break;
}
}
$isExistNextNotifications = $oNoti->isExistNextNotification($appFields['APP_UID'],
$currentDelIndex);
if (count($devicesAppleIds) > 0 && $isExistNextNotifications) {
$arrayData = array();
$arrayData['NOT_FROM'] = $currentUserId;
$arrayData['DEV_TYPE'] = 'apple';
$arrayData['DEV_UID'] = serialize($devicesAppleIds);
$arrayData['NOT_MSG'] = $message;
$arrayData['NOT_DATA'] = serialize($data);
$arrayData['NOT_STATUS'] = "pending";
$notQueue = new \NotificationQueue();
$notQueue->create($arrayData);
}
if (count($devicesAndroidIds) > 0 && $isExistNextNotifications) {
$arrayData = array();
$arrayData['NOT_FROM'] = $currentUserId;
$arrayData['DEV_TYPE'] = 'android';
$arrayData['DEV_UID'] = serialize($devicesAndroidIds);
$arrayData['NOT_MSG'] = $message;
$arrayData['NOT_DATA'] = serialize($data);
$arrayData['NOT_STATUS'] = "pending";
$notQueue = new \NotificationQueue();
$notQueue->create($arrayData);
}
} }
} }
} catch (\Exception $e) { } catch (\Exception $e) {
throw new \Exception($e->getMessage(), Api::STAT_APP_EXCEPTION); throw new \Exception($e->getMessage(), Api::STAT_APP_EXCEPTION);
} }
return $response; return $response;
} }