Standardise casing on ids in WorkflowMessages
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 20 May 2023 01:10:28 +0000 (13:10 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 20 May 2023 02:27:06 +0000 (14:27 +1200)
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

CRM/Batch/Form/Entry.php
CRM/Contribute/WorkflowMessage/ContributionTrait.php
CRM/Event/Form/Participant.php
CRM/Member/Form/Membership.php
CRM/Member/Form/MembershipRenewal.php
Civi/WorkflowMessage/GenericWorkflowMessage.php
tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php
tests/phpunit/Civi/WorkflowMessage/ExampleWorkflowMessageTest.php

index a29e665abe393878010a5707e7499ddce516f3a1..b17c8c733b27c023c8667d27db3ddf90fbb96900 100644 (file)
@@ -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(),
         ],
       ]
index 7cdaed94b98a5f760be2069e1bf96b3c8fbd9184..2951c7480344831a68abd7894fd74c399f3e833d 100644 (file)
@@ -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;
   }
index 828d9434199d660b0ba669e5118bb71444c355cc..a824a92bab6f99ab014fdfd66565acb106468c4f 100644 (file)
@@ -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(),
         ],
       ];
 
index 765eeaccd79e08e76b442ce29be4003d730b9f34..ea8df97fd1d2c031e07b110d2f7f6cebccaf3bd5 100644 (file)
@@ -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(),
         ],
       ]
index 03d07796c9ce61b4a241c5f3cddd0a0a4c7f978e..2452991e3dc7079697c5ad4f9e5b7a72ba0c71c1 100644 (file)
@@ -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,
         ],
       ]
index 9d2d3bdf1a0490167899f10c5f9c3df1c203352c..7eb6a59b1cf9126a08ce0d148e5f984c6eb4dc6c 100644 (file)
@@ -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'],
index 1e143518ad2ce92c5648fbe6a03145c140ec7beb..e9bd988b37fc7f96209294307b39ca7e0dffce43 100644 (file)
@@ -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,
index e60888d748eb31ab1744db65375ed7cc0b973c66..acf995b0763fe14c0a56ada52871e9fbc2933571 100644 (file)
@@ -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]');