This commit is contained in:
Julio Cesar Laura Avendaño
2019-07-01 11:49:26 -04:00
parent 6e9247fdb8
commit e486b40906
14 changed files with 106 additions and 36 deletions

View File

@@ -1691,7 +1691,7 @@ class G
* @fn() Evaluate string with the function "fn" * @fn() Evaluate string with the function "fn"
* @author David Callizaya <calidavidx21@hotmail.com> * @author David Callizaya <calidavidx21@hotmail.com>
*/ */
public static function replaceDataField($sqlString, $result, $DBEngine = 'mysql') public static function replaceDataField($sqlString, $result, $DBEngine = 'mysql', $recursive = true)
{ {
if (!is_array($result)) { if (!is_array($result)) {
$result = array(); $result = array();
@@ -1748,12 +1748,12 @@ class G
} }
//Non-quoted //Non-quoted
if (($match[1][$r][0] == '#') && (isset($result[$match[2][$r][0]]))) { 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; continue;
} }
//Non-quoted = //Non-quoted =
if (($match[1][$r][0] == '=') && (isset($result[$match[2][$r][0]]))) { 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; continue;
} }
//Objects attributes //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; return $sContent;
} }

View File

@@ -27,9 +27,10 @@ class ReplaceDataFieldTest extends TestCase
]; ];
$dbEngine = 'mysql'; $dbEngine = 'mysql';
$recursive = false;
// Replace variables in the string // Replace variables in the string, $recursive is false because is don't needed replace recursively the same value
$stringToCheck = G::replaceDataField($string, $result, $dbEngine); $stringToCheck = G::replaceDataField($string, $result, $dbEngine, $recursive);
// Assert the @qq is not being set as an empty value // Assert the @qq is not being set as an empty value
$this->assertRegExp("/asa@qq.fds/", $stringToCheck); $this->assertRegExp("/asa@qq.fds/", $stringToCheck);
@@ -41,9 +42,10 @@ class ReplaceDataFieldTest extends TestCase
]; ];
$dbEngine = 'mysql'; $dbEngine = 'mysql';
$recursive = false;
// Replace variables in the string // Replace variables in the string, $recursive is false because is don't needed replace recursively the same value
$stringToCheck = G::replaceDataField($string, $result, $dbEngine); $stringToCheck = G::replaceDataField($string, $result, $dbEngine, $recursive);
// Assert the @qstring is not being set as an empty value // Assert the @qstring is not being set as an empty value
$this->assertRegExp("/@qstring/", $stringToCheck); $this->assertRegExp("/@qstring/", $stringToCheck);
@@ -72,9 +74,10 @@ class ReplaceDataFieldTest extends TestCase
]; ];
$dbEngine = 'mysql'; $dbEngine = 'mysql';
$recursive = false;
// Replace variables in the string // Replace variables in the string, $recursive is false because is don't needed replace recursively the same value
$stringToCheck = G::replaceDataField($string, $result, $dbEngine); $stringToCheck = G::replaceDataField($string, $result, $dbEngine, $recursive);
// Assert the @qq is not being set as an empty value // Assert the @qq is not being set as an empty value
$this->assertRegExp("/asa@qq.fds/", $stringToCheck); $this->assertRegExp("/asa@qq.fds/", $stringToCheck);
@@ -86,11 +89,80 @@ class ReplaceDataFieldTest extends TestCase
]; ];
$dbEngine = 'mysql'; $dbEngine = 'mysql';
$recursive = false;
// Replace variables in the string // Replace variables in the string, $recursive is false because is don't needed replace recursively the same value
$stringToCheck = G::replaceDataField($string, $result, $dbEngine); $stringToCheck = G::replaceDataField($string, $result, $dbEngine, $recursive);
// Assert the @qstring is not being set as an empty value // Assert the @qstring is not being set as an empty value
$this->assertRegExp("/@qstring/", $stringToCheck); $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);
}
} }

View File

@@ -110,7 +110,7 @@ class ActionsByEmailCoreClass extends PMPlugin
} }
if ($email != '') { 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 == ''){ if($subject == ''){
$subject = $caseFields['APP_TITLE']; $subject = $caseFields['APP_TITLE'];
} }

View File

