CRM-20420 - PDFLetterCommon::postProcess - Improve precondition check
authorTim Otten <totten@civicrm.org>
Thu, 13 Apr 2017 17:20:31 +0000 (10:20 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 13 Apr 2017 17:20:31 +0000 (10:20 -0700)
It's not valid to apply the policy `combined-attached` unless you have
exactly 1 activity.  The previous code would silently degrade if the
precondition wasn't met. The revision makes the failure clear.

CRM/Contact/Form/Task/PDFLetterCommon.php

index add44a19ef2afda2865e53e9d7fe73aa5b409964..979488a615aa7274936bb2e67c5e50cc509e7d19 100644 (file)
@@ -410,8 +410,12 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
       $html[] = $tokenHtml;
     }
 
-    $saveToFile = count($activityIds) === 1 && Civi::settings()->get('recordGeneratedLetters') === 'combined-attached';
+    $saveToFile = Civi::settings()->get('recordGeneratedLetters') === 'combined-attached';
     if ($saveToFile) {
+      if (count($activityIds) !== 1) {
+        throw new CRM_Core_Exception("When recordGeneratedLetters=combined-attached, there should only be one activity.");
+      }
+
       // We need to capture data from various output-generators whose only
       // consistent output format is writing to the console (for download).
       $tmpFile = tempnam(sys_get_temp_dir(), 'PDFLetterCommon-');