From 56e8ac9833c46d573baca1d3c384a60ecaa35704 Mon Sep 17 00:00:00 2001 From: "j.buchanan" Date: Mon, 30 Sep 2024 11:45:27 +0100 Subject: [PATCH] Fix #10069 - Fix issue with workflow/report conditions not saving values when moving between modules Add functionality to loop through relationship path to pass in correct module to fixUpFormatting --- modules/AOR_Conditions/AOR_Condition.php | 22 +++++++++++++++++++--- modules/AOR_Reports/aor_utils.php | 12 +++++++++++- modules/AOR_Reports/controller.php | 4 ++-- modules/AOW_Conditions/AOW_Condition.php | 20 ++++++++++++++++++-- 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/modules/AOR_Conditions/AOR_Condition.php b/modules/AOR_Conditions/AOR_Condition.php index eb24f45d815..7e21be20fbc 100755 --- a/modules/AOR_Conditions/AOR_Condition.php +++ b/modules/AOR_Conditions/AOR_Condition.php @@ -91,10 +91,11 @@ public function save_lines($post_data, $parent, $key = '') $j = 0; foreach ((array)$postData as $i => $field) { + $condition_module = $_REQUEST['report_module']; if (!isset($post_data[$key . 'deleted'][$i])) { LoggerManager::getLogger()->warn('AOR Condition trying to save lines but POST data does not contains the key "' . $key . 'deleted' . '" at index: ' . $i); } - + $flow_bean = BeanFactory::newBean($_REQUEST['report_module']); if (isset($post_data[$key . 'deleted'][$i]) && $post_data[$key . 'deleted'][$i] == 1) { $this->mark_deleted($post_data[$key . 'id'][$i]); } else { @@ -112,8 +113,23 @@ public function save_lines($post_data, $parent, $key = '') } } else { if ($field_name == 'value' && $post_data[$key . 'value_type'][$i] === 'Value') { - $post_data[$key . $field_name][$i] = fixUpFormatting($_REQUEST['report_module'], $condition->field, $post_data[$key . $field_name][$i]); - } else { + if (!empty($flow_bean)) { + $condition_relation = $post_data["aor_conditions_module_path"][$i]; + $condition_relation_array = unserialize(base64_decode($condition_relation)); + $rel_module = ''; + foreach ($condition_relation_array as $relate){ + $flow_bean->load_relationship($relate); + if ($flow_bean->$relate) { + $rel_module = $flow_bean->$relate->getRelatedModuleName(); + $flow_bean = BeanFactory::newBean($rel_module); + } + } + + if (!empty($rel_module) && $condition_module !== $rel_module) { + $condition_module = $rel_module; + } + } + $post_data[$key . $field_name][$i] = fixUpFormatting($condition_module, $condition->field, $post_data[$key . $field_name][$i]); } else { if ($field_name == 'parameter') { $post_data[$key . $field_name][$i] = isset($post_data[$key . $field_name][$i]); } else { diff --git a/modules/AOR_Reports/aor_utils.php b/modules/AOR_Reports/aor_utils.php index bb4d5238fb6..f9ec833c26e 100644 --- a/modules/AOR_Reports/aor_utils.php +++ b/modules/AOR_Reports/aor_utils.php @@ -108,9 +108,19 @@ function requestToUserParameters($reportBean = null) } $condition = BeanFactory::getBean('AOR_Conditions', $_REQUEST['parameter_id'][$key]); + $flow_bean = BeanFactory::newBean($reportBean->report_module); + $modulePathArray = unserialize(base64_decode($condition->module_path)); + $rel_module = $reportBean->report_module; + foreach ($modulePathArray as $relate){ + $flow_bean->load_relationship($relate); + if ($flow_bean->$relate) { + $rel_module = $flow_bean->$relate->getRelatedModuleName(); + $flow_bean = BeanFactory::newBean($rel_module); + } + } $value = $_REQUEST['parameter_value'][$key]; if ($reportBean && $condition && !array_key_exists($value, $app_list_strings['date_time_period_list'])) { - $value = fixUpFormatting($reportBean->report_module, $condition->field, $value); + $value = fixUpFormatting($rel_module, $condition->field, $value); } $params[$parameterId] = array( diff --git a/modules/AOR_Reports/controller.php b/modules/AOR_Reports/controller.php index 38493ac8916..e7b3739e0cb 100755 --- a/modules/AOR_Reports/controller.php +++ b/modules/AOR_Reports/controller.php @@ -81,7 +81,7 @@ protected function action_changeReportPage() $offset = !empty($_REQUEST['offset']) ? $_REQUEST['offset'] : 0; $group = !empty($_REQUEST['group']) ? $_REQUEST['group'] : ''; if (!empty($this->bean->id)) { - $this->bean->user_parameters = requestToUserParameters(); + $this->bean->user_parameters = requestToUserParameters($this->bean); echo $this->bean->build_group_report($offset, true, array(), $group); } @@ -144,7 +144,7 @@ protected function action_addToProspectList() $key = Relationship::retrieve_by_modules($this->bean->report_module, 'ProspectLists', $GLOBALS['db']); if (!empty($key)) { - $this->bean->user_parameters = requestToUserParameters(); + $this->bean->user_parameters = requestToUserParameters($this->bean); $sql = $this->bean->build_report_query(); $result = $this->bean->db->query($sql); $beans = array(); diff --git a/modules/AOW_Conditions/AOW_Condition.php b/modules/AOW_Conditions/AOW_Condition.php index 3487fcc2809..0f1e9d1265a 100755 --- a/modules/AOW_Conditions/AOW_Condition.php +++ b/modules/AOW_Conditions/AOW_Condition.php @@ -98,6 +98,7 @@ public function save_lines($post_data, $parent, $key = '') $line_count = count((array)$postedField); $j = 0; for ($i = 0; $i < $line_count; ++$i) { + $condition_module = $_REQUEST['flow_module'] ?? ''; if (!isset($post_data[$key . 'deleted'][$i])) { LoggerManager::getLogger()->warn('AOR Condition trying to save lines but POST data does not contains the key "' . $key . 'deleted' . '" at index: ' . $i); } @@ -106,11 +107,14 @@ public function save_lines($post_data, $parent, $key = '') $this->mark_deleted($post_data[$key . 'id'][$i] ?? ''); } else { $condition = BeanFactory::newBean('AOW_Conditions'); + $condition_relation = ''; + $flow_bean = BeanFactory::newBean($condition_module); foreach ($this->field_defs as $field_def) { $field_name = $field_def['name']; if (isset($post_data[$key . $field_name][$i])) { if (is_array($post_data[$key . $field_name][$i])) { if ($field_name == 'module_path') { + $condition_relation = $post_data[$key . $field_name][$i]; $post_data[$key . $field_name][$i] = base64_encode(serialize($post_data[$key . $field_name][$i])); } else { switch ($condition->value_type) { @@ -123,8 +127,20 @@ public function save_lines($post_data, $parent, $key = '') } } else { if ($field_name === 'value' && $post_data[$key . 'value_type'][$i] === 'Value') { - $post_data[$key . $field_name][$i] = fixUpFormatting($_REQUEST['flow_module'], $condition->field, $post_data[$key . $field_name][$i]); - } + if (!empty($flow_bean)) { + foreach ($condition_relation as $relate){ + $flow_bean->load_relationship($relate); + $rel_module = ''; + if ($flow_bean->$relate) { + $rel_module = $flow_bean->$relate->getRelatedModuleName(); + $flow_bean = BeanFactory::newBean($rel_module); + } + } + if (!empty($rel_module) && $condition_module !== $rel_module) { + $condition_module = $rel_module; + } + } + $post_data[$key . $field_name][$i] = fixUpFormatting($condition_module, $condition->field, $post_data[$key . $field_name][$i]); } } $condition->$field_name = $post_data[$key . $field_name][$i]; }