From 91da0d6ea4d1886bd99ee64e6997d1abbd977b17 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Tue, 30 Apr 2019 10:39:54 -0400 Subject: [PATCH] PMC-748 --- workflow/engine/classes/Cases.php | 10 +++++----- .../engine/src/ProcessMaker/Util/helpers.php | 20 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/workflow/engine/classes/Cases.php b/workflow/engine/classes/Cases.php index deba3d144..85f17b524 100644 --- a/workflow/engine/classes/Cases.php +++ b/workflow/engine/classes/Cases.php @@ -3541,19 +3541,19 @@ class Cases */ if ($oPMScript->executedOn() === $oPMScript::AFTER_ROUTING) { //Get the variables changed with the trigger - $fieldsTrigger = arrayDiffRecursive($appDataAfterTrigger, $fieldsCase); + $fieldsTrigger = getDiffBetweenModifiedVariables($appDataAfterTrigger, $fieldsCase); + $collection = collect($fieldsCase); + $merged = $collection->merge($fieldsTrigger); + //Merge the appData with variables changed + $fieldsCase = $merged->all(); //We will be load the last appData because: //Other thread execution can be changed the variables $appUid = !empty($fieldsCase['APPLICATION']) ? $fieldsCase['APPLICATION'] : ''; - //Save the fields changed in the trigger if (!$varInAfterRouting && !empty($fieldsTrigger)) { $varInAfterRouting = true; } - - //Merge the appData with variables changed - $fieldsCase = array_merge($fieldsCase, $fieldsTrigger); } else { $fieldsCase = $appDataAfterTrigger; } diff --git a/workflow/engine/src/ProcessMaker/Util/helpers.php b/workflow/engine/src/ProcessMaker/Util/helpers.php index 58afa158e..b3d93a2ae 100644 --- a/workflow/engine/src/ProcessMaker/Util/helpers.php +++ b/workflow/engine/src/ProcessMaker/Util/helpers.php @@ -401,27 +401,27 @@ function verifyCsrfToken($request) } /** - * Get the difference between to multidimensional array + * Get the difference between to arrays + * If the element is an array we will to keep the value from $array1 + * If the element is an object we will to keep the value from $array1 * * @param array $array1 * @param array $array2 * * @return array -*/ -function arrayDiffRecursive(array $array1, array $array2) + */ +function getDiffBetweenModifiedVariables(array $array1, array $array2) { $difference = []; foreach ($array1 as $key => $value) { if (is_array($value)) { - if (!isset($array2[$key])) { + if ($value !== $array2[$key]) { $difference[$key] = $value; - } elseif (!is_array($array2[$key])) { + } + } elseif (is_object($value)) { + // When using ===, it means object variables are identical and they refer to the same instance of the same class. + if ($value != $array2[$key]) { $difference[$key] = $value; - } else { - $new_diff = arrayDiffRecursive($value, $array2[$key]); - if (!empty($new_diff)) { - $difference[$key] = $new_diff; - } } } elseif (!isset($array2[$key]) || $array2[$key] != $value) { $difference[$key] = $value;