From bdac10d8e5bf8405bb444a8bbb8ffb3041304b2d Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 13 Apr 2017 10:20:31 -0700 Subject: [PATCH] CRM-20420 - PDFLetterCommon::postProcess - Improve precondition check 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/Form/Task/PDFLetterCommon.php b/CRM/Contact/Form/Task/PDFLetterCommon.php index add44a19ef..979488a615 100644 --- a/CRM/Contact/Form/Task/PDFLetterCommon.php +++ b/CRM/Contact/Form/Task/PDFLetterCommon.php @@ -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-'); -- 2.25.1