PM-3731 Los registros del equipo tienen que actualizarse con los tokens vigentes

This commit is contained in:
Ronald Quenta
2015-10-08 09:31:09 -04:00
committed by Victor Saisa Lopez
parent 28caced5e2
commit 5d598a875b
2 changed files with 46 additions and 5 deletions

View File

@@ -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)
{

View File

@@ -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;