From 7b145d96a90826b708caa255560309ffcb179bb7 Mon Sep 17 00:00:00 2001 From: colemanw Date: Fri, 21 Jul 2023 20:20:25 -0700 Subject: [PATCH] (REF) Replace CRM_Utils_Array in context of string-building (HTML/SQL/URL/etc) --- CRM/Activity/BAO/Activity.php | 8 ++++---- CRM/Case/BAO/Case.php | 4 ++-- CRM/Contribute/BAO/ContributionPage.php | 2 +- CRM/Contribute/Form/SoftCredit.php | 2 +- CRM/Core/BAO/Dashboard.php | 2 +- CRM/Core/Form.php | 2 +- CRM/Event/BAO/Event.php | 2 +- CRM/Event/BAO/Participant.php | 2 +- CRM/Event/Form/ManageEvent.php | 4 ++-- CRM/Event/Form/Participant.php | 4 ++-- CRM/Event/Form/ParticipantView.php | 2 +- CRM/Logging/Schema.php | 2 +- CRM/Mailing/Event/BAO/MailingEventForward.php | 2 +- CRM/Member/Import/Parser/Membership.php | 4 ++-- CRM/Pledge/BAO/Pledge.php | 2 +- tests/phpunit/api/v3/ProfileTest.php | 2 +- 16 files changed, 23 insertions(+), 23 deletions(-) diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index d6cba12795..3d7993b5fb 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -456,7 +456,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { ); } else { - $q = "action=view&reset=1&id={$activity->id}&atype={$activity->activity_type_id}&cid=" . CRM_Utils_Array::value('source_contact_id', $params) . "&context=home"; + $q = "action=view&reset=1&id={$activity->id}&atype={$activity->activity_type_id}&cid=" . ($params['source_contact_id'] ?? '') . "&context=home"; if ($activity->activity_type_id != CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Email')) { $url = CRM_Utils_System::url('civicrm/activity', $q); if ($activity->activity_type_id == CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Print PDF Letter')) { @@ -466,13 +466,13 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { } else { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/activity/add', - "action=update&reset=1&id={$activity->id}&atype={$activity->activity_type_id}&cid=" . CRM_Utils_Array::value('source_contact_id', $params) . "&context=home" + "action=update&reset=1&id={$activity->id}&atype={$activity->activity_type_id}&cid=" . ($params['source_contact_id'] ?? '') . "&context=home" ); } if (CRM_Core_Permission::check("delete activities")) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/activity', - "action=delete&reset=1&id={$activity->id}&atype={$activity->activity_type_id}&cid=" . CRM_Utils_Array::value('source_contact_id', $params) . "&context=home" + "action=delete&reset=1&id={$activity->id}&atype={$activity->activity_type_id}&cid=" . ($params['source_contact_id'] ?? '') . "&context=home" ); } } @@ -480,7 +480,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $url = CRM_Utils_System::url('civicrm/activity/view', $q); if (CRM_Core_Permission::check('delete activities')) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/activity', - "action=delete&reset=1&id={$activity->id}&atype={$activity->activity_type_id}&cid=" . CRM_Utils_Array::value('source_contact_id', $params) . "&context=home" + "action=delete&reset=1&id={$activity->id}&atype={$activity->activity_type_id}&cid=" . ($params['source_contact_id'] ?? '') . "&context=home" ); } } diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 9613965025..00aad654ae 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -706,7 +706,7 @@ HERESQL; $casesList[$key]['date'] = sprintf('%s', CRM_Utils_System::url('civicrm/case/activity/view', ['reset' => 1, 'cid' => $case['contact_id'], 'aid' => $case['activity_id']]), ts('View activity'), - CRM_Utils_Array::value($case['activity_type_id'], $activityTypeLabels) + $activityTypeLabels[$case['activity_type_id']] ?? '' ); } else { @@ -715,7 +715,7 @@ HERESQL; $status, CRM_Utils_System::url('civicrm/case/activity/view', ['reset' => 1, 'cid' => $case['contact_id'], 'aid' => $case['activity_id']]), ts('View activity'), - CRM_Utils_Array::value($case['activity_type_id'], $activityTypeLabels) + $activityTypeLabels[$case['activity_type_id']] ?? '' ); } } diff --git a/CRM/Contribute/BAO/ContributionPage.php b/CRM/Contribute/BAO/ContributionPage.php index 94aeb05556..026a1071c6 100644 --- a/CRM/Contribute/BAO/ContributionPage.php +++ b/CRM/Contribute/BAO/ContributionPage.php @@ -425,7 +425,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio } if ($values['is_email_receipt']) { - $sendTemplateParams['from'] = CRM_Utils_Array::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>'; + $sendTemplateParams['from'] = ($values['receipt_from_name'] ?? '') . ' <' . $values['receipt_from_email'] . '>'; $sendTemplateParams['toName'] = $displayName; $sendTemplateParams['toEmail'] = $email; $sendTemplateParams['cc'] = $values['cc_receipt'] ?? NULL; diff --git a/CRM/Contribute/Form/SoftCredit.php b/CRM/Contribute/Form/SoftCredit.php index 5ec45a8ba7..13f79e913d 100644 --- a/CRM/Contribute/Form/SoftCredit.php +++ b/CRM/Contribute/Form/SoftCredit.php @@ -150,7 +150,7 @@ class CRM_Contribute_Form_SoftCredit { $pcpId = $pcpInfo['pcp_id'] ?? NULL; $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'title'); $contributionPageTitle = CRM_PCP_BAO_PCP::getPcpPageTitle($pcpId, 'contribute'); - $defaults['pcp_made_through'] = CRM_Utils_Array::value('sort_name', $pcpInfo) . " :: " . $pcpTitle . " :: " . $contributionPageTitle; + $defaults['pcp_made_through'] = ($pcpInfo['sort_name'] ?? '') . " :: " . $pcpTitle . " :: " . $contributionPageTitle; $defaults['pcp_made_through_id'] = $pcpInfo['pcp_id'] ?? NULL; $defaults['pcp_display_in_roll'] = $pcpInfo['pcp_display_in_roll'] ?? NULL; $defaults['pcp_roll_nickname'] = $pcpInfo['pcp_roll_nickname'] ?? NULL; diff --git a/CRM/Core/BAO/Dashboard.php b/CRM/Core/BAO/Dashboard.php index 82f1b728a4..379d0d9620 100644 --- a/CRM/Core/BAO/Dashboard.php +++ b/CRM/Core/BAO/Dashboard.php @@ -198,7 +198,7 @@ class CRM_Core_BAO_Dashboard extends CRM_Core_DAO_Dashboard { if (!empty($params['instanceURL'])) { $query = "SELECT id FROM `civicrm_dashboard` - WHERE url LIKE '" . CRM_Utils_Array::value('instanceURL', $params) . "&%'"; + WHERE url LIKE '" . ($params['instanceURL'] ?? '') . "&%'"; $dashboardID = CRM_Core_DAO::singleValueQuery($query); } diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index bc34cb2ed8..e671b3f8b6 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -996,7 +996,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { */ protected function prepareParamsForPaymentProcessor($params) { // also add location name to the array - $params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params); + $params["address_name-{$this->_bltID}"] = ($params['billing_first_name'] ?? '') . ' ' . ($params['billing_middle_name'] ?? '') . ' ' . ($params['billing_last_name'] ?? ''); $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]); // Add additional parameters that the payment processors are used to receiving. if (!empty($params["billing_state_province_id-{$this->_bltID}"])) { diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index 13c18b2f4a..17f3095849 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -1244,7 +1244,7 @@ WHERE civicrm_event.is_active = 1 ]; } else { - $sendTemplateParams['from'] = CRM_Utils_Array::value('confirm_from_name', $values['event']) . " <" . CRM_Utils_Array::value('confirm_from_email', $values['event']) . ">"; + $sendTemplateParams['from'] = ($values['event']['confirm_from_name'] ?? '') . " <" . ($values['event']['confirm_from_email'] ?? '') . ">"; $sendTemplateParams['toName'] = $displayName; $sendTemplateParams['toEmail'] = $notifyEmail; $sendTemplateParams['autoSubmitted'] = TRUE; diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index 86dc17fd52..18915d84e8 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -660,7 +660,7 @@ INNER JOIN civicrm_price_field field ON ( value.price_field_id = field.id $extIdentifier = $contactFields['external_identifier'] ?? NULL; if ($extIdentifier) { $tmpContactField['external_identifier'] = $extIdentifier; - $tmpContactField['external_identifier']['title'] = CRM_Utils_Array::value('title', $extIdentifier) . ' (match to contact)'; + $tmpContactField['external_identifier']['title'] = ($extIdentifier['title'] ?? '') . ' (match to contact)'; } $tmpFields['participant_contact_id']['title'] = $tmpFields['participant_contact_id']['title'] . ' (match to contact)'; diff --git a/CRM/Event/Form/ManageEvent.php b/CRM/Event/Form/ManageEvent.php index 5b00499fff..6eed43ce9d 100644 --- a/CRM/Event/Form/ManageEvent.php +++ b/CRM/Event/Form/ManageEvent.php @@ -142,11 +142,11 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form { $title = NULL; if ($this->_id) { if ($this->_isTemplate) { - $title = ts('Edit Event Template') . ' - ' . CRM_Utils_Array::value('template_title', $eventInfo); + $title = ts('Edit Event Template') . ' - ' . ($eventInfo['template_title'] ?? ''); } else { $configureText = $this->_isRepeatingEvent ? ts('Configure Repeating Event') : ts('Configure Event'); - $title = $configureText . ' - ' . CRM_Utils_Array::value('title', $eventInfo); + $title = $configureText . ' - ' . ($eventInfo['title'] ?? ''); } } elseif ($this->_action & CRM_Core_Action::ADD) { diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 2331084417..a5c15626b6 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1010,8 +1010,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment // also add location name to the array $params["address_name-{$this->_bltID}"] - = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . - CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . + = ($params['billing_first_name'] ?? '') . ' ' . + ($params['billing_middle_name'] ?? '') . ' ' . CRM_Utils_Array::value('billing_last_name', $params); $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]); diff --git a/CRM/Event/Form/ParticipantView.php b/CRM/Event/Form/ParticipantView.php index 6d205cc9bd..2ed5d70926 100644 --- a/CRM/Event/Form/ParticipantView.php +++ b/CRM/Event/Form/ParticipantView.php @@ -210,7 +210,7 @@ class CRM_Event_Form_ParticipantView extends CRM_Core_Form { $this->setTitle(ts('View Event Registration for') . ' ' . $displayName); $roleId = $values[$participantID]['role_id'] ?? NULL; - $title = $displayName . ' (' . CRM_Utils_Array::value($roleId, $participantRoles) . ' - ' . $eventTitle . ')'; + $title = $displayName . ' (' . ($participantRoles[$roleId] ?? '') . ' - ' . $eventTitle . ')'; $sep = CRM_Core_DAO::VALUE_SEPARATOR; $viewRoles = []; diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index 8094be15c3..70cc37c30a 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -337,7 +337,7 @@ AND (TABLE_NAME LIKE 'log_civicrm_%' $nonStandardTableNameString ) $engineChanged = isset($tableSpec['engine']) && (strtoupper($tableSpec['engine']) != $currentEngine); $engineConfigChanged = isset($tableSpec['engine_config']) && (strtoupper($tableSpec['engine_config']) != $this->getEngineConfigForLogTable($logTable)); if ($engineChanged || ($engineConfigChanged && $params['updateChangedEngineConfig'])) { - $alterSql[] = "ENGINE=" . $tableSpec['engine'] . " " . CRM_Utils_Array::value('engine_config', $tableSpec); + $alterSql[] = "ENGINE=" . $tableSpec['engine'] . " " . ($tableSpec['engine_config'] ?? ''); } if (!empty($tableSpec['indexes'])) { $indexes = $this->getIndexesForTable($logTable); diff --git a/CRM/Mailing/Event/BAO/MailingEventForward.php b/CRM/Mailing/Event/BAO/MailingEventForward.php index 4fa9667991..6c45cb1645 100644 --- a/CRM/Mailing/Event/BAO/MailingEventForward.php +++ b/CRM/Mailing/Event/BAO/MailingEventForward.php @@ -150,7 +150,7 @@ class CRM_Mailing_Event_BAO_MailingEventForward extends CRM_Mailing_Event_DAO_Ma ); //append comment if added while forwarding. if (count($comment)) { - $message->_txtbody = CRM_Utils_Array::value('body_text', $comment) . $message->_txtbody; + $message->_txtbody = ($comment['body_text'] ?? '') . $message->_txtbody; if (!empty($comment['body_html'])) { $message->_htmlbody = $comment['body_html'] . '
---------------Original message---------------------
' . $message->_htmlbody; } diff --git a/CRM/Member/Import/Parser/Membership.php b/CRM/Member/Import/Parser/Membership.php index 7d7348bc2a..eb350f6dd5 100644 --- a/CRM/Member/Import/Parser/Membership.php +++ b/CRM/Member/Import/Parser/Membership.php @@ -322,11 +322,11 @@ class CRM_Member_Import_Parser_Membership extends CRM_Import_Parser { } elseif (empty($formatted['is_override'])) { if (empty($calcStatus)) { - throw new CRM_Core_Exception('Status in import row (' . CRM_Utils_Array::value('status_id', $formatValues) . ') does not match calculated status based on your configured Membership Status Rules. Record was not imported.', CRM_Import_Parser::ERROR); + throw new CRM_Core_Exception('Status in import row (' . ($formatValues['status_id'] ?? '') . ') does not match calculated status based on your configured Membership Status Rules. Record was not imported.', CRM_Import_Parser::ERROR); } if ($formatted['status_id'] != $calcStatus['id']) { //Status Hold" is either NOT mapped or is FALSE - throw new CRM_Core_Exception('Status in import row (' . CRM_Utils_Array::value('status_id', $formatValues) . ') does not match calculated status based on your configured Membership Status Rules (' . $calcStatus['name'] . '). Record was not imported.', CRM_Import_Parser::ERROR); + throw new CRM_Core_Exception('Status in import row (' . ($formatValues['status_id'] ?? '') . ') does not match calculated status based on your configured Membership Status Rules (' . $calcStatus['name'] . '). Record was not imported.', CRM_Import_Parser::ERROR); } } diff --git a/CRM/Pledge/BAO/Pledge.php b/CRM/Pledge/BAO/Pledge.php index f1312cfbf9..c665dc2b1a 100644 --- a/CRM/Pledge/BAO/Pledge.php +++ b/CRM/Pledge/BAO/Pledge.php @@ -184,7 +184,7 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge { } $contributionTypes = CRM_Contribute_PseudoConstant::financialType(); - $title = CRM_Contact_BAO_Contact::displayName($pledge->contact_id) . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($pledge->amount, $pledge->currency) . ' - ' . CRM_Utils_Array::value($pledge->financial_type_id, $contributionTypes) . ')'; + $title = CRM_Contact_BAO_Contact::displayName($pledge->contact_id) . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($pledge->amount, $pledge->currency) . ' - ' . ($contributionTypes[$pledge->financial_type_id] ?? '') . ')'; // add the recently created Pledge CRM_Utils_Recent::add($title, diff --git a/tests/phpunit/api/v3/ProfileTest.php b/tests/phpunit/api/v3/ProfileTest.php index 44dc57c1fb..8ba8fea6d4 100644 --- a/tests/phpunit/api/v3/ProfileTest.php +++ b/tests/phpunit/api/v3/ProfileTest.php @@ -976,7 +976,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $keys = array_keys($contact['values']); $contactId = array_pop($keys); - $this->assertEquals(0, $contact['values'][$contactId]['api.address.create']['is_error'], ' error message: ' . CRM_Utils_Array::value('error_message', $contact['values'][$contactId]['api.address.create']) + $this->assertEquals(0, $contact['values'][$contactId]['api.address.create']['is_error'], ' error message: ' . ($contact['values'][$contactId]['api.address.create']['error_message'] ?? '') ); $activityParams = [ -- 2.25.1