Update references to 'workflow' (from old 'valueName' parameter)
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 26 Jul 2022 18:56:01 +0000 (19:56 +0100)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 26 Jul 2022 18:56:01 +0000 (19:56 +0100)
19 files changed:
CRM/Campaign/BAO/Petition.php
CRM/Case/BAO/Case.php
CRM/Contribute/BAO/ContributionPage.php
CRM/Contribute/BAO/ContributionSoft.php
CRM/Contribute/Form/CancelSubscription.php
CRM/Contribute/Form/UpdateBilling.php
CRM/Contribute/Form/UpdateSubscription.php
CRM/Core/BAO/MessageTemplate.php
CRM/Core/BAO/UFGroup.php
CRM/Event/BAO/Event.php
CRM/Event/Form/SelfSvcTransfer.php
CRM/Financial/BAO/Payment.php
CRM/Friend/BAO/Friend.php
CRM/PCP/BAO/PCP.php
CRM/PCP/Form/Campaign.php
CRM/Pledge/BAO/Pledge.php
api/v3/MessageTemplate.php
ext/eventcart/CRM/Event/Cart/Form/Checkout/Payment.php
tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php

index 5d3d55a5f0a94420cd07fc877251afa7e95eaabc..d6e688b849dff8184d51aa117923a546be0171de 100644 (file)
@@ -571,7 +571,7 @@ AND         tag_id = ( SELECT id FROM civicrm_tag WHERE name = %2 )";
           CRM_Core_BAO_MessageTemplate::sendTemplate(
             [
               'groupName' => 'msg_tpl_workflow_petition',
-              'valueName' => 'petition_sign',
+              'workflow' => 'petition_sign',
               'contactId' => $params['contactId'],
               'tplParams' => $tplParams,
               'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>",
@@ -628,7 +628,7 @@ AND         tag_id = ( SELECT id FROM civicrm_tag WHERE name = %2 )";
           CRM_Core_BAO_MessageTemplate::sendTemplate(
             [
               'groupName' => 'msg_tpl_workflow_petition',
-              'valueName' => 'petition_confirmation_needed',
+              'workflow' => 'petition_confirmation_needed',
               'contactId' => $params['contactId'],
               'tplParams' => $tplParams,
               'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>",
index b2a0db357b9aa570c8a1ca0af80cd540874df229..e11b04701a0c845a4b55e88143248dd3e444998a 100644 (file)
@@ -1340,7 +1340,7 @@ HERESQL;
       list($result[CRM_Utils_Array::value('contact_id', $info)], $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(
         [
           'groupName' => 'msg_tpl_workflow_case',
-          'valueName' => 'case_activity',
+          'workflow' => 'case_activity',
           'contactId' => $info['contact_id'] ?? NULL,
           'tplParams' => $tplParams,
           'from' => $receiptFrom,
index f184d191165b880c40b81410d9234139e8b947aa..e47933d76c370f81bd0d5cb6f899b4fdfbc49c27 100644 (file)
@@ -454,7 +454,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
       // send duplicate alert, if dupe match found during on-behalf-of processing.
       if (!empty($values['onbehalf_dupe_alert'])) {
         $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution';
-        $sendTemplateParams['valueName'] = 'contribution_dupalert';
+        $sendTemplateParams['workflow'] = 'contribution_dupalert';
         $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>";
         $sendTemplateParams['toName'] = $values['receipt_from_name'] ?? NULL;
         $sendTemplateParams['toEmail'] = $values['receipt_from_email'] ?? NULL;
@@ -554,7 +554,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
       [$displayName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution['contact_id'], FALSE);
       $templatesParams = [
         'groupName' => 'msg_tpl_workflow_contribution',
-        'valueName' => 'contribution_recurring_notify',
+        'workflow' => 'contribution_recurring_notify',
         'contactId' => $contribution['contact_id'],
         'tplParams' => [
           'recur_frequency_interval' => $recur->frequency_interval,
index 56f52515501da09451ba410747028d7a836a6a45..ee983c7aa2e032c42aa78781445852300de3d824 100644 (file)
@@ -666,7 +666,7 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
       $domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
       $sendTemplateParams = [
         'groupName' => 'msg_tpl_workflow_contribution',
-        'valueName' => 'pcp_owner_notify',
+        'workflow' => 'pcp_owner_notify',
         'contactId' => $contributionSoft['contact_id'],
         'toEmail' => $ownerEmail,
         'toName' => $ownerName,
index 529de295e0936dd21163b4ef23d92f202b92895b..281b372683adbd559081f16f2794dc0af44797b6 100644 (file)
@@ -263,7 +263,7 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib
         $sendTemplateParams
           = [
             'groupName' => $this->_mode == 'auto_renew' ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution',
-            'valueName' => $this->_mode == 'auto_renew' ? 'membership_autorenew_cancelled' : 'contribution_recurring_cancelled',
+            'workflow' => $this->_mode == 'auto_renew' ? 'membership_autorenew_cancelled' : 'contribution_recurring_cancelled',
             'contactId' => $this->getSubscriptionDetails()->contact_id,
             'tplParams' => $tplParams,
             'tokenContext' => ['contribution_recurId' => $this->getContributionRecurID()],
index 6df7ba092af13bab47520712872b5bcbd5e72bce..272a7ed2341e001ca551a461b292ab47801bb95c 100644 (file)
@@ -323,7 +323,7 @@ class CRM_Contribute_Form_UpdateBilling extends CRM_Contribute_Form_Contribution
 
       $sendTemplateParams = array(
         'groupName' => $this->getSubscriptionDetails()->membership_id ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution',
-        'valueName' => $this->getSubscriptionDetails()->membership_id ? 'membership_autorenew_billing' : 'contribution_recurring_billing',
+        'workflow' => $this->getSubscriptionDetails()->membership_id ? 'membership_autorenew_billing' : 'contribution_recurring_billing',
         'contactId' => $this->getSubscriptionDetails()->contact_id,
         'tplParams' => $tplParams,
         'isTest' => $this->getSubscriptionDetails()->is_test,
index ea02ea7d633a75790e5f93eae90a8f5b9260ebe5..42f956c33d0a6d1af0c441fe3f89785bf644d731 100644 (file)
@@ -303,7 +303,7 @@ class CRM_Contribute_Form_UpdateSubscription extends CRM_Contribute_Form_Contrib
 
         $sendTemplateParams = [
           'groupName' => 'msg_tpl_workflow_contribution',
-          'valueName' => 'contribution_recurring_edit',
+          'workflow' => 'contribution_recurring_edit',
           'contactId' => $contactID,
           'tplParams' => ['receipt_from_email' => $receiptFrom],
           'isTest' => $this->_subscriptionDetails->is_test,
index 39228848c76741209b3e7fb200486ab95d21006e..a34afa9cd77e36abff73159229aebc2f9f6878a7 100644 (file)
@@ -287,8 +287,8 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate implemen
     $modelDefaults = [
       // instance of WorkflowMessageInterface, containing a list of data to provide to the message-template
       'model' => NULL,
-      // Symbolic name of the workflow step. Matches the option-value-name of the template.
-      'valueName' => NULL,
+      // Symbolic name of the workflow step. Matches the value in civicrm_msg_template.workflow_name.
+      'workflow' => NULL,
       // additional template params (other than the ones already set in the template singleton)
       'tplParams' => [],
       // additional token params (passed to the TokenProcessor)
@@ -343,7 +343,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate implemen
     $params = array_merge($modelDefaults, $viewDefaults, $envelopeDefaults, $params);
 
     CRM_Utils_Hook::alterMailParams($params, 'messageTemplate');
-    $mailContent = self::loadTemplate((string) $params['valueName'], $params['isTest'], $params['messageTemplateID'] ?? NULL, $params['groupName'] ?? '', $params['messageTemplate'], $params['subject'] ?? NULL);
+    $mailContent = self::loadTemplate((string) $params['workflow'], $params['isTest'], $params['messageTemplateID'] ?? NULL, $params['groupName'] ?? '', $params['messageTemplate'], $params['subject'] ?? NULL);
 
     self::synchronizeLegacyParameters($params);
     $rendered = CRM_Core_TokenSmarty::render(CRM_Utils_Array::subset($mailContent, ['text', 'html', 'subject']), $params['tokenContext'], $params['tplParams']);
@@ -363,6 +363,9 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate implemen
    * @param array $params
    */
   private static function synchronizeLegacyParameters(&$params) {
+    // 'valueName' is deprecated, docs were updated some time back
+    // and people have been notified. Having it here means the
+    // hooks will still see it until we remove.
     CRM_Utils_Array::pathSync($params, ['workflow'], ['valueName']);
     CRM_Utils_Array::pathSync($params, ['tokenContext', 'contactId'], ['contactId']);
     CRM_Utils_Array::pathSync($params, ['tokenContext', 'smarty'], ['disableSmarty'], function ($v, bool $isCanon) {
@@ -505,7 +508,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate implemen
       // Group name & valueName are deprecated parameters. At some point it will not be passed out.
       // https://github.com/civicrm/civicrm-core/pull/17180
       'groupName' => $groupName,
-      'valueName' => $workflowName,
+      'workflow' => $workflowName,
     ];
 
     CRM_Utils_Hook::alterMailContent($mailContent);
index 2732cf5739d1005e3ae23da0409757b4aee97bbe..7007ad71142b2fa471fc8c4e789f10bf5ec52d27 100644 (file)
@@ -2690,7 +2690,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       CRM_Core_BAO_MessageTemplate::sendTemplate(
         [
           'groupName' => 'msg_tpl_workflow_uf',
-          'valueName' => 'uf_notify',
+          'workflow' => 'uf_notify',
           'contactId' => $contactID,
           'tplParams' => [
             'displayName' => $displayName,
index 5f0f604cd7b77dc523f502ff51b9c4d016507094..6e31f5bef43d6247f653710ccabf31bd3a3a3b35 100644 (file)
@@ -1190,7 +1190,7 @@ WHERE civicrm_event.is_active = 1
 
         $sendTemplateParams = [
           'groupName' => 'msg_tpl_workflow_event',
-          'valueName' => 'event_online_receipt',
+          'workflow' => 'event_online_receipt',
           'contactId' => $contactID,
           'isTest' => $isTest,
           'tplParams' => $tplParams,
index a6db5abdd92a08d20af067b0b352ca46f02745d4..3bc858f0a649f3ebc1c5c3acfafe5bbe472304ac 100644 (file)
@@ -399,7 +399,7 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form {
 
       $sendTemplateParams = [
         'groupName' => 'msg_tpl_workflow_event',
-        'valueName' => 'event_online_receipt',
+        'workflow' => 'event_online_receipt',
         'contactId' => $participantDetails[$participant->id]['contact_id'],
         'tplParams' => $tplParams,
         'from' => $receiptFrom,
index 874fc38a283f9d1d0933f2aee319437318825e9f..17b03cec0fc13ee4c37f409c44e345735f3cb8eb 100644 (file)
@@ -281,7 +281,7 @@ class CRM_Financial_BAO_Payment {
 
     $sendTemplateParams = [
       'groupName' => 'msg_tpl_workflow_contribution',
-      'valueName' => 'payment_or_refund_notification',
+      'workflow' => 'payment_or_refund_notification',
       'PDFFilename' => ts('notification') . '.pdf',
       'contactId' => $entities['contact']['id'],
       'toName' => $entities['contact']['display_name'],
index 8e92204caa2a795645cf4c6bbb4a0ad847df760b..39a090dc78daea2f9068e759426a5a209e4a1afb 100644 (file)
@@ -289,7 +289,7 @@ class CRM_Friend_BAO_Friend extends CRM_Friend_DAO_Friend {
 
     $templateParams = [
       'groupName' => 'msg_tpl_workflow_friend',
-      'valueName' => 'friend',
+      'workflow' => 'friend',
       'contactId' => $contactID,
       'tplParams' => [
         $values['module'] => $values['module'],
index c6138349eb75200990298d8258bd509cc410ddbb..f59b1ea386931d9778d94bee1f5cb62172c0c2df 100644 (file)
@@ -716,7 +716,7 @@ WHERE pcp.id = %1 AND cc.contribution_status_id = %2 AND cc.is_test = 0";
     list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(
       [
         'groupName' => 'msg_tpl_workflow_contribution',
-        'valueName' => $tplName,
+        'workflow' => $tplName,
         'contactId' => $pcpInfo['contact_id'],
         'tplParams' => $tplParams,
         'from' => $receiptFrom,
index bf24d4ce25da351c40ccb49ed1755a901ab5b844..59421cdd42b2445696654d5d0f37423b885f93ba 100644 (file)
@@ -315,7 +315,7 @@ class CRM_PCP_Form_Campaign extends CRM_Core_Form {
       list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(
         [
           'groupName' => 'msg_tpl_workflow_contribution',
-          'valueName' => 'pcp_notify',
+          'workflow' => 'pcp_notify',
           'contactId' => $contactID,
           'from' => "$domainEmailName <$domainEmailAddress>",
           'toEmail' => $to,
index 112a3eefe50b638f5b6ed6a81dd474ae09408c69..2c53936daa16dc56547dc4d3541fb96bf6cc72e0 100644 (file)
@@ -595,7 +595,7 @@ GROUP BY  currency
     [$sent, $subject, $message, $html] = CRM_Core_BAO_MessageTemplate::sendTemplate(
       [
         'groupName' => 'msg_tpl_workflow_pledge',
-        'valueName' => 'pledge_acknowledge',
+        'workflow' => 'pledge_acknowledge',
         'contactId' => $params['contact_id'],
         'from' => $receiptFrom,
         'toName' => $pledgerDisplayName,
@@ -962,7 +962,7 @@ SELECT  pledge.contact_id              as contact_id,
             ] = CRM_Core_BAO_MessageTemplate::sendTemplate(
               [
                 'groupName' => 'msg_tpl_workflow_pledge',
-                'valueName' => 'pledge_reminder',
+                'workflow' => 'pledge_reminder',
                 'contactId' => $contactId,
                 'from' => $receiptFrom,
                 'toName' => $pledgerName,
index b75e43df5b32a01d141d806275e8694303eb85e0..40a7a559086d0946d3e620e0ea990895425b0e6c 100644 (file)
@@ -93,18 +93,27 @@ function civicrm_api3_message_template_send($params) {
   _civicrm_api3_message_template_send_spec($fieldSpec);
 
   foreach ($fieldSpec as $field => $spec) {
-    if (isset($spec['api.aliases']) && array_key_exists($field, $params)) {
+    // There is some dark magic going on here.
+    // The point of the 'api.aliases' metadata is generally
+    // to ensure that old params can be passed in and they still work.
+    // However, in this case the api params don't match the BAO
+    // params so the names that have been determined as
+    // 'right' for the api are being transformed into
+    // the 'wrong' BAO ones. It works, it's tested &
+    // we can do better in apiv4 once we get a suitable
+    // api there.
+    if ($spec['name'] !== 'workflow' && isset($spec['api.aliases']) && array_key_exists($field, $params)) {
       $params[CRM_Utils_Array::first($spec['api.aliases'])] = $params[$field];
       unset($params[$field]);
     }
   }
   if (empty($params['messageTemplateID'])) {
-    if (empty($params['valueName'])) {
+    if (empty($params['workflow'])) {
       // Can't use civicrm_api3_verify_mandatory for this because it would give the wrong field names
       throw new API_Exception(
-        'Mandatory key(s) missing from params array: requires id or option_value_name',
+        'Mandatory key(s) missing from params array: requires id or workflow',
         'mandatory_missing',
-        ['fields' => ['id', 'option_value_name']]
+        ['fields' => ['id', 'workflow']]
       );
     }
   }
@@ -126,10 +135,11 @@ function _civicrm_api3_message_template_send_spec(&$params) {
   $params['id']['api.aliases'] = ['messageTemplateID', 'message_template_id'];
   $params['id']['type'] = CRM_Utils_Type::T_INT;
 
-  $params['option_value_name']['description'] = 'option value name of the template (required if no id supplied)';
-  $params['option_value_name']['title'] = 'Option Value Name';
-  $params['option_value_name']['api.aliases'] = ['valueName'];
-  $params['option_value_name']['type'] = CRM_Utils_Type::T_STRING;
+  $params['workflow']['description'] = 'option value name of the template (required if no id supplied)';
+  $params['workflow']['title'] = ts('Workflow');
+  $params['workflow']['api.aliases'] = ['option_value_name', 'valueName'];
+  $params['workflow']['type'] = CRM_Utils_Type::T_STRING;
+  $params['workflow']['name'] = 'workflow';
 
   $params['contact_id']['description'] = 'contact id if contact tokens are to be replaced';
   $params['contact_id']['title'] = 'Contact ID';
index 6c831f39904197e3cb22b7b3f1f05edb9ac4c585..b61142c29a8a3752d862840403b578819ab0c3eb 100644 (file)
@@ -341,7 +341,7 @@ class CRM_Event_Cart_Form_Checkout_Payment extends CRM_Event_Cart_Form_Cart {
         'is_pay_later' => $this->is_pay_later,
         'pay_later_receipt' => $this->pay_later_receipt,
       ],
-      'valueName' => 'event_registration_receipt',
+      'workflow' => 'event_registration_receipt',
       'PDFFilename' => ts('confirmation') . '.pdf',
     ];
     $template_params_to_copy = [
index 0f44b3a9aaa4cad3770d59590d0466f1789a63b0..22675616f6965c0c74b96376234f95c784f8abd6 100644 (file)
@@ -30,7 +30,7 @@ class CRM_Core_BAO_MessageTemplateTest extends CiviUnitTestCase {
       'suffix_id' => NULL,
     ]);
     $rendered = CRM_Core_BAO_MessageTemplate::renderTemplate([
-      'valueName' => 'case_activity',
+      'workflow' => 'case_activity',
       'tokenContext' => [
         'contactId' => $contactId,
       ],
@@ -58,7 +58,7 @@ class CRM_Core_BAO_MessageTemplateTest extends CiviUnitTestCase {
     ]);
     [$sent, $subject, $messageText, $messageHtml] = CRM_Core_BAO_MessageTemplate::sendTemplate(
       [
-        'valueName' => 'case_activity',
+        'workflow' => 'case_activity',
         'contactId' => $contactId,
         'from' => 'admin@example.com',
         // No 'toEmail'/'toName' address => not sendable, but still returns rendered value.
@@ -99,7 +99,7 @@ class CRM_Core_BAO_MessageTemplateTest extends CiviUnitTestCase {
 
       [$sent, $subject, $messageText, $messageHtml] = CRM_Core_BAO_MessageTemplate::sendTemplate(
         [
-          'valueName' => 'case_activity',
+          'workflow' => 'case_activity',
           'contactId' => $contactId,
           'from' => 'admin@example.com',
           // No 'toEmail'/'toName' address => not sendable, but still returns rendered value.
@@ -137,7 +137,7 @@ class CRM_Core_BAO_MessageTemplateTest extends CiviUnitTestCase {
 
       [$sent, $subject, $messageText, $messageHtml] = CRM_Core_BAO_MessageTemplate::sendTemplate(
         [
-          'valueName' => 'case_activity',
+          'workflow' => 'case_activity',
           'tokenContext' => [
             'contactId' => $contactId,
             'activityId' => $activityId,
@@ -188,7 +188,7 @@ class CRM_Core_BAO_MessageTemplateTest extends CiviUnitTestCase {
     $this->assertEquals([], \Civi\Test\Invasive::get([$msg, '_extras']));
 
     [, $subject, $message] = $msg->sendTemplate([
-      'valueName' => 'case_activity',
+      'workflow' => 'case_activity',
       'from' => 'admin@example.com',
       'toName' => 'Demo',
       'toEmail' => 'admin@example.com',
@@ -217,7 +217,7 @@ class CRM_Core_BAO_MessageTemplateTest extends CiviUnitTestCase {
     $tokenString = '{domain.' . implode('} ~ {domain.', array_keys($values)) . '}';
 
     $messageContent = CRM_Core_BAO_MessageTemplate::renderTemplate([
-      'valueName' => 'dummy',
+      'workflow' => 'dummy',
       'messageTemplate' => [
         'msg_html' => $tokenString,
         // Check the space is stripped.
@@ -241,7 +241,7 @@ London, 90210
    */
   public function testRenderTemplateSmarty(): void {
     $messageContent = CRM_Core_BAO_MessageTemplate::renderTemplate([
-      'valueName' => 'dummy',
+      'workflow' => 'dummy',
       'messageTemplate' => [
         'msg_html' => '{$tokenString}',
         // Check the space is stripped.
@@ -261,7 +261,7 @@ London, 90210
    */
   public function testRenderTemplateIgnoreSmarty(): void {
     $messageContent = CRM_Core_BAO_MessageTemplate::renderTemplate([
-      'valueName' => 'dummy',
+      'workflow' => 'dummy',
       'messageTemplate' => [
         'msg_html' => '{$tokenString}',
         // Check the space is stripped.
@@ -308,7 +308,7 @@ London, 90210
       $tokenString .= "{$key}:{contact.{$key}}\n";
     }
     $messageContent = CRM_Core_BAO_MessageTemplate::renderTemplate([
-      'valueName' => 'dummy',
+      'workflow' => 'dummy',
       'messageTemplate' => [
         'msg_html' => $tokenString,
         // Check the space is stripped.