From: Tim Otten Date: Thu, 13 Apr 2017 03:25:22 +0000 (-0700) Subject: CRM-20420 - CRM_Utils_PDF_Document::printDocuments - Normalize $fileName X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=63c8a9bac1696f2a0fe045e72902e22394409194;p=civicrm-core.git CRM-20420 - CRM_Utils_PDF_Document::printDocuments - Normalize $fileName Normalize semantics of `$fileName` to align with `CRM_Utils_PDF_Document::html2doc` and `CRM_Utils_PDF_Utils::html2pdf`. --- diff --git a/CRM/Contact/Form/Task/PDFLetterCommon.php b/CRM/Contact/Form/Task/PDFLetterCommon.php index 6cf5a7bbf7..404f2ef0d6 100644 --- a/CRM/Contact/Form/Task/PDFLetterCommon.php +++ b/CRM/Contact/Form/Task/PDFLetterCommon.php @@ -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); diff --git a/CRM/Utils/PDF/Document.php b/CRM/Utils/PDF/Document.php index 08b817872c..6120321df6 100644 --- a/CRM/Utils/PDF/Document.php +++ b/CRM/Utils/PDF/Document.php @@ -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); } diff --git a/tests/phpunit/CRM/Contact/Form/Task/PrintDocumentTest.php b/tests/phpunit/CRM/Contact/Form/Task/PrintDocumentTest.php index 3571b7ec07..5f9095e5ab 100644 --- a/tests/phpunit/CRM/Contact/Form/Task/PrintDocumentTest.php +++ b/tests/phpunit/CRM/Contact/Form/Task/PrintDocumentTest.php @@ -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);