Fix #577 - Fix empty addr variable creating logs

This commit is contained in:
y.yerli 2025-01-14 18:13:00 +03:00
parent a2ff98643a
commit bb4afd4b56

View file

@ -192,7 +192,7 @@ class SugarEmailAddress extends SugarBean
'Users', 'Users',
'Employees' 'Employees'
); );
/** /**
* For saveAtUserProfile() method to telling what * For saveAtUserProfile() method to telling what
* went wrong at the last call. * went wrong at the last call.
@ -461,11 +461,11 @@ class SugarEmailAddress extends SugarBean
$_addressCaps = $db->quote(strtoupper($address)); $_addressCaps = $db->quote(strtoupper($address));
$_id = $db->quoted($id); $_id = $db->quoted($id);
$query = $query =
"UPDATE email_addresses "UPDATE email_addresses
SET SET
email_address = '$_address', email_address = '$_address',
email_address_caps = '$_addressCaps' email_address_caps = '$_addressCaps'
WHERE WHERE
id = {$_id} AND id = {$_id} AND
deleted = 0"; deleted = 0";
$result = $db->query($query); $result = $db->query($query);
@ -483,13 +483,13 @@ class SugarEmailAddress extends SugarBean
$_replyTo = (bool)$replyTo ? '1' : '0'; $_replyTo = (bool)$replyTo ? '1' : '0';
$_id = $db->quoted($id); $_id = $db->quoted($id);
$query = $query =
"UPDATE email_addr_bean_rel "UPDATE email_addr_bean_rel
SET SET
primary_address = '{$_primary}', primary_address = '{$_primary}',
reply_to_address = '{$_replyTo}' reply_to_address = '{$_replyTo}'
WHERE WHERE
email_address_id = {$_id} AND email_address_id = {$_id} AND
bean_module = 'Users' AND bean_module = 'Users' AND
bean_id = '{$current_user->id}' AND bean_id = '{$current_user->id}' AND
deleted = 0"; deleted = 0";
$result = $db->query($query); $result = $db->query($query);
@ -872,10 +872,7 @@ class SugarEmailAddress extends SugarBean
$optOut = '' $optOut = ''
) { ) {
if (!is_array($new_addrs)) { if (!is_array($new_addrs)) {
$GLOBALS['log']->fatal( $new_addrs = array($new_addrs);
'Invalid Argument: new address should be an array of strings, ' .
gettype($new_addrs) . ' given.'
);
} }
$module = $this->getCorrectedModule($module); $module = $this->getCorrectedModule($module);
//One last check for the ConvertLead action in which case we need to change $module to 'Leads' //One last check for the ConvertLead action in which case we need to change $module to 'Leads'
@ -1083,6 +1080,11 @@ class SugarEmailAddress extends SugarBean
$optIn = null $optIn = null
) { ) {
$addr = html_entity_decode($addr, ENT_QUOTES); $addr = html_entity_decode($addr, ENT_QUOTES);
if (empty($addr)) {
return;
}
if (preg_match($this->regex, $addr)) { if (preg_match($this->regex, $addr)) {
$primaryFlag = ($primary) ? '1' : '0'; $primaryFlag = ($primary) ? '1' : '0';
$replyToFlag = ($replyTo) ? '1' : '0'; $replyToFlag = ($replyTo) ? '1' : '0';
@ -1155,10 +1157,10 @@ class SugarEmailAddress extends SugarBean
$id = $this->db->quote($a['id']); $id = $this->db->quote($a['id']);
$qUpdate = /** @lang sql */ $qUpdate = /** @lang sql */
"UPDATE email_addresses SET "UPDATE email_addresses SET
invalid_email = {$addressMetaInvalidEmailInt}, invalid_email = {$addressMetaInvalidEmailInt},
opt_out = {$addressMetaOptOutInt}, opt_out = {$addressMetaOptOutInt},
date_modified = '{$now}' date_modified = '{$now}'
WHERE id = '{$id}'"; WHERE id = '{$id}'";
$this->db->query($qUpdate); $this->db->query($qUpdate);
@ -1470,7 +1472,7 @@ class SugarEmailAddress extends SugarBean
$return = array(); $return = array();
$module = $this->getCorrectedModule($module); $module = $this->getCorrectedModule($module);
$q = "SELECT $q = "SELECT
ea.email_address, ea.email_address,
ea.email_address_caps, ea.email_address_caps,
ea.invalid_email, ea.invalid_email,
@ -1486,7 +1488,7 @@ class SugarEmailAddress extends SugarBean
ear.reply_to_address, ear.reply_to_address,
ear.deleted ear.deleted
FROM email_addresses ea LEFT JOIN email_addr_bean_rel ear ON ea.id = ear.email_address_id FROM email_addresses ea LEFT JOIN email_addr_bean_rel ear ON ea.id = ear.email_address_id
WHERE WHERE
ear.bean_module = '" . $this->db->quote($module) . "' ear.bean_module = '" . $this->db->quote($module) . "'
AND ear.bean_id = '" . $this->db->quote($id) . "' AND ear.bean_id = '" . $this->db->quote($id) . "'
AND ear.deleted = 0 AND ear.deleted = 0