ProcessMaker-BE "Process Variable - Endpoint execute-query"
- Se ha implementado el siguiente Endpoint:
POST /api/1.0/{workspace}/project/:prj_uid/process-variable/:var_name/execute-query
This commit is contained in:
@@ -959,7 +959,7 @@ class DynaForm
|
||||
$this->getFieldNameByFormatFieldName("DYN_DESCRIPTION") => $record["DYN_DESCRIPTION"] . "",
|
||||
$this->getFieldNameByFormatFieldName("DYN_TYPE") => $record["DYN_TYPE"] . "",
|
||||
$this->getFieldNameByFormatFieldName("DYN_CONTENT") => $record["DYN_CONTENT"] . "",
|
||||
$this->getFieldNameByFormatFieldName("DYN_VERSION") => $record["DYN_VERSION"] . ""
|
||||
$this->getFieldNameByFormatFieldName("DYN_VERSION") => (int)($record["DYN_VERSION"])
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
|
||||
@@ -191,7 +191,7 @@ class FilesManager
|
||||
}
|
||||
$content = $aData['prf_content'];
|
||||
if (is_string($content)) {
|
||||
if (file_exists(PATH_SEP.$sDirectory)) {
|
||||
if (file_exists($sDirectory)) {
|
||||
$directory = $sMainDirectory. PATH_SEP . $sSubDirectory . $aData['prf_filename'];
|
||||
throw new \Exception(\G::LoadTranslation("ID_EXISTS_FILE", array($directory)));
|
||||
}
|
||||
@@ -393,7 +393,7 @@ class FilesManager
|
||||
* @param string $prfUid {@min 32} {@max 32}
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @access public
|
||||
*/
|
||||
public function deleteProcessFilesManager($sProcessUID, $prfUid)
|
||||
{
|
||||
|
||||
@@ -376,6 +376,119 @@ class Variable
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get required variables in the SQL
|
||||
*
|
||||
* @param string $sql SQL
|
||||
*
|
||||
* return array Return an array with required variables in the SQL
|
||||
*/
|
||||
public function sqlGetRequiredVariables($sql)
|
||||
{
|
||||
try {
|
||||
$arrayVariableRequired = array();
|
||||
|
||||
preg_match_all("/@[@%#\?\x24\=]([A-Za-z_]\w*)/", $sql, $arrayMatch, PREG_SET_ORDER);
|
||||
|
||||
foreach ($arrayMatch as $value) {
|
||||
$arrayVariableRequired[] = $value[1];
|
||||
}
|
||||
|
||||
return $arrayVariableRequired;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if some required variable in the SQL is missing in the variables
|
||||
*
|
||||
* @param string $variableName Variable name
|
||||
* @param string $variableSql SQL
|
||||
* @param array $arrayVariable The variables
|
||||
*
|
||||
* return void Throw exception if some required variable in the SQL is missing in the variables
|
||||
*/
|
||||
public function throwExceptionIfSomeRequiredVariableSqlIsMissingInVariables($variableName, $variableSql, array $arrayVariable)
|
||||
{
|
||||
try {
|
||||
$arrayResult = array_diff(array_unique($this->sqlGetRequiredVariables($variableSql)), array_keys($arrayVariable));
|
||||
|
||||
if (count($arrayResult) > 0) {
|
||||
throw new \Exception(\G::LoadTranslation("ID_PROCESS_VARIABLE_REQUIRED_VARIABLES_FOR_QUERY", array($variableName, implode(", ", $arrayResult))));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all records by execute SQL
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param string $variableName Variable name
|
||||
* @param array $arrayVariable The variables
|
||||
*
|
||||
* return array Return an array with all records
|
||||
*/
|
||||
public function executeSql($processUid, $variableName, array $arrayVariable = array())
|
||||
{
|
||||
try {
|
||||
$arrayRecord = array();
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$process->throwExceptionIfNotExistsProcess($processUid, strtolower("PRJ_UID"));
|
||||
|
||||
//Set data
|
||||
$variableDbConnectionUid = "";
|
||||
$variableSql = "";
|
||||
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_DBCONNECTION);
|
||||
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_SQL);
|
||||
$criteria->add(\ProcessVariablesPeer::PRJ_UID, $processUid, \Criteria::EQUAL);
|
||||
$criteria->add(\ProcessVariablesPeer::VAR_NAME, $variableName, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
if ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$variableDbConnectionUid = $row["VAR_DBCONNECTION"];
|
||||
$variableSql = $row["VAR_SQL"];
|
||||
} else {
|
||||
throw new \Exception(\G::LoadTranslation("ID_PROCESS_VARIABLE_DOES_NOT_EXIST", array(strtolower($this->arrayFieldNameForException["varName"]), $variableName)));
|
||||
}
|
||||
|
||||
//Verify data
|
||||
$this->throwExceptionIfSomeRequiredVariableSqlIsMissingInVariables($variableName, $variableSql, $arrayVariable);
|
||||
|
||||
//Get data
|
||||
$_SESSION["PROCESS"] = $processUid;
|
||||
|
||||
$cnn = \Propel::getConnection(($variableDbConnectionUid . "" != "")? $variableDbConnectionUid : "workflow");
|
||||
$stmt = $cnn->createStatement();
|
||||
|
||||
$rs = $stmt->executeQuery(\G::replaceDataField($variableSql, $arrayVariable), \ResultSet::FETCHMODE_NUM);
|
||||
|
||||
while ($rs->next()) {
|
||||
$row = $rs->getRow();
|
||||
|
||||
$arrayRecord[] = array(
|
||||
strtolower("VALUE") => $row[0],
|
||||
strtolower("TEXT") => $row[1]
|
||||
);
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayRecord;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,4 +107,27 @@ class Variable extends Api
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @url POST /:prj_uid/process-variable/:var_name/execute-query
|
||||
*
|
||||
* @param string $prj_uid {@min 32}{@max 32}
|
||||
* @param string $var_name
|
||||
* @param array $request_data
|
||||
*/
|
||||
public function doPostVariableExecuteSql($prj_uid, $var_name, $request_data)
|
||||
{
|
||||
try {
|
||||
$variable = new \ProcessMaker\BusinessModel\Variable();
|
||||
|
||||
$arrayData = ($request_data != null)? $variable->executeSql($prj_uid, $var_name, $request_data) : $variable->executeSql($prj_uid, $var_name);
|
||||
|
||||
$response = $arrayData;
|
||||
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user