diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index 319fe85f7..7df1fd296 100644 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -1691,7 +1691,7 @@ class G * @fn() Evaluate string with the function "fn" * @author David Callizaya */ - public static function replaceDataField($sqlString, $result, $DBEngine = 'mysql') + public static function replaceDataField($sqlString, $result, $DBEngine = 'mysql', $recursive = true) { if (!is_array($result)) { $result = array(); @@ -1748,12 +1748,12 @@ class G } //Non-quoted if (($match[1][$r][0] == '#') && (isset($result[$match[2][$r][0]]))) { - $__textoEval .= $result[$match[2][$r][0]]; + $__textoEval .= $recursive ? G::replaceDataField($result[$match[2][$r][0]], $result) : $result[$match[2][$r][0]]; continue; } //Non-quoted = if (($match[1][$r][0] == '=') && (isset($result[$match[2][$r][0]]))) { - $__textoEval .= $result[$match[2][$r][0]]; + $__textoEval .= $recursive ? G::replaceDataField($result[$match[2][$r][0]], $result) : $result[$match[2][$r][0]]; continue; } //Objects attributes @@ -1826,7 +1826,7 @@ class G } } } - $strData = $strData . G::replaceDataField($arrayMatch2[2], $aRow); + $strData = $strData . G::replaceDataField($arrayMatch2[2], $aRow, 'mysql', false); } } @@ -1851,7 +1851,7 @@ class G } } - $sContent = G::replaceDataField($sContent, $aFields); + $sContent = G::replaceDataField($sContent, $aFields, 'mysql', false); return $sContent; } diff --git a/tests/unit/gulliver/system/ReplaceDataFieldTest.php b/tests/unit/gulliver/system/ReplaceDataFieldTest.php index 231859f93..f0653c86c 100644 --- a/tests/unit/gulliver/system/ReplaceDataFieldTest.php +++ b/tests/unit/gulliver/system/ReplaceDataFieldTest.php @@ -27,9 +27,10 @@ class ReplaceDataFieldTest extends TestCase ]; $dbEngine = 'mysql'; + $recursive = false; - // Replace variables in the string - $stringToCheck = G::replaceDataField($string, $result, $dbEngine); + // Replace variables in the string, $recursive is false because is don't needed replace recursively the same value + $stringToCheck = G::replaceDataField($string, $result, $dbEngine, $recursive); // Assert the @qq is not being set as an empty value $this->assertRegExp("/asa@qq.fds/", $stringToCheck); @@ -41,9 +42,10 @@ class ReplaceDataFieldTest extends TestCase ]; $dbEngine = 'mysql'; + $recursive = false; - // Replace variables in the string - $stringToCheck = G::replaceDataField($string, $result, $dbEngine); + // Replace variables in the string, $recursive is false because is don't needed replace recursively the same value + $stringToCheck = G::replaceDataField($string, $result, $dbEngine, $recursive); // Assert the @qstring is not being set as an empty value $this->assertRegExp("/@qstring/", $stringToCheck); @@ -72,9 +74,10 @@ class ReplaceDataFieldTest extends TestCase ]; $dbEngine = 'mysql'; + $recursive = false; - // Replace variables in the string - $stringToCheck = G::replaceDataField($string, $result, $dbEngine); + // Replace variables in the string, $recursive is false because is don't needed replace recursively the same value + $stringToCheck = G::replaceDataField($string, $result, $dbEngine, $recursive); // Assert the @qq is not being set as an empty value $this->assertRegExp("/asa@qq.fds/", $stringToCheck); @@ -86,11 +89,80 @@ class ReplaceDataFieldTest extends TestCase ]; $dbEngine = 'mysql'; + $recursive = false; - // Replace variables in the string - $stringToCheck = G::replaceDataField($string, $result, $dbEngine); + // Replace variables in the string, $recursive is false because is don't needed replace recursively the same value + $stringToCheck = G::replaceDataField($string, $result, $dbEngine, $recursive); // Assert the @qstring is not being set as an empty value $this->assertRegExp("/@qstring/", $stringToCheck); } + + /** + * Check that the variable using "@#" will be replaced recursively or not according to the parameters sent + * + * @test + * @covers G::replaceDataField + */ + public function it_should_replace_recursively_a_variable_inside_another_variable_with_hashtag_symbol() + { + // Initialize variables + $string = '@#upload_New'; + $variables = ['upload_New' => "javascript:uploadInputDocument('@#DOC_UID');", + 'DOC_UID' => '1988828025cc89aba0cd2b8079038028']; + + // Set parameters to test the method + $dbEngine = 'mysql'; + $recursive = false; + + // Replace variables in the string, $recursive is false because is don't needed replace recursively the same value + $stringToCheck = G::replaceDataField($string, $variables, $dbEngine, $recursive); + + // The variable @#DOC_UID inside in the variable "@#upload_New" shouldn't be replaced + $this->assertRegExp("/@#DOC_UID/", $stringToCheck); + + // Set parameters to test the method + $dbEngine = 'mysql'; + $recursive = true; + + // Replace variables in the string, $recursive is true because is required replace recursively the same value + $stringToCheck = G::replaceDataField($string, $variables, $dbEngine, $recursive); + + // The variable @#DOC_UID inside in the variable "@#upload_New" should be replaced correctly + $this->assertRegExp("/1988828025cc89aba0cd2b8079038028/", $stringToCheck); + } + + /** + * Check that the variable using "@=" will be replaced recursively or not according to the parameters sent + * + * @test + * @covers G::replaceDataField + */ + public function it_should_replace_recursively_a_variable_inside_another_variable_with_equals_symbol() + { + // Initialize variables + $string = '@=upload_New'; + $variables = ['upload_New' => "javascript:uploadInputDocument('@=DOC_UID');", + 'DOC_UID' => '1988828025cc89aba0cd2b8079038028']; + + // Set parameters to test the method + $dbEngine = 'mysql'; + $recursive = false; + + // Replace variables in the string, $recursive is false because is don't needed replace recursively the same value + $stringToCheck = G::replaceDataField($string, $variables, $dbEngine, $recursive); + + // The variable @=DOC_UID inside in the variable "@=upload_New" shouldn't be replaced + $this->assertRegExp("/@=DOC_UID/", $stringToCheck); + + // Set parameters to test the method + $dbEngine = 'mysql'; + $recursive = true; + + // Replace variables in the string, $recursive is true because is required replace recursively the same value + $stringToCheck = G::replaceDataField($string, $variables, $dbEngine, $recursive); + + // The variable @=DOC_UID inside in the variable "@=upload_New" should be replaced correctly + $this->assertRegExp("/1988828025cc89aba0cd2b8079038028/", $stringToCheck); + } } diff --git a/workflow/engine/classes/ActionsByEmailCoreClass.php b/workflow/engine/classes/ActionsByEmailCoreClass.php index a52f45e44..f013b02f9 100644 --- a/workflow/engine/classes/ActionsByEmailCoreClass.php +++ b/workflow/engine/classes/ActionsByEmailCoreClass.php @@ -110,7 +110,7 @@ class ActionsByEmailCoreClass extends PMPlugin } if ($email != '') { - $subject = G::replaceDataField( $configuration['ABE_SUBJECT_FIELD'], $caseFields['APP_DATA'] ); + $subject = G::replaceDataField( $configuration['ABE_SUBJECT_FIELD'], $caseFields['APP_DATA'], 'mysql', false ); if($subject == ''){ $subject = $caseFields['APP_TITLE']; } diff --git a/workflow/engine/classes/Cases.php b/workflow/engine/classes/Cases.php index 02b69a8c5..0f0fe232d 100644 --- a/workflow/engine/classes/Cases.php +++ b/workflow/engine/classes/Cases.php @@ -628,7 +628,7 @@ class Cases $task = TaskPeer::retrieveByPk($currentDelegations[$r]->getTasUid()); $caseLabel = $task->$getTasDef(); if ($caseLabel != '') { - $appLabel = G::replaceDataField($caseLabel, $aAppData); + $appLabel = G::replaceDataField($caseLabel, $aAppData, 'mysql', false); break; } } @@ -686,7 +686,7 @@ class Cases //Get the case title $tasDefTitle = trim($row['TAS_DEF_TITLE']); if (!empty($tasDefTitle) && !$flagTitle) { - $newAppProperty = G::replaceDataField($tasDefTitle, $lastFieldsCase); + $newAppProperty = G::replaceDataField($tasDefTitle, $lastFieldsCase, 'mysql', false); $res['APP_TITLE'] = $newAppProperty; if (!(isset($currentValue) && ($currentValue == $tasDefTitle))) { $newValues['APP_TITLE'] = $newAppProperty; @@ -696,7 +696,7 @@ class Cases //Get the case description $tasDefDescription = trim($row['TAS_DEF_DESCRIPTION']); if (!empty($tasDefDescription) && !$flagDescription) { - $newAppProperty = G::replaceDataField($tasDefDescription, $lastFieldsCase); + $newAppProperty = G::replaceDataField($tasDefDescription, $lastFieldsCase, 'mysql', false); $res['APP_DESCRIPTION'] = $newAppProperty; if (!(isset($currentValue) && ($currentValue == $tasDefDescription))) { $newValues['APP_DESCRIPTION'] = $newAppProperty; @@ -5441,7 +5441,7 @@ class Cases switch ($typeSend) { case 'LAST': if (isset($aTaskInfo['TAS_DEF_SUBJECT_MESSAGE']) && $aTaskInfo['TAS_DEF_SUBJECT_MESSAGE'] != '') { - $sSubject = G::replaceDataField($aTaskInfo['TAS_DEF_SUBJECT_MESSAGE'], $arrayData); + $sSubject = G::replaceDataField($aTaskInfo['TAS_DEF_SUBJECT_MESSAGE'], $arrayData, 'mysql', false); } else { $sSubject = G::LoadTranslation('ID_MESSAGE_SUBJECT_DERIVATION'); } @@ -5526,7 +5526,7 @@ class Cases break; case 'RECEIVE': if (isset($aTaskInfo['TAS_RECEIVE_SUBJECT_MESSAGE']) && $aTaskInfo['TAS_RECEIVE_SUBJECT_MESSAGE'] != '') { - $sSubject = G::replaceDataField($aTaskInfo['TAS_RECEIVE_SUBJECT_MESSAGE'], $arrayData); + $sSubject = G::replaceDataField($aTaskInfo['TAS_RECEIVE_SUBJECT_MESSAGE'], $arrayData, 'mysql', false); } else { $sSubject = G::LoadTranslation('ID_MESSAGE_SUBJECT_DERIVATION'); } @@ -5674,7 +5674,7 @@ class Cases ) { @copy(PATH_TPL . "mails" . PATH_SEP . G::LoadTranslation('ID_UNASSIGNED_MESSAGE'), $fileTemplate); } - $body2 = G::replaceDataField(file_get_contents($fileTemplate), $arrayData2); + $body2 = G::replaceDataField(file_get_contents($fileTemplate), $arrayData2, 'mysql', false); } } diff --git a/workflow/engine/classes/PmDynaform.php b/workflow/engine/classes/PmDynaform.php index a4b8d5262..a0e52da02 100644 --- a/workflow/engine/classes/PmDynaform.php +++ b/workflow/engine/classes/PmDynaform.php @@ -253,7 +253,7 @@ class PmDynaform } } } - $sql = G::replaceDataField($json->sql, $dtFields); + $sql = G::replaceDataField($json->sql, $dtFields, 'mysql', false); if ($value === "suggest") { $sql = $this->prepareSuggestSql($sql, $json); } @@ -715,7 +715,7 @@ class PmDynaform } } if ($json->dbConnection !== "" && $json->dbConnection !== "none" && $json->sql !== "") { - $sql = G::replaceDataField($json->sql, $data); + $sql = G::replaceDataField($json->sql, $data, 'mysql', false); $dt = $this->getCacheQueryData($json->dbConnection, $sql, $json->type); $row = isset($dt[0]) ? $dt[0] : []; $index = $json->variable === "" ? $json->id : $json->variable; diff --git a/workflow/engine/classes/class.pmFunctions.php b/workflow/engine/classes/class.pmFunctions.php index 31cf411a4..c6c80cf65 100644 --- a/workflow/engine/classes/class.pmFunctions.php +++ b/workflow/engine/classes/class.pmFunctions.php @@ -1750,7 +1750,7 @@ function PMFGenerateOutputDocument ($outputID, $sApplication = null, $index = nu //The $_GET['UID'] variable is used when a process executes. //$_GET['UID']=($aOD['OUT_DOC_VERSIONING'])?$_GET['UID']:$aOD['OUT_DOC_UID']; //$sUID = ($aOD['OUT_DOC_VERSIONING'])?$_GET['UID']:$aOD['OUT_DOC_UID']; - $sFilename = preg_replace( '[^A-Za-z0-9_]', '_', G::replaceDataField( $aOD['OUT_DOC_FILENAME'], $Fields['APP_DATA'] ) ); + $sFilename = preg_replace( '[^A-Za-z0-9_]', '_', G::replaceDataField( $aOD['OUT_DOC_FILENAME'], $Fields['APP_DATA'], 'mysql', false ) ); require_once 'classes/model/AppFolder.php'; require_once 'classes/model/AppDocument.php'; diff --git a/workflow/engine/classes/class.pmScript.php b/workflow/engine/classes/class.pmScript.php index cd4cf8631..e5e301c13 100644 --- a/workflow/engine/classes/class.pmScript.php +++ b/workflow/engine/classes/class.pmScript.php @@ -706,7 +706,7 @@ class PMScript try { $cnn = Propel::getConnection($varInfo["VAR_DBCONNECTION"]); $stmt = $cnn->createStatement(); - $sql = G::replaceDataField($varInfo["VAR_SQL"], $this->aFields); + $sql = G::replaceDataField($varInfo["VAR_SQL"], $this->aFields, 'mysql', false); $rs = $stmt->executeQuery($sql, \ResultSet::FETCHMODE_NUM); while ($rs->next()) { $row = $rs->getRow(); diff --git a/workflow/engine/classes/model/AppCacheView.php b/workflow/engine/classes/model/AppCacheView.php index c2fea04ce..45a669b02 100644 --- a/workflow/engine/classes/model/AppCacheView.php +++ b/workflow/engine/classes/model/AppCacheView.php @@ -1735,7 +1735,7 @@ class AppCacheView extends BaseAppCacheView $arrayAppField = $app->Load($appcvAppUid); $appTitle = (!empty($appTitle))? $appTitle : "#" . $arrayAppField["APP_NUMBER"]; - $appTitleNew = G::replaceDataField($appTitle, unserialize($arrayAppField["APP_DATA"])); + $appTitleNew = G::replaceDataField($appTitle, unserialize($arrayAppField["APP_DATA"]), 'mysql', false); if (isset($arrayAppField["APP_TITLE"]) && $arrayAppField["APP_TITLE"] != $appTitleNew) { //Updating the value in content, where... diff --git a/workflow/engine/classes/model/AppFolder.php b/workflow/engine/classes/model/AppFolder.php index 2fdba2748..3a0acb45a 100644 --- a/workflow/engine/classes/model/AppFolder.php +++ b/workflow/engine/classes/model/AppFolder.php @@ -145,8 +145,7 @@ class AppFolder extends BaseAppFolder $oApplication = new Application(); $appFields = $oApplication->Load( $sessionID ); - $folderPathParsed = G::replaceDataField( $folderPath, $appFields ); - $folderPathParsed = G::replaceDataField( $folderPath, unserialize( $appFields['APP_DATA'] ) ); + $folderPathParsed = G::replaceDataField( $folderPath, unserialize( $appFields['APP_DATA'] ), 'mysql', false ); $folderPathParsedArray = explode( "/", $folderPathParsed ); $folderRoot = "/"; //Always starting from Root foreach ($folderPathParsedArray as $folderName) { @@ -174,8 +173,7 @@ class AppFolder extends BaseAppFolder $oApplication = new Application(); $appFields = $oApplication->Load( $sessionID ); - $fileTagsParsed = G::replaceDataField( $fileTags, $appFields ); - $fileTagsParsed = G::replaceDataField( $fileTags, unserialize( $appFields['APP_DATA'] ) ); + $fileTagsParsed = G::replaceDataField( $fileTags, unserialize( $appFields['APP_DATA'] ), 'mysql', false ); return $fileTagsParsed; } diff --git a/workflow/engine/classes/model/AppNotes.php b/workflow/engine/classes/model/AppNotes.php index a36b13681..6e99dc408 100644 --- a/workflow/engine/classes/model/AppNotes.php +++ b/workflow/engine/classes/model/AppNotes.php @@ -213,7 +213,7 @@ class AppNotes extends BaseAppNotes $configNoteNotification['subject'] = G::LoadTranslation('ID_MESSAGE_SUBJECT_NOTE_NOTIFICATION') . " @#APP_TITLE "; //Define the body for the notification $configNoteNotification['body'] = $this->getBodyCaseNote($authorName, $noteContent); - $body = nl2br(G::replaceDataField($configNoteNotification['body'], $fieldCase)); + $body = nl2br(G::replaceDataField($configNoteNotification['body'], $fieldCase, 'mysql', false)); $users = new Users(); $recipientsArray = explode(",", $noteRecipients); @@ -229,7 +229,7 @@ class AppNotes extends BaseAppNotes $appUid, $delIndex, WsBase::MESSAGE_TYPE_CASE_NOTE, - G::replaceDataField($configNoteNotification['subject'], $fieldCase), + G::replaceDataField($configNoteNotification['subject'], $fieldCase, 'mysql', false), G::buildFrom($configuration, $from), $to, $body, diff --git a/workflow/engine/classes/model/ListInbox.php b/workflow/engine/classes/model/ListInbox.php index 97e21e018..b8e00ace6 100644 --- a/workflow/engine/classes/model/ListInbox.php +++ b/workflow/engine/classes/model/ListInbox.php @@ -34,7 +34,7 @@ class ListInbox extends BaseListInbox implements ListInterface if (isset($data['APP_TITLE'])) { $oCase = new Cases(); $aData = $oCase->loadCase($data["APP_UID"]); - $data['APP_TITLE'] = G::replaceDataField($data['APP_TITLE'], $aData['APP_DATA']); + $data['APP_TITLE'] = G::replaceDataField($data['APP_TITLE'], $aData['APP_DATA'], 'mysql', false); } if (!empty($data['PRO_UID']) && empty($data['PRO_ID'])) { $p = new Process(); @@ -124,7 +124,7 @@ class ListInbox extends BaseListInbox implements ListInterface if (isset($data['APP_TITLE'])) { $oCase = new Cases(); $aData = $oCase->loadCase($data["APP_UID"]); - $data['APP_TITLE'] = G::replaceDataField($data['APP_TITLE'], $aData['APP_DATA']); + $data['APP_TITLE'] = G::replaceDataField($data['APP_TITLE'], $aData['APP_DATA'], 'mysql', false); } if ($isSelfService) { $listParticipatedLast = new ListParticipatedLast(); diff --git a/workflow/engine/methods/cases/proxyDataCombobox.php b/workflow/engine/methods/cases/proxyDataCombobox.php index f35befa5a..44d5aeb61 100644 --- a/workflow/engine/methods/cases/proxyDataCombobox.php +++ b/workflow/engine/methods/cases/proxyDataCombobox.php @@ -23,7 +23,7 @@ $aFields = $oCase->loadCase($appUid); foreach ($G_FORM->fields as $key => $val) { if ($fieldName == $val->name) { if ($G_FORM->fields[$key]->sql != null) { - $sqlQuery = G::replaceDataField($G_FORM->fields[$key]->sql, $aFields ["APP_DATA"]); + $sqlQuery = G::replaceDataField($G_FORM->fields[$key]->sql, $aFields ["APP_DATA"], 'mysql', false); } //$coma = ""; //$data1 = ""; diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Consolidated.php b/workflow/engine/src/ProcessMaker/BusinessModel/Consolidated.php index 45b7b5713..dc867df42 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Consolidated.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Consolidated.php @@ -1108,7 +1108,7 @@ class Consolidated foreach ($G_FORM->fields as $key => $val) { if ($fieldName == $val->name) { if ($G_FORM->fields[$key]->sql != "") { - $sqlQuery = G::replaceDataField($G_FORM->fields[$key]->sql, $aFields ["APP_DATA"]); + $sqlQuery = G::replaceDataField($G_FORM->fields[$key]->sql, $aFields ["APP_DATA"], 'mysql', false); } if ((is_array($val->options)) && (!empty($val->options))) { foreach ($val->options as $key1 => $val1) { diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/EmailEvent.php b/workflow/engine/src/ProcessMaker/BusinessModel/EmailEvent.php index 1ecf359ea..a2dc6f92f 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/EmailEvent.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/EmailEvent.php @@ -522,7 +522,7 @@ class EmailEvent $emailTo, '', '', - G::replaceDataField($arrayData[5], $arrayApplicationData['APP_DATA']), + G::replaceDataField($arrayData[5], $arrayApplicationData['APP_DATA'], 'mysql', false), $contentFile['prf_filename'], [], [],