From: Eileen McNaughton Date: Sat, 20 May 2023 01:10:28 +0000 (+1200) Subject: Standardise casing on ids in WorkflowMessages X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f89712245ac3af441cc5680f13cf6a2609de4be7;p=civicrm-core.git Standardise casing on ids in WorkflowMessages This resolves the inconsistencies in id fields in the workFlowMessages My general feeling is this hasn't really been adopted outside of core as yet as it has been so immature so I'm fixing the core uses - these are all heavily tested --- diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index a29e665abe..b17c8c733b 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -966,8 +966,8 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { 'isEmailPdf' => Civi::settings()->get('invoice_is_email_pdf'), 'isTest' => (bool) ($form->_action & CRM_Core_Action::PREVIEW), 'modelProps' => [ - 'contributionId' => $this->getCurrentRowContributionID(), - 'contactId' => $form->_receiptContactId, + 'contributionID' => $this->getCurrentRowContributionID(), + 'contactID' => $form->_receiptContactId, 'membershipID' => $this->getCurrentRowMembershipID(), ], ] diff --git a/CRM/Contribute/WorkflowMessage/ContributionTrait.php b/CRM/Contribute/WorkflowMessage/ContributionTrait.php index 7cdaed94b9..2951c74803 100644 --- a/CRM/Contribute/WorkflowMessage/ContributionTrait.php +++ b/CRM/Contribute/WorkflowMessage/ContributionTrait.php @@ -21,7 +21,7 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait { * @var int * @scope tokenContext as contributionId, tplParams as contributionID */ - public $contributionId; + public $contributionID; /** * Is the site configured such that tax should be displayed. @@ -67,9 +67,9 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait { * @return \CRM_Financial_BAO_Order|null */ private function getOrder(): ?CRM_Financial_BAO_Order { - if (!$this->order && $this->contributionId) { + if (!$this->order && $this->contributionID) { $this->order = new CRM_Financial_BAO_Order(); - $this->order->setTemplateContributionID($this->contributionId); + $this->order->setTemplateContributionID($this->contributionID); } return $this->order; } @@ -170,7 +170,7 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait { public function setContribution(array $contribution): self { $this->contribution = $contribution; if (!empty($contribution['id'])) { - $this->contributionId = $contribution['id']; + $this->contributionID = $contribution['id']; } return $this; } diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 828d943419..a824a92bab 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -2255,7 +2255,7 @@ INNER JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_ 'modelProps' => [ 'participantID' => $this->_id, 'eventID' => $params['event_id'], - 'contributionId' => $this->getContributionID(), + 'contributionID' => $this->getContributionID(), ], ]; diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 765eeaccd7..ea8df97fd1 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -981,8 +981,8 @@ DESC limit 1"); 'isTest' => (bool) ($this->_action & CRM_Core_Action::PREVIEW), 'modelProps' => [ 'receiptText' => $this->getSubmittedValue('receipt_text'), - 'contributionId' => $formValues['contribution_id'], - 'contactId' => $this->_receiptContactId, + 'contributionID' => $formValues['contribution_id'], + 'contactID' => $this->_receiptContactId, 'membershipID' => $this->getMembershipID(), ], ] diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 03d07796c9..2452991e3d 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -703,8 +703,8 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { 'isEmailPdf' => Civi::settings()->get('invoice_is_email_pdf'), 'modelProps' => [ 'receiptText' => $this->getSubmittedValue('receipt_text'), - 'contactId' => $this->_receiptContactId, - 'contributionId' => $this->getContributionID(), + 'contactID' => $this->_receiptContactId, + 'contributionID' => $this->getContributionID(), 'membershipID' => $this->_membershipId, ], ] diff --git a/Civi/WorkflowMessage/GenericWorkflowMessage.php b/Civi/WorkflowMessage/GenericWorkflowMessage.php index 9d2d3bdf1a..7eb6a59b1c 100644 --- a/Civi/WorkflowMessage/GenericWorkflowMessage.php +++ b/Civi/WorkflowMessage/GenericWorkflowMessage.php @@ -21,8 +21,8 @@ use Civi\WorkflowMessage\Traits\ReflectiveWorkflowTrait; /** * Generic base-class for describing the inputs for a workflow email template. * - * @method $this setContactId(int|null $contactId) - * @method int|null getContactId() + * @method $this setContactID(int|null $contactID) + * @method int|null getContactID() * @method $this setContact(array|null $contact) * @method array|null getContact() * @@ -64,10 +64,10 @@ class GenericWorkflowMessage implements WorkflowMessageInterface { * The contact receiving this message. * * @var int|null - * @scope tokenContext, tplParams as contactID + * @scope tokenContext as contactId, tplParams as contactID * @fkEntity Contact */ - protected $contactId; + protected $contactID; /** * @var array|null @@ -82,7 +82,7 @@ class GenericWorkflowMessage implements WorkflowMessageInterface { * @see ReflectiveWorkflowTrait::validate() */ protected function validateExtra_contact(array &$errors) { - if (empty($this->contactId) && empty($this->contact['id'])) { + if (empty($this->contactID) && empty($this->contact['id'])) { $errors[] = [ 'severity' => 'error', 'fields' => ['contactId', 'contact'], @@ -90,7 +90,7 @@ class GenericWorkflowMessage implements WorkflowMessageInterface { 'message' => ts('Message template requires one of these fields (%1)', ['contactId, contact']), ]; } - if (!empty($this->contactId) && !empty($this->contact)) { + if (!empty($this->contactID) && !empty($this->contact)) { $errors[] = [ 'severity' => 'warning', 'fields' => ['contactId', 'contact'], diff --git a/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php b/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php index 1e143518ad..e9bd988b37 100644 --- a/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php +++ b/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php @@ -308,7 +308,7 @@ class CRM_Core_BAO_MessageTemplateTest extends CiviUnitTestCase { $msg = WorkflowMessage::create('case_activity', [ 'modelProps' => [ - 'contactId' => $contact_id, + 'contactID' => $contact_id, 'contact' => ['role' => 'Sand grain counter'], 'isCaseActivity' => 1, 'clientId' => $client_id, diff --git a/tests/phpunit/Civi/WorkflowMessage/ExampleWorkflowMessageTest.php b/tests/phpunit/Civi/WorkflowMessage/ExampleWorkflowMessageTest.php index e60888d748..acf995b076 100644 --- a/tests/phpunit/Civi/WorkflowMessage/ExampleWorkflowMessageTest.php +++ b/tests/phpunit/Civi/WorkflowMessage/ExampleWorkflowMessageTest.php @@ -109,7 +109,7 @@ class ExampleWorkflowMessageTest extends \CiviUnitTestCase { /** @var \Civi\WorkflowMessage\WorkflowMessageInterface $ex */ $ex = static::createExample(); $ex->import('modelProps', [ - 'contactId' => $this->individualCreate(), + 'contactID' => $this->individualCreate(), 'myPublicString' => 'ok', 'implicitStringArray' => ['single'], 'myProtectedInt' => 2, @@ -268,7 +268,7 @@ class ExampleWorkflowMessageTest extends \CiviUnitTestCase { $rand = rand(0, 1000); $cid = $this->individualCreate(['first_name' => 'Foo', 'last_name' => 'Bar' . $rand, 'prefix_id' => NULL, 'suffix_id' => NULL]); /** @var \Civi\WorkflowMessage\GenericWorkflowMessage $ex */ - $ex = $this->createExample()->setContactId($cid); + $ex = $this->createExample()->setContactID($cid); \Civi::dispatcher()->addListener('hook_civicrm_alterMailParams', function($e) use (&$hookCount) { $hookCount++; $this->assertEquals('my_example_wf', $e->params['workflow'], 'ExampleWorkflow::WORKFLOW should propagate to params[workflow]');