diff --git a/workflow/engine/classes/model/NotificationDevice.php b/workflow/engine/classes/model/NotificationDevice.php index 07328a910..d4d7ee56f 100644 --- a/workflow/engine/classes/model/NotificationDevice.php +++ b/workflow/engine/classes/model/NotificationDevice.php @@ -44,6 +44,34 @@ class NotificationDevice extends BaseNotificationDevice { return $result; } + public function createOrUpdate(array $arrayData) + { + $cnn = Propel::getConnection(NotificationDevicePeer::DATABASE_NAME); + try { + if (!isset($arrayData['DEV_UID'])) { + $arrayData['DEV_UID'] = G::generateUniqueID(); + $arrayData['DEV_CREATE'] = date('Y-m-d H:i:s'); + $arrayData['DEV_UPDATE'] = date('Y-m-d H:i:s'); + $mNotification = new NotificationDevice(); + } else { + $arrayData['DEV_UPDATE'] = date('Y-m-d H:i:s'); + $mNotification = NotificationDevicePeer::retrieveByPK($arrayData['DEV_UID'],$arrayData['USR_UID']); + } + $mNotification->fromArray($arrayData, BasePeer::TYPE_FIELDNAME); + if ($mNotification->validate()) { + $cnn->begin(); + $result = $mNotification->save(); + $cnn->commit(); + } else { + throw new Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED")); + } + } catch (Exception $e) { + $cnn->rollback(); + throw $e; + } + return isset($arrayData['DEV_UID']) ? $arrayData['DEV_UID'] : 0; + } + public function update(array $arrayData) { diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Light/NotificationDevice.php b/workflow/engine/src/ProcessMaker/BusinessModel/Light/NotificationDevice.php index a74c4db4b..e7ac2fb0d 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Light/NotificationDevice.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Light/NotificationDevice.php @@ -33,12 +33,25 @@ class NotificationDevice G::auditLog("Create", "Device Save: Device ID (".$oNoti->getDevUid().") "); } } else { - $response["devUid"] = $devices[0]['DEV_UID']; - $response["message"] = G:: LoadTranslation("ID_RECORD_EXISTS_IN_TABLE",array($devices[0]['DEV_UID'], "NOTIFICATION_DEVICE")); - //throw new \Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED")); + if($oNoti->remove($devices[0]['DEV_UID'],$devices[0]['USR_UID'])){ + $arrayData['USR_UID'] = $use_uid; + $arrayData['DEV_REG_ID'] = $devices[0]['DEV_REG_ID']; + $arrayData['SYS_LANG'] = $devices[0]['SYS_LANG']; + $arrayData['DEV_TYPE'] = $devices[0]['DEV_TYPE']; + $arrayData['DEV_STATUS'] = 'active'; + + if($devUid = $oNoti->createOrUpdate($arrayData)){ + $response["devUid"] = $devUid; + $response["message"] = G:: LoadTranslation("ID_RECORD_SAVED_SUCCESFULLY"); + G::auditLog("Create", "Device Save: Device ID (".$oNoti->getDevUid().") "); + } else { + throw new \Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED")); + } + } else { + throw new \Exception(G::LoadTranslation("ID_RECORD_DOES_NOT_EXIST")); + } } return $response; - } /** @@ -69,7 +82,7 @@ class NotificationDevice $response = array(); if($oNoti->update($arrayData)){ $response["message"] = G:: LoadTranslation("ID_RECORD_SAVED_SUCCESFULLY"); - G::auditLog("Create", "Device Save: Device ID (".$oNoti->getDevUid().") "); + G::auditLog("Update", "Device Save: Device ID (".$oNoti->getDevUid().") "); } return $response;