CRM-20420 - CRM_Utils_PDF_Document::printDocuments - Normalize $fileName
authorTim Otten <totten@civicrm.org>
Thu, 13 Apr 2017 03:25:22 +0000 (20:25 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 13 Apr 2017 05:16:29 +0000 (22:16 -0700)
Normalize semantics of `$fileName` to align with
`CRM_Utils_PDF_Document::html2doc` and `CRM_Utils_PDF_Utils::html2pdf`.

CRM/Contact/Form/Task/PDFLetterCommon.php
CRM/Utils/PDF/Document.php
tests/phpunit/CRM/Contact/Form/Task/PrintDocumentTest.php

index 6cf5a7bbf7b82f7547af4136df99bb7859c48cc0..404f2ef0d6d36bb31a423ab64901d8d46896de36 100644 (file)
@@ -416,7 +416,8 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
       CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues);
     }
     elseif (!empty($formValues['document_file_path'])) {
-      CRM_Utils_PDF_Document::printDocuments($formValues['document_file_path'], $html, $type, $zip);
+      $fileName = pathinfo($formValues['document_file_path'], PATHINFO_FILENAME) . '.' . $type;
+      CRM_Utils_PDF_Document::printDocuments($html, $fileName, $type, $zip);
     }
     else {
       CRM_Utils_PDF_Document::html2doc($html, "CiviLetter.$type", $formValues);
index 08b817872c2bce7679e361fa66d882fd241b7e50..6120321df6497923d020f5c254f4de1817dc860b 100644 (file)
@@ -174,11 +174,11 @@ class CRM_Utils_PDF_Document {
   /**
    * Modify contents of docx/odt file(s) and later merged into one final document
    *
-   * @param string $filePath
-   *   Document file path
    * @param array $contents
    *   Content of formatted/token-replaced document.
    *   List of HTML snippets.
+   * @param string $fileName
+   *   Document file name
    * @param string $docType
    *   Document type e.g. odt/docx
    * @param clsTbsZip $zip
@@ -188,7 +188,7 @@ class CRM_Utils_PDF_Document {
    *
    * @return string
    */
-  public static function printDocuments($filePath, $contents, $docType, $zip, $returnFinalContent = FALSE) {
+  public static function printDocuments($contents, $fileName, $docType, $zip, $returnFinalContent = FALSE) {
     $dataMap = self::$ooxmlMap[$docType];
 
     $finalContent = $zip->FileRead($dataMap['dataFile']);
@@ -217,7 +217,6 @@ class CRM_Utils_PDF_Document {
     // Replace the loaded document file content located at $filePath with $finaContent
     $zip->FileReplace($dataMap['dataFile'], $finalContent, TBSZIP_STRING);
 
-    $fileName = pathinfo($filePath, PATHINFO_FILENAME) . '.' . $docType;
     $zip->Flush(TBSZIP_DOWNLOAD, $fileName);
   }
 
index 3571b7ec070a346221c5d391cda17fc80aef0955..5f9095e5ab9cf73fe3de68c1306da38937779c97 100644 (file)
@@ -84,7 +84,8 @@ class CRM_Contact_Form_Task_PrintDocumentTest extends CiviUnitTestCase {
       $html[] = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken);
     }
 
-    $returnContent = CRM_Utils_PDF_Document::printDocuments($formValues['document_file_path'], $html, $type, $zip, TRUE);
+    $fileName = pathinfo($formValues['document_file_path'], PATHINFO_FILENAME) . '.' . $type;
+    $returnContent = CRM_Utils_PDF_Document::printDocuments($html, $fileName, $type, $zip, TRUE);
     $returnContent = strip_tags($returnContent);
 
     $this->assertTrue(strpos($returnContent, 'Hello Antonia D`souza') !== 0);