@@ -628,7 +628,7 @@ class Cases
$task = TaskPeer::retrieveByPk($currentDelegations[$r]->getTasUid()); $task = TaskPeer::retrieveByPk($currentDelegations[$r]->getTasUid());
$caseLabel = $task->$getTasDef(); $caseLabel = $task->$getTasDef();
if ($caseLabel != '') { if ($caseLabel != '') {
$appLabel = G::replaceDataField($caseLabel, $aAppData); $appLabel = G::replaceDataField($caseLabel, $aAppData, 'mysql', false);
break; break;
} }
} }
@@ -686,7 +686,7 @@ class Cases
//Get the case title //Get the case title
$tasDefTitle = trim($row['TAS_DEF_TITLE']); $tasDefTitle = trim($row['TAS_DEF_TITLE']);
if (!empty($tasDefTitle) && !$flagTitle) { if (!empty($tasDefTitle) && !$flagTitle) {
$newAppProperty = G::replaceDataField($tasDefTitle, $lastFieldsCase); $newAppProperty = G::replaceDataField($tasDefTitle, $lastFieldsCase, 'mysql', false);
$res['APP_TITLE'] = $newAppProperty; $res['APP_TITLE'] = $newAppProperty;
if (!(isset($currentValue) && ($currentValue == $tasDefTitle))) { if (!(isset($currentValue) && ($currentValue == $tasDefTitle))) {
$newValues['APP_TITLE'] = $newAppProperty; $newValues['APP_TITLE'] = $newAppProperty;
@@ -696,7 +696,7 @@ class Cases
//Get the case description //Get the case description
$tasDefDescription = trim($row['TAS_DEF_DESCRIPTION']); $tasDefDescription = trim($row['TAS_DEF_DESCRIPTION']);
if (!empty($tasDefDescription) && !$flagDescription) { if (!empty($tasDefDescription) && !$flagDescription) {
$newAppProperty = G::replaceDataField($tasDefDescription, $lastFieldsCase); $newAppProperty = G::replaceDataField($tasDefDescription, $lastFieldsCase, 'mysql', false);
$res['APP_DESCRIPTION'] = $newAppProperty; $res['APP_DESCRIPTION'] = $newAppProperty;
if (!(isset($currentValue) && ($currentValue == $tasDefDescription))) { if (!(isset($currentValue) && ($currentValue == $tasDefDescription))) {
$newValues['APP_DESCRIPTION'] = $newAppProperty; $newValues['APP_DESCRIPTION'] = $newAppProperty;
@@ -5441,7 +5441,7 @@ class Cases
switch ($typeSend) { switch ($typeSend) {
case 'LAST': case 'LAST':
if (isset($aTaskInfo['TAS_DEF_SUBJECT_MESSAGE']) && $aTaskInfo['TAS_DEF_SUBJECT_MESSAGE'] != '') { 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 { } else {
$sSubject = G::LoadTranslation('ID_MESSAGE_SUBJECT_DERIVATION'); $sSubject = G::LoadTranslation('ID_MESSAGE_SUBJECT_DERIVATION');
} }
@@ -5526,7 +5526,7 @@ class Cases
break; break;
case 'RECEIVE': case 'RECEIVE':
if (isset($aTaskInfo['TAS_RECEIVE_SUBJECT_MESSAGE']) && $aTaskInfo['TAS_RECEIVE_SUBJECT_MESSAGE'] != '') { 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 { } else {
$sSubject = G::LoadTranslation('ID_MESSAGE_SUBJECT_DERIVATION'); $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); @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);
} }
} }

View File

@@ -253,7 +253,7 @@ class PmDynaform
} }
} }
} }
$sql = G::replaceDataField($json->sql, $dtFields); $sql = G::replaceDataField($json->sql, $dtFields, 'mysql', false);
if ($value === "suggest") { if ($value === "suggest") {
$sql = $this->prepareSuggestSql($sql, $json); $sql = $this->prepareSuggestSql($sql, $json);
} }
@@ -715,7 +715,7 @@ class PmDynaform
} }
} }
if ($json->dbConnection !== "" && $json->dbConnection !== "none" && $json->sql !== "") { 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); $dt = $this->getCacheQueryData($json->dbConnection, $sql, $json->type);
$row = isset($dt[0]) ? $dt[0] : []; $row = isset($dt[0]) ? $dt[0] : [];
$index = $json->variable === "" ? $json->id : $json->variable; $index = $json->variable === "" ? $json->id : $json->variable;

View File

