Commit fd7c5b1243c3fd998de5c38c4f3e184b5d34d79c
1 parent
6f3966ab
Fixed wrong filename document after PDF conversion
Showing
1 changed file
with
9 additions
and
6 deletions
plugins/ktstandard/PDFGeneratorWorkflowTriggers.php
| @@ -35,7 +35,7 @@ | @@ -35,7 +35,7 @@ | ||
| 35 | * Contributor( s): thePanz (thepanz@gmail.com) | 35 | * Contributor( s): thePanz (thepanz@gmail.com) |
| 36 | * | 36 | * |
| 37 | */ | 37 | */ |
| 38 | - | 38 | + |
| 39 | require_once(KT_LIB_DIR . '/workflow/workflowtrigger.inc.php'); | 39 | require_once(KT_LIB_DIR . '/workflow/workflowtrigger.inc.php'); |
| 40 | require_once(KT_DIR . '/plugins/pdfConverter/pdfConverter.php'); | 40 | require_once(KT_DIR . '/plugins/pdfConverter/pdfConverter.php'); |
| 41 | 41 | ||
| @@ -86,7 +86,7 @@ class PDFGeneratorWorkflowTriggerDuplicatePDF extends KTWorkflowTrigger { | @@ -86,7 +86,7 @@ class PDFGeneratorWorkflowTriggerDuplicatePDF extends KTWorkflowTrigger { | ||
| 86 | return $pdfFile; | 86 | return $pdfFile; |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | - $default->log->error("Duplicate_Copy the Document"); | 89 | + $default->log->error("Duplicate-and-Copy the Document"); |
| 90 | // Duplicate/Copy the Document | 90 | // Duplicate/Copy the Document |
| 91 | $oNewDocument = KTDocumentUtil::copy($oDocument, $oToFolder); | 91 | $oNewDocument = KTDocumentUtil::copy($oDocument, $oToFolder); |
| 92 | if (PEAR::isError($oNewDocument)) { | 92 | if (PEAR::isError($oNewDocument)) { |
| @@ -102,14 +102,18 @@ class PDFGeneratorWorkflowTriggerDuplicatePDF extends KTWorkflowTrigger { | @@ -102,14 +102,18 @@ class PDFGeneratorWorkflowTriggerDuplicatePDF extends KTWorkflowTrigger { | ||
| 102 | 102 | ||
| 103 | $res = KTDocumentUtil::storeContents($oNewDocument, $oContents = null, $aOptions); | 103 | $res = KTDocumentUtil::storeContents($oNewDocument, $oContents = null, $aOptions); |
| 104 | if (PEAR::isError($res)) { | 104 | if (PEAR::isError($res)) { |
| 105 | - $default->log->error("PDF WorkflowTrigger error: can't associate PDF file to document." . $res->message); | 105 | + $default->log->error("PDF Error: can't associate PDF file to document. storeDocument error = " . $res->message); |
| 106 | // Remove the created document (not-correct) | 106 | // Remove the created document (not-correct) |
| 107 | KTDocumentUtil::delete($oNewDocument, _kt("PDF WorkflowTrigger error: can't create associate PDF file to document.")); | 107 | KTDocumentUtil::delete($oNewDocument, _kt("PDF WorkflowTrigger error: can't create associate PDF file to document.")); |
| 108 | return $res; | 108 | return $res; |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | + // Change filename reporeted by Document: renamed to .PDF | ||
| 112 | + // TODO: maybe use the KTDocumentUtil::rename($oDocument, $sFilename, $oUser) for rename+MimeType? | ||
| 113 | + $sFilename= pathinfo($oNewDocument->getFileName(), PATHINFO_FILENAME); | ||
| 114 | + $oNewDocument->setFileName($sFilename . '.pdf'); | ||
| 115 | + | ||
| 111 | // Changing MIME-Filetype | 116 | // Changing MIME-Filetype |
| 112 | - // TODO: maybe use the KTDocumentUtil::rename($oDocument, $sFilename, $oUser) ? | ||
| 113 | $iMimeTypeId = KTMime::getMimeTypeID('application/pdf'); | 117 | $iMimeTypeId = KTMime::getMimeTypeID('application/pdf'); |
| 114 | $oNewDocument->setMimeTypeId($iMimeTypeId); | 118 | $oNewDocument->setMimeTypeId($iMimeTypeId); |
| 115 | 119 | ||
| @@ -132,17 +136,16 @@ class PDFGeneratorWorkflowTriggerDuplicatePDF extends KTWorkflowTrigger { | @@ -132,17 +136,16 @@ class PDFGeneratorWorkflowTriggerDuplicatePDF extends KTWorkflowTrigger { | ||
| 132 | $dir = $default->pdfDirectory; | 136 | $dir = $default->pdfDirectory; |
| 133 | $iDocId = $oDocument->iId; | 137 | $iDocId = $oDocument->iId; |
| 134 | $file = $dir .'/'. $iDocId . '.pdf'; | 138 | $file = $dir .'/'. $iDocId . '.pdf'; |
| 135 | - $default->log->error(__class__ . '::' . __function__ . '() PRE-CONV: '." file=$file'"); | ||
| 136 | if (!file_exists($file)) { | 139 | if (!file_exists($file)) { |
| 137 | // If not - create one | 140 | // If not - create one |
| 138 | $converter = new pdfConverter(); | 141 | $converter = new pdfConverter(); |
| 139 | $converter->setDocument($oDocument); | 142 | $converter->setDocument($oDocument); |
| 140 | $res = $converter->processDocument(); | 143 | $res = $converter->processDocument(); |
| 141 | if ($res !== true) { | 144 | if ($res !== true) { |
| 145 | + $default->log->error(__class__ . '::' . __function__ . '() PDF file could not be generated.'); | ||
| 142 | return PEAR::raiseError(_kt('PDF file could not be generated; Please contact your System Administrator for assistance.')); | 146 | return PEAR::raiseError(_kt('PDF file could not be generated; Please contact your System Administrator for assistance.')); |
| 143 | } | 147 | } |
| 144 | } | 148 | } |
| 145 | - $default->log->error(__class__ . '::' . __function__ . '() CONVERTED! : '." file=$file'"); | ||
| 146 | return $file; | 149 | return $file; |
| 147 | } | 150 | } |
| 148 | 151 |