From 253d4c27501b0c366be59de1cc1f2e83bdbcf797 Mon Sep 17 00:00:00 2001 From: Enric Prats Date: Thu, 31 Oct 2024 08:44:58 +0000 Subject: [PATCH 1/5] Protect variable before use --- data/SugarBean.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/SugarBean.php b/data/SugarBean.php index a676884b4b6..14c71504068 100755 --- a/data/SugarBean.php +++ b/data/SugarBean.php @@ -2522,7 +2522,8 @@ public function cleanBean() // STIC Custom - 20221213 - JCH - Trim name & varchar type values on save when the value is not null // STIC#902 // STIC#982 - if (isset($def['type']) && in_array($def['type'], ['name', 'varchar']) && !is_null($this->$key)) { + // xxxxx + if (isset($def['type']) && in_array($def['type'], ['name', 'varchar']) && property_exists($this, $key) && !is_null($this->$key)) { $this->$key = trim($this->$key); } // END STIC From e20547db74404af21ee8ed1b4cc0c0f01929e8b7 Mon Sep 17 00:00:00 2001 From: Enric Prats Date: Thu, 31 Oct 2024 08:54:16 +0000 Subject: [PATCH 2/5] Added PR info --- data/SugarBean.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/SugarBean.php b/data/SugarBean.php index 14c71504068..8aa467d873c 100755 --- a/data/SugarBean.php +++ b/data/SugarBean.php @@ -2522,7 +2522,7 @@ public function cleanBean() // STIC Custom - 20221213 - JCH - Trim name & varchar type values on save when the value is not null // STIC#902 // STIC#982 - // xxxxx + // https://github.com/SinergiaTIC/SinergiaCRM/pull/470 if (isset($def['type']) && in_array($def['type'], ['name', 'varchar']) && property_exists($this, $key) && !is_null($this->$key)) { $this->$key = trim($this->$key); } From 95032ee96da6bb80dd2c267165209cd4f31c856c Mon Sep 17 00:00:00 2001 From: Enric Prats Date: Thu, 31 Oct 2024 11:08:35 +0000 Subject: [PATCH 3/5] Controlling more "undefined" uses --- .../modules/Contacts/SticLogicHooksCode.php | 6 ++--- custom/modules/Contacts/SticUtils.php | 2 +- data/SugarBean.php | 2 +- modules/stic_Incorpora_Locations/Utils.php | 24 +++++++++++++------ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/custom/modules/Contacts/SticLogicHooksCode.php b/custom/modules/Contacts/SticLogicHooksCode.php index 985d2593c9c..12e2fb87d04 100644 --- a/custom/modules/Contacts/SticLogicHooksCode.php +++ b/custom/modules/Contacts/SticLogicHooksCode.php @@ -24,13 +24,13 @@ class ContactsLogicHooks { public function before_save(&$bean, $event, $arguments) { // Calculate age - if ($bean->birthdate != $bean->fetched_row['birthdate']) { + if (empty($bean->fetched_row) || $bean->birthdate != $bean->fetched_row['birthdate']) { include_once 'custom/modules/Contacts/SticUtils.php'; $bean->stic_age_c = ContactsUtils::getAge($bean->birthdate); } // Bring Incorpora location data, if there is any - if ($bean->fetched_row['stic_incorpora_locations_id_c'] != $bean->stic_incorpora_locations_id_c) { + if (empty($bean->fetched_row) || $bean->fetched_row['stic_incorpora_locations_id_c'] != $bean->stic_incorpora_locations_id_c) { include_once 'modules/stic_Incorpora_Locations/Utils.php'; stic_Incorpora_LocationsUtils::transferLocationData($bean); } @@ -49,7 +49,7 @@ public function after_save(&$bean, $event, $arguments) { // End of Patch issue // Generate automatic Call - if ($bean->stic_postal_mail_return_reason_c != $bean->fetched_row['stic_postal_mail_return_reason_c']) { + if (empty($bean->fetched_row) || $bean->stic_postal_mail_return_reason_c != $bean->fetched_row['stic_postal_mail_return_reason_c']) { include_once 'custom/modules/Contacts/SticUtils.php'; ContactsUtils::generateCallFromReturnMailReason($bean); } diff --git a/custom/modules/Contacts/SticUtils.php b/custom/modules/Contacts/SticUtils.php index 2667e27a7ed..2d9aa4ecc1a 100644 --- a/custom/modules/Contacts/SticUtils.php +++ b/custom/modules/Contacts/SticUtils.php @@ -83,7 +83,7 @@ public static function getAge($birthday) public static function generateCallFromReturnMailReason($contactBean) { $reasons = array('wrong_address', 'unknown', 'rejected'); - if (in_array($contactBean->stic_postal_mail_return_reason_c, $reasons)) { + if (!empty($contactBean->stic_postal_mail_return_reason_c) && in_array($contactBean->stic_postal_mail_return_reason_c, $reasons)) { global $current_user, $timedate, $app_strings; // Create the new call diff --git a/data/SugarBean.php b/data/SugarBean.php index 8aa467d873c..0465bfceefb 100755 --- a/data/SugarBean.php +++ b/data/SugarBean.php @@ -2523,7 +2523,7 @@ public function cleanBean() // STIC#902 // STIC#982 // https://github.com/SinergiaTIC/SinergiaCRM/pull/470 - if (isset($def['type']) && in_array($def['type'], ['name', 'varchar']) && property_exists($this, $key) && !is_null($this->$key)) { + if (isset($def['type']) && in_array($def['type'], ['name', 'varchar']) && property_exists($this, $key) && !empty($this->$key)) { $this->$key = trim($this->$key); } // END STIC diff --git a/modules/stic_Incorpora_Locations/Utils.php b/modules/stic_Incorpora_Locations/Utils.php index 66ace07055c..800e88337d8 100644 --- a/modules/stic_Incorpora_Locations/Utils.php +++ b/modules/stic_Incorpora_Locations/Utils.php @@ -41,12 +41,22 @@ public static function transferLocationData($recordBean) { $inc_state = 'inc_state' .$sufix; $stic_incorpora_locations_id = 'stic_incorpora_locations_id' .$sufix; - $location_bean = BeanFactory::getBean('stic_Incorpora_Locations', $recordBean->$stic_incorpora_locations_id); - $recordBean->$inc_town_code = $location_bean->town_code; - $recordBean->$inc_town = $location_bean->town; - $recordBean->$inc_municipality_code = $location_bean->municipality_code; - $recordBean->$inc_municipality = $location_bean->municipality; - $recordBean->$inc_state_code = $location_bean->state_code; - $recordBean->$inc_state = $location_bean->state; + if(!empty($recordBean->$stic_incorpora_locations_id)) { + $location_bean = BeanFactory::getBean('stic_Incorpora_Locations', $recordBean->$stic_incorpora_locations_id); + $recordBean->$inc_town_code = $location_bean->town_code; + $recordBean->$inc_town = $location_bean->town; + $recordBean->$inc_municipality_code = $location_bean->municipality_code; + $recordBean->$inc_municipality = $location_bean->municipality; + $recordBean->$inc_state_code = $location_bean->state_code; + $recordBean->$inc_state = $location_bean->state; + } + else { + $recordBean->$inc_town_code = null; + $recordBean->$inc_town = null; + $recordBean->$inc_municipality_code = null; + $recordBean->$inc_municipality = null; + $recordBean->$inc_state_code = null; + $recordBean->$inc_state = null; + } } } \ No newline at end of file From e7f6b0078d61c1a0a6080e76cd8d46435f246c86 Mon Sep 17 00:00:00 2001 From: Enric Prats Date: Thu, 31 Oct 2024 11:31:28 +0000 Subject: [PATCH 4/5] fixing when incorpora location is removed --- modules/stic_Incorpora_Locations/Utils.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/stic_Incorpora_Locations/Utils.php b/modules/stic_Incorpora_Locations/Utils.php index 800e88337d8..628ed78e454 100644 --- a/modules/stic_Incorpora_Locations/Utils.php +++ b/modules/stic_Incorpora_Locations/Utils.php @@ -51,12 +51,12 @@ public static function transferLocationData($recordBean) { $recordBean->$inc_state = $location_bean->state; } else { - $recordBean->$inc_town_code = null; - $recordBean->$inc_town = null; - $recordBean->$inc_municipality_code = null; - $recordBean->$inc_municipality = null; - $recordBean->$inc_state_code = null; - $recordBean->$inc_state = null; + $recordBean->$inc_town_code = ''; + $recordBean->$inc_town = ''; + $recordBean->$inc_municipality_code = ''; + $recordBean->$inc_municipality = ''; + $recordBean->$inc_state_code = ''; + $recordBean->$inc_state = ''; } } } \ No newline at end of file From cb8d6de25bce3bfe7624c035046524ee153a7c91 Mon Sep 17 00:00:00 2001 From: Enric Prats Date: Wed, 18 Dec 2024 08:41:15 +0000 Subject: [PATCH 5/5] Adding tag STIC-Custom --- data/SugarBean.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/data/SugarBean.php b/data/SugarBean.php index 0465bfceefb..9929b97bd3e 100755 --- a/data/SugarBean.php +++ b/data/SugarBean.php @@ -2522,8 +2522,11 @@ public function cleanBean() // STIC Custom - 20221213 - JCH - Trim name & varchar type values on save when the value is not null // STIC#902 // STIC#982 + // STIC-Custom 20241218 EPS - Avoid using property "key" if it is not setted // https://github.com/SinergiaTIC/SinergiaCRM/pull/470 + // if (isset($def['type']) && in_array($def['type'], ['name', 'varchar']) && !is_null($this->$key)) { if (isset($def['type']) && in_array($def['type'], ['name', 'varchar']) && property_exists($this, $key) && !empty($this->$key)) { + // END STIC-Custom (EPS 20241218) $this->$key = trim($this->$key); } // END STIC