Commit 1f59fde31f556176e67a1c4933e4ecc3f386ffbb

Authored by Megan Watson
1 parent 33b20eaf

Updated the PDF converter to check if open office is running and to display a decent error message.

PT: 1549976

Committed by: Megan Watson
plugins/ktstandard/PDFGeneratorAction.php
@@ -255,9 +255,10 @@ class PDFGeneratorAction extends KTDocumentAction { @@ -255,9 +255,10 @@ class PDFGeneratorAction extends KTDocumentAction {
255 $converter->setDocument($this->oDocument); 255 $converter->setDocument($this->oDocument);
256 $res = $converter->processDocument(); 256 $res = $converter->processDocument();
257 257
258 - if(!$res){ 258 + if($res !== true){
  259 + // please contact your System Administrator
259 $default->log->error('PDF Generator: PDF file could not be generated'); 260 $default->log->error('PDF Generator: PDF file could not be generated');
260 - $this->errorRedirectToMain(_kt('PDF file could not be generated, the file may be of an unsupported mime type or the PDF Generator could not connect.')); 261 + $this->errorRedirectToMain($res . ' ' . _kt('Please contact your System Administrator for assistance.'));
261 exit(); 262 exit();
262 } 263 }
263 264
@@ -268,7 +269,22 @@ class PDFGeneratorAction extends KTDocumentAction { @@ -268,7 +269,22 @@ class PDFGeneratorAction extends KTDocumentAction {
268 } 269 }
269 exit(); 270 exit();
270 } 271 }
271 - $this->errorRedirectToMain(_kt('PDF file could not be generated')); 272 +
  273 + // Check if this is a office 2007 doc
  274 + $mime = $this->getMimeExtension();
  275 +
  276 + $o2007_types[] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
  277 + $o2007_types[] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
  278 + $o2007_types[] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
  279 +
  280 + if(in_array($mime, $o2007_types)){
  281 + $error = _kt('The document is an MS Office 2007 format. This may not be supported by your version of OpenOffice. Please contact your System Administrator for assistance');
  282 + $default->log->error('PDF Generator: Document is an MS Office 2007 format. OpenOffice must be version 3.0 or higher to support this format. Please upgrade to the latest version.');
  283 + }else{
  284 + $error = _kt('PDF file could not be generated. The format may not be supported by your version of OpenOffice. Please contact your System Administrator for assistance');
  285 + $default->log->error('PDF Generator: PDF file could not be generated. The format may not be supported by your version of OpenOffice. Please check that you have the latest version installed.');
  286 + }
  287 + $this->errorRedirectToMain($error);
272 exit(); 288 exit();
273 } 289 }
274 290
plugins/pdfConverter/pdfConverter.php
@@ -48,6 +48,25 @@ class pdfConverter extends BaseProcessor @@ -48,6 +48,25 @@ class pdfConverter extends BaseProcessor
48 $this->ooPort = $config->get('openoffice/port','8100'); 48 $this->ooPort = $config->get('openoffice/port','8100');
49 49
50 $this->xmlrpc = XmlRpcLucene::get($javaServerUrl); 50 $this->xmlrpc = XmlRpcLucene::get($javaServerUrl);
  51 +
  52 +
  53 +
  54 + }
  55 +
  56 + /**
  57 + * Check that open office is running
  58 + *
  59 + * @return boolean
  60 + */
  61 + private function checkOO()
  62 + {
  63 + $available = SearchHelper::checkOpenOfficeAvailablity();
  64 +
  65 + if(is_null($available)){
  66 + return true;
  67 + }
  68 +
  69 + return false;
51 } 70 }
52 71
53 /** 72 /**
@@ -63,17 +82,26 @@ class pdfConverter extends BaseProcessor @@ -63,17 +82,26 @@ class pdfConverter extends BaseProcessor
63 82
64 if(!file_exists($path)){ 83 if(!file_exists($path)){
65 global $default; 84 global $default;
66 - $default->log->debug('Document, id: '.$this->document->iId.', does not exist at given storage path: '.$path);  
67 - return false; 85 + $default->log->debug('PDF Converter: Document, id: '.$this->document->iId.', does not exist at given storage path: '.$path);
  86 + return _kt("The document, id: {$this->document->iId}, does not exist at the given storage path: {$path}");
68 } 87 }
69 88
  89 + // check for OO
  90 + $available = $this->checkOO();
  91 +
70 // do pdf conversion 92 // do pdf conversion
  93 + if(!$available){
  94 + global $default;
  95 + $default->log->error("PDF Converter: Cannot connect to Open Office Server on host {$this->ooHost} : {$this->ooPort}");
  96 + return _kt('Cannot connect to Open Office Server.');
  97 + }
  98 +
71 $res = $this->convertFile($path, $ext); 99 $res = $this->convertFile($path, $ext);
72 100
73 - if($res === false){ 101 + if($res !== true){
74 global $default; 102 global $default;
75 - $default->log->debug('Document, id: '.$this->document->iId.', could not be converted to pdf.');  
76 - return false; 103 + $default->log->debug('PDF Converter: Document, id: '.$this->document->iId.', could not be converted to pdf.');
  104 + return _kt("The document, id: {$this->document->iId}, could not be converted to pdf format. The following error occurred: \"{$res}\".");
77 } 105 }
78 106
79 return true; 107 return true;
@@ -169,11 +197,11 @@ class pdfConverter extends BaseProcessor @@ -169,11 +197,11 @@ class pdfConverter extends BaseProcessor
169 // Get contents and send to converter 197 // Get contents and send to converter
170 $result = $this->xmlrpc->convertDocument($sourceFile, $targetFile, $this->ooHost, $this->ooPort); 198 $result = $this->xmlrpc->convertDocument($sourceFile, $targetFile, $this->ooHost, $this->ooPort);
171 199
172 - if($result === false){ 200 + if(is_string($result)){
173 $default->log->error('PDF Converter Plugin: Conversion to PDF Failed'); 201 $default->log->error('PDF Converter Plugin: Conversion to PDF Failed');
174 @unlink($sourceFile); 202 @unlink($sourceFile);
175 @unlink($targetFile); 203 @unlink($targetFile);
176 - return false; 204 + return $result;
177 } 205 }
178 206
179 $pdfDir = $default->pdfDirectory; 207 $pdfDir = $default->pdfDirectory;
@@ -196,7 +224,7 @@ class pdfConverter extends BaseProcessor @@ -196,7 +224,7 @@ class pdfConverter extends BaseProcessor
196 $res = @copy($targetFile, $pdfFile); 224 $res = @copy($targetFile, $pdfFile);
197 @unlink($sourceFile); 225 @unlink($sourceFile);
198 @unlink($targetFile); 226 @unlink($targetFile);
199 - return $pdfFile; 227 + return true;
200 228
201 } 229 }
202 } 230 }
search2/indexing/lib/XmlRpcLucene.inc.php
@@ -416,7 +416,7 @@ class XmlRpcLucene @@ -416,7 +416,7 @@ class XmlRpcLucene
416 416
417 if($result->faultCode()) { 417 if($result->faultCode()) {
418 $this->error($result, 'convertDocument'); 418 $this->error($result, 'convertDocument');
419 - return false; 419 + return $result->faultString();
420 } 420 }
421 return php_xmlrpc_decode($result->value()) == 0; 421 return php_xmlrpc_decode($result->value()) == 0;
422 } 422 }