Don't bypass hooks when updating contribution receipt/thankyou date
authorMatthew Wire <devel@mrwire.co.uk>
Wed, 8 Nov 2017 14:10:42 +0000 (14:10 +0000)
committerMatthew Wire <devel@mrwire.co.uk>
Wed, 22 Nov 2017 18:26:58 +0000 (18:26 +0000)
CRM/Contribute/Form/Task/PDFLetterCommon.php

index 2aa925542ac0fd81237d08344e80f4f28cf92451..370900a74f198d08aa7d6e3f6dace3f28bc801f0 100644 (file)
@@ -89,19 +89,18 @@ class CRM_Contribute_Form_Task_PDFLetterCommon extends CRM_Contact_Form_Task_PDF
         }
         $contact['is_sent'][$groupBy][$groupByID] = TRUE;
       }
-      // update dates (do it for each contribution including grouped recurring contribution)
-      //@todo - the 2 calls below bypass all hooks. Using the api would possibly be slower than one call but not than 2
+      // Update receipt/thankyou dates
+      $contributionParams = array('id' => $contributionId);
       if ($receipt_update) {
-        $result = CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'receipt_date', $nowDate);
-        if ($result) {
-          $receipts++;
-        }
+        $contributionParams['receipt_date'] = $nowDate;
       }
       if ($thankyou_update) {
-        $result = CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'thankyou_date', $nowDate);
-        if ($result) {
-          $thanks++;
-        }
+        $contributionParams['thankyou_date'] = $nowDate;
+      }
+      if ($receipt_update || $thankyou_update) {
+        civicrm_api3('Contribution', 'create', $contributionParams);
+        $receipts = ($receipt_update ? $receipts + 1 : $receipts);
+        $thanks = ($thankyou_update ? $thanks + 1 : $thanks);
       }
     }