PMC-151
This commit is contained in:
@@ -2069,57 +2069,72 @@ class WsBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a new case impersonating a user who has the proper privileges to create new cases
|
* Creates a new case impersonating a user who has the proper privileges to create new cases
|
||||||
*
|
*
|
||||||
* @param string $processId
|
* @param string $processId
|
||||||
* @param string $userId
|
* @param string $userId
|
||||||
* @param string $variables
|
* @param array $variables, that are set in the new case
|
||||||
* @param string $taskId , must be in the starting group.
|
* @param string $taskId, must be in the starting group.
|
||||||
*
|
*
|
||||||
* @return $result will return an object
|
* @return object
|
||||||
|
*
|
||||||
|
* @see PMFNewCaseImpersonate/class.pmFunctions.php on
|
||||||
|
* @link https://wiki.processmaker.com/3.1/ProcessMaker_Functions#PMFNewCaseImpersonate.28.29
|
||||||
|
*
|
||||||
|
* @see doPostCaseImpersonate/Api/Cases on
|
||||||
|
* @link https://wiki.processmaker.com/3.2/REST_API_Cases/Cases#New_Case_Impersonate_User:_POST_.2Fcases.2Fimpersonate
|
||||||
|
*
|
||||||
|
* @see NewCaseImpersonate/soap2.php on
|
||||||
|
* @link https://wiki.processmaker.com/3.0/ProcessMaker_WSDL_Web_Services#newCaseImpersonate.28.29
|
||||||
*/
|
*/
|
||||||
public function newCaseImpersonate($processId, $userId, $variables, $taskId = '')
|
public function newCaseImpersonate($processId, $userId, $variables, $taskId = '')
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (is_array($variables)) {
|
$g = new G();
|
||||||
if (count($variables) > 0) {
|
$g->sessionVarSave();
|
||||||
$c = count($variables);
|
|
||||||
$Fields = $variables;
|
|
||||||
} else {
|
|
||||||
if ($c == 0) {
|
|
||||||
$result = new WsResponse(10, G::loadTranslation('ID_ARRAY_VARIABLES_EMPTY'));
|
|
||||||
|
|
||||||
return $result;
|
$c = count($variables);
|
||||||
}
|
if (is_array($variables)) {
|
||||||
|
if ($c > 0) {
|
||||||
|
$fieldsVariables = $variables;
|
||||||
|
} elseif ($c === 0) {
|
||||||
|
$result = new WsResponse(10, G::loadTranslation('ID_ARRAY_VARIABLES_EMPTY'));
|
||||||
|
$g->sessionVarRestore();
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$result = new WsResponse(10, G::loadTranslation('ID_VARIABLES_PARAM_NOT_ARRAY'));
|
$result = new WsResponse(10, G::loadTranslation('ID_VARIABLES_PARAM_NOT_ARRAY'));
|
||||||
|
$g->sessionVarRestore();
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
$processes = new Processes();
|
$processes = new Processes();
|
||||||
|
|
||||||
if (!$processes->processExists($processId)) {
|
if (!$processes->processExists($processId)) {
|
||||||
$result = new WsResponse(11, G::loadTranslation('ID_INVALID_PROCESS') . " " . $processId . "!!");
|
$result = new WsResponse(11, G::loadTranslation('ID_INVALID_PROCESS') . " " . $processId . "!!");
|
||||||
|
$g->sessionVarRestore();
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = new Users();
|
$user = new Users();
|
||||||
|
|
||||||
if (!$user->userExists($userId)) {
|
if (!$user->userExists($userId)) {
|
||||||
$result = new WsResponse(11, G::loadTranslation('ID_USER_NOT_REGISTERED') . " " . $userId . "!!");
|
$result = new WsResponse(11, G::loadTranslation('ID_USER_NOT_REGISTERED') . " " . $userId . "!!");
|
||||||
|
$g->sessionVarRestore();
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
} else {
|
||||||
|
$user->load($userId);
|
||||||
|
$userName = $user->getUsrUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
$oCase = new Cases();
|
$caseInstance = new Cases();
|
||||||
|
|
||||||
$numTasks = 0;
|
$numTasks = 0;
|
||||||
if ($taskId != '') {
|
if (!empty($taskId)) {
|
||||||
$aTasks = $processes->getStartingTaskForUser($processId, null);
|
$startTasks = $processes->getStartingTaskForUser($processId, null);
|
||||||
foreach ($aTasks as $task) {
|
foreach ($startTasks as $task) {
|
||||||
if ($task['TAS_UID'] == $taskId) {
|
if ($task['TAS_UID'] == $taskId) {
|
||||||
$arrayTask[0]['TAS_UID'] = $taskId;
|
$arrayTask[0]['TAS_UID'] = $taskId;
|
||||||
$numTasks = 1;
|
$numTasks = 1;
|
||||||
@@ -2130,38 +2145,47 @@ class WsBase
|
|||||||
$numTasks = count($arrayTask);
|
$numTasks = count($arrayTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($numTasks == 1) {
|
if ($numTasks === 1) {
|
||||||
$case = $oCase->startCase($arrayTask[0]['TAS_UID'], $userId);
|
//@todo Find a better way to define session variables
|
||||||
$caseId = $case['APPLICATION'];
|
$_SESSION["PROCESS"] = $processId;
|
||||||
$caseNumber = $case['CASE_NUMBER'];
|
$_SESSION["TASK"] = $arrayTask[0]['TAS_UID'];
|
||||||
|
$_SESSION["USER_LOGGED"] = $userId;
|
||||||
|
$_SESSION["INDEX"] = 1;
|
||||||
|
$_SESSION["USR_USERNAME"] = $userName;
|
||||||
|
|
||||||
$oldFields = $oCase->loadCase($caseId);
|
//Create a newCase
|
||||||
|
$infoCase = $caseInstance->startCase($arrayTask[0]['TAS_UID'], $userId);
|
||||||
$oldFields['APP_DATA'] = array_merge($oldFields['APP_DATA'], $Fields);
|
$_SESSION["APPLICATION"] = $caseId = $infoCase['APPLICATION'];
|
||||||
|
$oldFields = $caseInstance->loadCase($caseId);
|
||||||
$up_case = $oCase->updateCase($caseId, $oldFields);
|
//Merge the data with the $fieldsVariables that are set in the new case
|
||||||
|
$oldFields['APP_DATA'] = array_merge($oldFields['APP_DATA'], $fieldsVariables);
|
||||||
|
|
||||||
|
//Update the case
|
||||||
|
$res = $caseInstance->updateCase($caseId, $oldFields);
|
||||||
$result = new WsResponse(0, G::loadTranslation('ID_COMMAND_EXECUTED_SUCCESSFULLY'));
|
$result = new WsResponse(0, G::loadTranslation('ID_COMMAND_EXECUTED_SUCCESSFULLY'));
|
||||||
|
|
||||||
$result->caseId = $caseId;
|
$result->caseId = $caseId;
|
||||||
$result->caseNumber = $caseNumber;
|
$result->caseNumber = $infoCase['CASE_NUMBER'];
|
||||||
|
$g->sessionVarRestore();
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
} else {
|
} else {
|
||||||
if ($numTasks == 0) {
|
if ($numTasks === 0) {
|
||||||
$result = new WsResponse(12, G::loadTranslation('ID_NO_STARTING_TASK'));
|
$result = new WsResponse(12, G::loadTranslation('ID_NO_STARTING_TASK'));
|
||||||
|
$g->sessionVarRestore();
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($numTasks > 1) {
|
if ($numTasks > 1) {
|
||||||
$result = new WsResponse(13, G::loadTranslation('ID_MULTIPLE_STARTING_TASKS'));
|
$result = new WsResponse(13, G::loadTranslation('ID_MULTIPLE_STARTING_TASKS'));
|
||||||
|
$g->sessionVarRestore();
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$result = new WsResponse(100, $e->getMessage());
|
$result = new WsResponse(100, $e->getMessage());
|
||||||
|
$g->sessionVarRestore();
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -415,6 +415,7 @@ class Light
|
|||||||
|
|
||||||
$oCase = new Cases();
|
$oCase = new Cases();
|
||||||
$Fields = $oCase->loadCase($cas_uid);
|
$Fields = $oCase->loadCase($cas_uid);
|
||||||
|
//@todo Find a better way to define session variables
|
||||||
$_SESSION["APPLICATION"] = $cas_uid;
|
$_SESSION["APPLICATION"] = $cas_uid;
|
||||||
$_SESSION["PROCESS"] = $prj_uid;
|
$_SESSION["PROCESS"] = $prj_uid;
|
||||||
$_SESSION["TASK"] = $act_uid;
|
$_SESSION["TASK"] = $act_uid;
|
||||||
@@ -453,6 +454,7 @@ class Light
|
|||||||
try {
|
try {
|
||||||
$oCase = new Cases();
|
$oCase = new Cases();
|
||||||
$Fields = $oCase->loadCase($app_uid);
|
$Fields = $oCase->loadCase($app_uid);
|
||||||
|
//@todo Find a better way to define session variables
|
||||||
$_SESSION["APPLICATION"] = $app_uid;
|
$_SESSION["APPLICATION"] = $app_uid;
|
||||||
$_SESSION["PROCESS"] = $Fields['PRO_UID'];
|
$_SESSION["PROCESS"] = $Fields['PRO_UID'];
|
||||||
$_SESSION["TASK"] = $tas_uid;
|
$_SESSION["TASK"] = $tas_uid;
|
||||||
|
|||||||
@@ -1038,6 +1038,7 @@ class Light extends Api
|
|||||||
}
|
}
|
||||||
|
|
||||||
$userUid = $this->getUserId();
|
$userUid = $this->getUserId();
|
||||||
|
//@todo Find a better way to define session variables
|
||||||
$_SESSION["APPLICATION"] = $app_uid;
|
$_SESSION["APPLICATION"] = $app_uid;
|
||||||
$_SESSION["PROCESS"] = $pro_uid;
|
$_SESSION["PROCESS"] = $pro_uid;
|
||||||
//$_SESSION["TASK"] = "";
|
//$_SESSION["TASK"] = "";
|
||||||
@@ -2009,6 +2010,7 @@ class Light extends Api
|
|||||||
if ($alreadyRouted) {
|
if ($alreadyRouted) {
|
||||||
throw (new RestException(Api::STAT_APP_EXCEPTION, G::LoadTranslation('ID_CASE_DELEGATION_ALREADY_CLOSED')));
|
throw (new RestException(Api::STAT_APP_EXCEPTION, G::LoadTranslation('ID_CASE_DELEGATION_ALREADY_CLOSED')));
|
||||||
}
|
}
|
||||||
|
//@todo Find a better way to define session variables
|
||||||
$_SESSION["APPLICATION"] = $app_uid;
|
$_SESSION["APPLICATION"] = $app_uid;
|
||||||
$_SESSION["PROCESS"] = $pro_uid;
|
$_SESSION["PROCESS"] = $pro_uid;
|
||||||
$_SESSION["INDEX"] = $app_index;
|
$_SESSION["INDEX"] = $app_index;
|
||||||
|
|||||||
Reference in New Issue
Block a user