Commit 610e1a78a3070150e2424795000e62e3106b31fc

Authored by kevin_fourie
1 parent 5ed30c96

Merged in from DEV trunk...

KTC-388
"remove Dev comment from config file at [user_prefs]"
Removed.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-3070
"Path not found when generating PDFs"
Fixed. Paths updated.

KTS-3096
"Import from Server Locaton, get a python error."
Fixed. Paths updated.

KTS-3074
"Location of OpenOffice in the stack has changed"
Fixed. Paths updated.

Committed By: Kevin Fourie
Reviewed By: Jonnathan Byrne

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@8131 c91229c3-7414-0410-bfa2-8a42b809f60b
bin/openoffice/pdfgen.py
... ... @@ -84,7 +84,7 @@ except RuntimeException, e:
84 84 sys.stderr.write("An unknown error occured: " + e.Message + "\n")
85 85  
86 86 if doc == None:
87   - sys.stderr.write("Could not load doc.\n")
  87 + sys.stderr.write("OpenOffice could not load the document for conversion. This could indicate an unsupported minetype.\n")
88 88 sys.exit(1)
89 89  
90 90  
... ...
config/config.ini
... ... @@ -311,7 +311,6 @@ port = default
311 311  
312 312 [user_prefs]
313 313 ; minimum password length on password-setting
314   -; could be moved into DB-auth-config
315 314 passwordLength = 6
316 315  
317 316 ; apply the minimum password length to admin while creating / editing accounts?
... ...
config/dmsDefaults.php
... ... @@ -76,13 +76,14 @@ if (!defined('KT_LIB_DIR')) {
76 76 define('KT_LIB_DIR', KT_DIR . '/lib');
77 77 }
78 78  
79   -// If not defined, set KT_INSTALL_DIR based on my usual location in the tree
80   -if (!defined('KT_INSTALL_DIR')) {
81   - $installLoc = realpath(dirname(__FILE__) . '/../..');
  79 +// If not defined, set KT_STACK_DIR based on my usual location in the tree
  80 +// TODO: This needs to use a config.ini entry if available
  81 +if (!defined('KT_STACK_DIR')) {
  82 + $stackLoc = realpath(dirname(__FILE__) . '/../..');
82 83 if (substr(PHP_OS, 0, 3) == 'WIN') {
83   - $installLoc = str_replace('\\','/',$installLoc);
  84 + $stackLoc = str_replace('\\','/',$stackLoc);
84 85 }
85   - define('KT_INSTALL_DIR', $installLoc);
  86 + define('KT_STACK_DIR', $stackLoc);
86 87 }
87 88  
88 89  
... ...
lib/upgrades/UpgradeFunctions.inc.php
... ... @@ -1040,16 +1040,16 @@ class UpgradeFunctions {
1040 1040 // externalBinary Section
1041 1041 $ini->delSection('externalBinary');
1042 1042 if(OS_WINDOWS){
1043   - $ini->addItem('externalBinary', 'xls2csv', KT_INSTALL_DIR . '/bin/catdoc/xls2csv.exe', '', 'The following are external binaries that may be used by various parts of knowledgeTree.');
1044   - $ini->addItem('externalBinary', 'pdftotext', KT_INSTALL_DIR . '/bin/xpdf/pdftotext.exe');
1045   - $ini->addItem('externalBinary', 'catppt', KT_INSTALL_DIR . '/bin/catdoc/catppt.exe');
1046   - $ini->addItem('externalBinary', 'pstotext', KT_INSTALL_DIR . '/pstotext');
1047   - $ini->addItem('externalBinary', 'catdoc', KT_INSTALL_DIR . '/bin/catdoc/catdoc.exe');
1048   - $ini->addItem('externalBinary', 'antiword', KT_INSTALL_DIR . '/bin/antiword/antiword.exe');
1049   - $ini->addItem('externalBinary', 'python', KT_INSTALL_DIR . '/python.bat');
1050   - $ini->addItem('externalBinary', 'java', KT_INSTALL_DIR . '/java/jre/bin/java.exe');
1051   - $ini->addItem('externalBinary', 'php', KT_INSTALL_DIR . '/php/php.exe');
1052   - $ini->addItem('externalBinary', 'df', KT_INSTALL_DIR . '/bin/gnuwin32/df.exe');
  1043 + $ini->addItem('externalBinary', 'xls2csv', KT_STACK_DIR . '/bin/catdoc/xls2csv.exe', '', 'The following are external binaries that may be used by various parts of knowledgeTree.');
  1044 + $ini->addItem('externalBinary', 'pdftotext', KT_STACK_DIR . '/bin/xpdf/pdftotext.exe');
  1045 + $ini->addItem('externalBinary', 'catppt', KT_STACK_DIR . '/bin/catdoc/catppt.exe');
  1046 + $ini->addItem('externalBinary', 'pstotext', KT_STACK_DIR . '/bin/pstotext/pstotext.exe');
  1047 + $ini->addItem('externalBinary', 'catdoc', KT_STACK_DIR . '/bin/catdoc/catdoc.exe');
  1048 + $ini->addItem('externalBinary', 'antiword', KT_STACK_DIR . '/bin/antiword/antiword.exe');
  1049 + $ini->addItem('externalBinary', 'python', KT_STACK_DIR . '/openoffice/program/python.bat');
  1050 + $ini->addItem('externalBinary', 'java', KT_STACK_DIR . '/java/jre/bin/java.exe');
  1051 + $ini->addItem('externalBinary', 'php', KT_STACK_DIR . '/php/php.exe');
  1052 + $ini->addItem('externalBinary', 'df', KT_STACK_DIR . '/bin/gnuwin32/df.exe');
1053 1053  
1054 1054 } else {
1055 1055 $ini->addItem('externalBinary', 'xls2csv', 'xls2csv', '', 'The following are external binaries that may be used by various parts of knowledgeTree.');
... ... @@ -1057,7 +1057,7 @@ class UpgradeFunctions {
1057 1057 $ini->addItem('externalBinary', 'catppt', 'catppt');
1058 1058 $ini->addItem('externalBinary', 'pstotext', 'pstotext');
1059 1059 $ini->addItem('externalBinary', 'catdoc', 'catdoc');
1060   - $ini->addItem('externalBinary', 'antiword', '');
  1060 + $ini->addItem('externalBinary', 'antiword', 'antiword');
1061 1061 $ini->addItem('externalBinary', 'python', 'python');
1062 1062 $ini->addItem('externalBinary', 'java', 'java');
1063 1063 $ini->addItem('externalBinary', 'php', 'php');
... ...
lib/util/ktutil.inc
... ... @@ -704,7 +704,7 @@ class KTUtil {
704 704 case 'externalBinary/python':
705 705 if (OS_WINDOWS)
706 706 {
707   - $script = $stackPath . '/openoffice/openoffice/program/python.bat';
  707 + $script = $stackPath . '/openoffice/program/python.bat';
708 708 }
709 709 else
710 710 {
... ...
plugins/ktstandard/PDFGeneratorAction.php
... ... @@ -58,25 +58,23 @@ class PDFGeneratorAction extends KTDocumentAction {
58 58 'odp', 'otp', 'sxi', 'sti', 'ppt', 'pot', 'sxd', 'odg',
59 59 'otg', 'std', 'asc');
60 60  
  61 + function getName() {
  62 + return 'PDF Generator';
  63 + }
  64 +
61 65 function getDisplayName() {
62   - // We need to handle Windows differently - as usual ;)
63   - if (substr( PHP_OS, 0, 3) == 'WIN') {
64   - $cmdpath = KT_DIR . "/../openoffice/openoffice/program/python.bat";
65   - $cmdpath = str_replace( '/','\\',$cmdpath);
66   - } else {
67   - $cmdpath = "../openoffice/program/python";
68   - }
  66 + $cmdpath = KTUtil::findCommand('externalBinary/python');
69 67 // Check if openoffice and python are available
70   - if(file_exists($cmdpath)) {
  68 + if($cmdpath != false && file_exists($cmdpath) && !empty($cmdpath)) {
71 69 $sDocType = $this->getMimeExtension();
72   - // make sure that the selected document id of an acceptable extension
  70 + // make sure that the selected document is of an acceptable extension
73 71 foreach($this->aAcceptedMimeTypes as $acceptType){
74 72 if($acceptType == $sDocType){
75 73 return _kt('Generate PDF') . "&nbsp;<a href=\"" . KTUtil::ktLink( 'action.php', 'ktstandard.pdf.generate', array( "fDocumentId" => $this->oDocument->getId(), "action" => "pdfdownload") ) . "\" <img src='resources/mimetypes/pdf.png' alt='PDF' border=0/></a>";
76 74 }
77 75 }
78 76 }
79   - return 'PDF Generator';
  77 + return '';
80 78 }
81 79  
82 80 function form_main() {
... ... @@ -174,6 +172,14 @@ class PDFGeneratorAction extends KTDocumentAction {
174 172 $oDocument = $this->oDocument;
175 173 $oStorage =& KTStorageManagerUtil::getSingleton();
176 174 $oConfig =& KTConfig::getSingleton();
  175 + $cmdpath = KTUtil::findCommand('externalBinary/python');
  176 + // Check if openoffice and python are available
  177 + if($cmdpath == false || !file_exists($cmdpath) || empty($cmdpath)) {
  178 + // Set the error messsage and redirect to view document
  179 + $this->addErrorMessage(_kt('An error occurred generating the PDF - please contact the system administrator. Python binary not found.'));
  180 + redirect(generateControllerLink('viewDocument',sprintf('fDocumentId=%d',$oDocument->getId())));
  181 + exit(0);
  182 + }
177 183  
178 184 //get the actual path to the document on the server
179 185 $sPath = sprintf("%s/%s", $oConfig->get('urls/documentRoot'), $oStorage->getPath($oDocument));
... ... @@ -186,7 +192,7 @@ class PDFGeneratorAction extends KTDocumentAction {
186 192 // We need to handle Windows differently - as usual ;)
187 193 if (substr( PHP_OS, 0, 3) == 'WIN') {
188 194  
189   - $cmd = "\"" . KT_DIR . "/../openoffice/openoffice/program/python.bat\" \"". KT_DIR . "/bin/openoffice/pdfgen.py\" \"" . $sPath . "\" \"" . $sTempFilename . "\"";
  195 + $cmd = "\"" . $cmdpath . "\" \"". KT_DIR . "/bin/openoffice/pdfgen.py\" \"" . $sPath . "\" \"" . $sTempFilename . "\"";
190 196 $cmd = str_replace( '/','\\',$cmd);
191 197  
192 198 // TODO: Check for more errors here
... ... @@ -202,7 +208,7 @@ class PDFGeneratorAction extends KTDocumentAction {
202 208 // TODO: Check for more errors here
203 209 // SECURTIY: Ensure $sPath and $sTempFilename are safe or they could be used to excecute arbitrary commands!
204 210 // Excecute the python script.
205   - $cmd = '../openoffice/program/python bin/openoffice/pdfgen.py ' . escapeshellcmd($sPath) . ' ' . escapeshellcmd($sTempFilename);
  211 + $cmd = $cmdpath . ' ' . KT_DIR . '/bin/openoffice/pdfgen.py ' . escapeshellcmd($sPath) . ' ' . escapeshellcmd($sTempFilename);
206 212 $res = shell_exec($cmd." 2>&1");
207 213 //print($res);
208 214 //print($cmd);
... ... @@ -245,15 +251,15 @@ class PDFGeneratorAction extends KTDocumentAction {
245 251  
246 252 } else {
247 253 // Set the error messsage and redirect to view document
248   - $this->addErrorMessage(_kt('An error occurred generating the PDF - please contact the system administrator.<br>' . $res));
249   - redirect(generateControllerLink('viewDocument',sprintf(_kt('fDocumentId=%d'),$oDocument->getId())));
  254 + $this->addErrorMessage(_kt('An error occurred generating the PDF - please contact the system administrator. ' . $res));
  255 + redirect(generateControllerLink('viewDocument',sprintf('fDocumentId=%d',$oDocument->getId())));
250 256 exit(0);
251 257 }
252 258  
253 259 } else {
254 260 // Set the error messsage and redirect to view document
255   - $this->addErrorMessage(_kt('An error occurred generating the PDF - please contact the system administrator.<br>The path to the document did not exist.'));
256   - redirect(generateControllerLink('viewDocument',sprintf(_kt('fDocumentId=%d'),$oDocument->getId())));
  261 + $this->addErrorMessage(_kt('An error occurred generating the PDF - please contact the system administrator. The path to the document did not exist.'));
  262 + redirect(generateControllerLink('viewDocument',sprintf('fDocumentId=%d',$oDocument->getId())));
257 263 exit(0);
258 264 }
259 265  
... ...