From 078d538b3226a84dac52543109f4265453565a50 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 12 Sep 2023 17:29:00 +1200 Subject: [PATCH] dev/core#4421 Fix some attempts to count NULL (php8.x) --- CRM/Mailing/Form/Unsubscribe.php | 6 ++++-- CRM/Mailing/Page/Common.php | 14 ++++++++------ api/v3/MailingEventResubscribe.php | 2 +- api/v3/MailingEventUnsubscribe.php | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CRM/Mailing/Form/Unsubscribe.php b/CRM/Mailing/Form/Unsubscribe.php index cf17a06f0a..c45e9d368d 100644 --- a/CRM/Mailing/Form/Unsubscribe.php +++ b/CRM/Mailing/Form/Unsubscribe.php @@ -78,9 +78,10 @@ class CRM_Mailing_Form_Unsubscribe extends CRM_Core_Form { $this->_email = $email; $groups = CRM_Mailing_Event_BAO_MailingEventUnsubscribe::unsub_from_mailing($job_id, $queue_id, $hash, TRUE); - $this->assign('groups', $groups); + $this->assign('groups', $groups ?? []); $groupExist = NULL; foreach ($groups as $value) { + // How about we just array_filter - only question is before or after the assign? if ($value) { $groupExist = TRUE; } @@ -89,6 +90,7 @@ class CRM_Mailing_Form_Unsubscribe extends CRM_Core_Form { $statusMsg = ts('%1 has already been unsubscribed.', [1 => $email]); CRM_Core_Session::setStatus($statusMsg, '', 'error'); } + // @todo - can we just check if groups is empty here & in the template? $this->assign('groupExist', $groupExist); } @@ -119,7 +121,7 @@ class CRM_Mailing_Form_Unsubscribe extends CRM_Core_Form { // Email address verified $groups = CRM_Mailing_Event_BAO_MailingEventUnsubscribe::unsub_from_mailing($this->_job_id, $this->_queue_id, $this->_hash); - if (count($groups)) { + if (!empty($groups)) { CRM_Mailing_Event_BAO_MailingEventUnsubscribe::send_unsub_response($this->_queue_id, $groups, FALSE, $this->_job_id); } diff --git a/CRM/Mailing/Page/Common.php b/CRM/Mailing/Page/Common.php index 70ccd7f6cd..66f4112688 100644 --- a/CRM/Mailing/Page/Common.php +++ b/CRM/Mailing/Page/Common.php @@ -57,28 +57,30 @@ class CRM_Mailing_Page_Common extends CRM_Core_Page { $this->assign('confirm', $confirm); $groups = CRM_Mailing_Event_BAO_MailingEventUnsubscribe::unsub_from_mailing($job_id, $queue_id, $hash, TRUE); - $this->assign('groups', $groups); + $this->assign('groups', $groups ?? []); $groupExist = NULL; - foreach ($groups as $key => $value) { + foreach ($groups as $value) { + // How about we just array_filter - only question is before or after the assign? if ($value) { $groupExist = TRUE; } } + // @todo - can we just check if groups is empty here & in the template? $this->assign('groupExist', $groupExist); if ($confirm) { - if ($this->_type == 'unsubscribe') { + if ($this->_type === 'unsubscribe') { $groups = CRM_Mailing_Event_BAO_MailingEventUnsubscribe::unsub_from_mailing($job_id, $queue_id, $hash); - if (count($groups)) { + if (!empty($groups)) { CRM_Mailing_Event_BAO_MailingEventUnsubscribe::send_unsub_response($queue_id, $groups, FALSE, $job_id); } else { // should we indicate an error, or just ignore? } } - elseif ($this->_type == 'resubscribe') { + elseif ($this->_type === 'resubscribe') { $groups = CRM_Mailing_Event_BAO_MailingEventResubscribe::resub_to_mailing($job_id, $queue_id, $hash); - if (count($groups)) { + if (!empty($groups)) { CRM_Mailing_Event_BAO_MailingEventResubscribe::send_resub_response($queue_id, $groups, $job_id); } else { diff --git a/api/v3/MailingEventResubscribe.php b/api/v3/MailingEventResubscribe.php index 1749b13156..fc8280fb51 100644 --- a/api/v3/MailingEventResubscribe.php +++ b/api/v3/MailingEventResubscribe.php @@ -32,7 +32,7 @@ function civicrm_api3_mailing_event_resubscribe_create($params) { $params['hash'] ); - if (count($groups)) { + if (!empty($groups)) { CRM_Mailing_Event_BAO_MailingEventResubscribe::send_resub_response( $params['event_queue_id'], $groups, diff --git a/api/v3/MailingEventUnsubscribe.php b/api/v3/MailingEventUnsubscribe.php index 56ac663ba1..644499c1c8 100644 --- a/api/v3/MailingEventUnsubscribe.php +++ b/api/v3/MailingEventUnsubscribe.php @@ -43,7 +43,7 @@ function civicrm_api3_mailing_event_unsubscribe_create($params) { $hash = $params['hash']; if (empty($params['org_unsubscribe'])) { $groups = CRM_Mailing_Event_BAO_MailingEventUnsubscribe::unsub_from_mailing($job, $queue, $hash); - if (count($groups)) { + if (!empty($groups)) { CRM_Mailing_Event_BAO_MailingEventUnsubscribe::send_unsub_response($queue, $groups, FALSE, $job); return civicrm_api3_create_success($params); } -- 2.25.1