@@ -1750,7 +1750,7 @@ function PMFGenerateOutputDocument ($outputID, $sApplication = null, $index = nu
//The $_GET['UID'] variable is used when a process executes. //The $_GET['UID'] variable is used when a process executes.
//$_GET['UID']=($aOD['OUT_DOC_VERSIONING'])?$_GET['UID']:$aOD['OUT_DOC_UID']; //$_GET['UID']=($aOD['OUT_DOC_VERSIONING'])?$_GET['UID']:$aOD['OUT_DOC_UID'];
//$sUID = ($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/AppFolder.php';
require_once 'classes/model/AppDocument.php'; require_once 'classes/model/AppDocument.php';

View File

@@ -706,7 +706,7 @@ class PMScript
try { try {
$cnn = Propel::getConnection($varInfo["VAR_DBCONNECTION"]); $cnn = Propel::getConnection($varInfo["VAR_DBCONNECTION"]);
$stmt = $cnn->createStatement(); $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); $rs = $stmt->executeQuery($sql, \ResultSet::FETCHMODE_NUM);
while ($rs->next()) { while ($rs->next()) {
$row = $rs->getRow(); $row = $rs->getRow();

View File

@@ -1735,7 +1735,7 @@ class AppCacheView extends BaseAppCacheView
$arrayAppField = $app->Load($appcvAppUid); $arrayAppField = $app->Load($appcvAppUid);
$appTitle = (!empty($appTitle))? $appTitle : "#" . $arrayAppField["APP_NUMBER"]; $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) { if (isset($arrayAppField["APP_TITLE"]) && $arrayAppField["APP_TITLE"] != $appTitleNew) {
//Updating the value in content, where... //Updating the value in content, where...

View File

@@ -145,8 +145,7 @@ class AppFolder extends BaseAppFolder
$oApplication = new Application(); $oApplication = new Application();
$appFields = $oApplication->Load( $sessionID ); $appFields = $oApplication->Load( $sessionID );
$folderPathParsed = G::replaceDataField( $folderPath, $appFields ); $folderPathParsed = G::replaceDataField( $folderPath, unserialize( $appFields['APP_DATA'] ), 'mysql', false );
$folderPathParsed = G::replaceDataField( $folderPath, unserialize( $appFields['APP_DATA'] ) );
$folderPathParsedArray = explode( "/", $folderPathParsed ); $folderPathParsedArray = explode( "/", $folderPathParsed );
$folderRoot = "/"; //Always starting from Root $folderRoot = "/"; //Always starting from Root
foreach ($folderPathParsedArray as $folderName) { foreach ($folderPathParsedArray as $folderName) {
@@ -174,8 +173,7 @@ class AppFolder extends BaseAppFolder
$oApplication = new Application(); $oApplication = new Application();
$appFields = $oApplication->Load( $sessionID ); $appFields = $oApplication->Load( $sessionID );
$fileTagsParsed = G::replaceDataField( $fileTags, $appFields ); $fileTagsParsed = G::replaceDataField( $fileTags, unserialize( $appFields['APP_DATA'] ), 'mysql', false );
$fileTagsParsed = G::replaceDataField( $fileTags, unserialize( $appFields['APP_DATA'] ) );
return $fileTagsParsed; return $fileTagsParsed;
} }

View File

@@ -213,7 +213,7 @@ class AppNotes extends BaseAppNotes
$configNoteNotification['subject'] = G::LoadTranslation('ID_MESSAGE_SUBJECT_NOTE_NOTIFICATION') . " @#APP_TITLE "; $configNoteNotification['subject'] = G::LoadTranslation('ID_MESSAGE_SUBJECT_NOTE_NOTIFICATION') . " @#APP_TITLE ";
//Define the body for the notification //Define the body for the notification
$configNoteNotification['body'] = $this->getBodyCaseNote($authorName, $noteContent); $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(); $users = new Users();
$recipientsArray = explode(",", $noteRecipients); $recipientsArray = explode(",", $noteRecipients);
@@ -229,7 +229,7 @@ class AppNotes extends BaseAppNotes
$appUid, $appUid,
$delIndex, $delIndex,
WsBase::MESSAGE_TYPE_CASE_NOTE, WsBase::MESSAGE_TYPE_CASE_NOTE,
G::replaceDataField($configNoteNotification['subject'], $fieldCase), G::replaceDataField($configNoteNotification['subject'], $fieldCase, 'mysql', false),
G::buildFrom($configuration, $from), G::buildFrom($configuration, $from),
$to, $to,
$body, $body,

View File

@@ -34,7 +34,7 @@ class ListInbox extends BaseListInbox implements ListInterface
if (isset($data['APP_TITLE'])) { if (isset($data['APP_TITLE'])) {
$oCase = new Cases(); $oCase = new Cases();
$aData = $oCase->loadCase($data["APP_UID"]); $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'])) { if (!empty($data['PRO_UID']) && empty($data['PRO_ID'])) {
$p = new Process(); $p = new Process();
@@ -124,7 +124,7 @@ class ListInbox extends BaseListInbox implements ListInterface
if (isset($data['APP_TITLE'])) { if (isset($data['APP_TITLE'])) {
$oCase = new Cases(); $oCase = new Cases();
$aData = $oCase->loadCase($data["APP_UID"]); $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) { if ($isSelfService) {
$listParticipatedLast = new ListParticipatedLast(); $listParticipatedLast = new ListParticipatedLast();

View File

@@ -23,7 +23,7 @@ $aFields = $oCase->loadCase($appUid);
foreach ($G_FORM->fields as $key => $val) { foreach ($G_FORM->fields as $key => $val) {
if ($fieldName == $val->name) { if ($fieldName == $val->name) {
if ($G_FORM->fields[$key]->sql != null) { 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 = ""; //$coma = "";
//$data1 = ""; //$data1 = "";

View File

@@ -1108,7 +1108,7 @@ class Consolidated
foreach ($G_FORM->fields as $key => $val) { foreach ($G_FORM->fields as $key => $val) {
if ($fieldName == $val->name) { if ($fieldName == $val->name) {
if ($G_FORM->fields[$key]->sql != "") { 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))) { if ((is_array($val->options)) && (!empty($val->options))) {
foreach ($val->options as $key1 => $val1) { foreach ($val->options as $key1 => $val1) {

View File

@@ -522,7 +522,7 @@ class EmailEvent
$emailTo, $emailTo,
'', '',
'', '',
G::replaceDataField($arrayData[5], $arrayApplicationData['APP_DATA']), G::replaceDataField($arrayData[5], $arrayApplicationData['APP_DATA'], 'mysql', false),
$contentFile['prf_filename'], $contentFile['prf_filename'],
[], [],
[], [],