Add Contributor Name to Offline Contribution Receipts
[civicrm-core.git] / CRM / Upgrade / Incremental / MessageTemplates.php
index 2ca5e17d9c7daa8f55ed868b3fc05115e5dd693d..2768fc69b1ea6ddfe5a3b6b6c3dc7453b637bde8 100644 (file)
@@ -192,6 +192,21 @@ class CRM_Upgrade_Incremental_MessageTemplates {
           ['name' => 'test_preview', 'type' => 'html'],
         ],
       ],
+      [
+        'version' => '5.21.beta1',
+        'upgrade_descriptor' => ts('Fix Membership Receipt'),
+        'templates' => [
+          ['name' => 'membership_online_receipt', 'type' => 'html'],
+        ],
+      ],
+      [
+        'version' => '5.23.alpha1',
+        'upgrade_descriptor' => ts('Add Contributor Name to Offline Contribution receipts'),
+        'templates' => [
+          ['name' => 'contribution_offline_receipt', 'type' => 'text'],
+          ['name' => 'contribution_offline_receipt', 'type' => 'html'],
+        ],
+      ],
 
     ];
   }
@@ -251,7 +266,12 @@ class CRM_Upgrade_Incremental_MessageTemplates {
       $content = file_get_contents(\Civi::paths()->getPath('[civicrm.root]/xml/templates/message_templates/' . $template['name'] . '_' . $template['type'] . '.tpl'));
       $templatesToUpdate = [];
       if (!empty($workFlowID)) {
-        $templatesToUpdate[] = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_msg_template WHERE workflow_id = $workFlowID AND is_reserved = 1");
+        // This could be empty if the template was deleted. It should not happen,
+        // but has been seen in the wild (ex: marketing/civicrm-website#163).
+        $id = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_msg_template WHERE workflow_id = $workFlowID AND is_reserved = 1");
+        if ($id) {
+          $templatesToUpdate[] = $id;
+        }
         $defaultTemplateID = CRM_Core_DAO::singleValueQuery("
           SELECT default_template.id FROM civicrm_msg_template reserved
           LEFT JOIN civicrm_msg_template default_template
@@ -264,11 +284,13 @@ class CRM_Upgrade_Incremental_MessageTemplates {
           $templatesToUpdate[] = $defaultTemplateID;
         }
 
-        CRM_Core_DAO::executeQuery("
-          UPDATE civicrm_msg_template SET msg_{$template['type']} = %1 WHERE id IN (" . implode(',', $templatesToUpdate) . ")", [
-            1 => [$content, 'String'],
-          ]
-        );
+        if (!empty($templatesToUpdate)) {
+          CRM_Core_DAO::executeQuery("
+            UPDATE civicrm_msg_template SET msg_{$template['type']} = %1 WHERE id IN (" . implode(',', $templatesToUpdate) . ")", [
+              1 => [$content, 'String'],
+            ]
+          );
+        }
       }
     }
   }