Commit 6899f2f02c1e569259e59c0fd29bc0f9d283c63e
1 parent
de993d01
Merged in from DEV trunk...
KTS-2811 "KnowledgeTree Indexer plugin not indexing in 3.4.5 on a windows machine" Fixed. Added a new util function for exec on windows, that iterates through the execute functions till one works. Committed by: Megan Watson Reviewed by: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/branches/3.4.6-Release-Branch@7927 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
99 additions
and
16 deletions
lib/util/ktutil.inc
| @@ -206,27 +206,56 @@ class KTUtil { | @@ -206,27 +206,56 @@ class KTUtil { | ||
| 206 | $aOutput = array(); | 206 | $aOutput = array(); |
| 207 | $iRet = ''; | 207 | $iRet = ''; |
| 208 | 208 | ||
| 209 | - if (OS_WINDOWS){ | ||
| 210 | - $wait = false; | ||
| 211 | - if(isset($aOptions['exec_wait']) && ($aOptions['exec_wait'] == 'true')){ | ||
| 212 | - $wait = true; | ||
| 213 | - } | ||
| 214 | - | ||
| 215 | - $WshShell = new COM("WScript.Shell"); | ||
| 216 | - $res = $WshShell->Run($sCmd, 0, $wait); | ||
| 217 | - | ||
| 218 | - $iRet = 0; | ||
| 219 | - $aOutput = array($res); | ||
| 220 | - }else{ | ||
| 221 | - exec($sCmd, $aOutput, $iRet); | ||
| 222 | - } | ||
| 223 | - | 209 | + exec($sCmd, $aOutput, $iRet); |
| 224 | $aRet['ret'] = $iRet; | 210 | $aRet['ret'] = $iRet; |
| 225 | $aRet['out'] = $aOutput; | 211 | $aRet['out'] = $aOutput; |
| 226 | return $aRet; | 212 | return $aRet; |
| 227 | } | 213 | } |
| 228 | // }}} | 214 | // }}} |
| 229 | 215 | ||
| 216 | + | ||
| 217 | + // {{{ winexec | ||
| 218 | + /** | ||
| 219 | + * Execute a command on a windows platform. | ||
| 220 | + */ | ||
| 221 | + function winexec($aCmd, $aOptions = null) { | ||
| 222 | + if (is_array($aCmd)) { | ||
| 223 | + $sCmd = KTUtil::safeShellString($aCmd); | ||
| 224 | + } else { | ||
| 225 | + $sCmd = $aCmd; | ||
| 226 | + } | ||
| 227 | + $sAppend = KTUtil::arrayGet($aOptions, 'append'); | ||
| 228 | + if ($sAppend) { | ||
| 229 | + $sCmd .= " >> " . escapeshellarg($sAppend); | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + $sCmd = str_replace( '/','\\',$sCmd); | ||
| 233 | + | ||
| 234 | + // Set wait to true if the execute must wait for the script to complete before continuing | ||
| 235 | + $wait = true; | ||
| 236 | + if(isset($aOptions['exec_wait']) && ($aOptions['exec_wait'] == 'false')){ | ||
| 237 | + $wait = false; | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + // Iterate through the various execute functions till one works. | ||
| 241 | + $WshShell = new COM("WScript.Shell"); | ||
| 242 | + $res = $WshShell->Run($sCmd, 0, $wait); | ||
| 243 | + | ||
| 244 | + if($res){ | ||
| 245 | + return $res; | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + $sCmd = "start /b \"kt\" " . $sCmd; | ||
| 249 | + $fp = popen($sCmd, 'r'); | ||
| 250 | + fclose($fp); | ||
| 251 | + | ||
| 252 | + if($wait){ | ||
| 253 | + sleep(1); | ||
| 254 | + } | ||
| 255 | + return 1; | ||
| 256 | + } | ||
| 257 | + // }}} | ||
| 258 | + | ||
| 230 | // {{{ copyDirectory | 259 | // {{{ copyDirectory |
| 231 | function copyDirectory($sSrc, $sDst, $bMove = false) { | 260 | function copyDirectory($sSrc, $sDst, $bMove = false) { |
| 232 | if (file_exists($sDst)) { | 261 | if (file_exists($sDst)) { |
| @@ -500,6 +529,12 @@ class KTUtil { | @@ -500,6 +529,12 @@ class KTUtil { | ||
| 500 | return $sCommand . ".exe"; | 529 | return $sCommand . ".exe"; |
| 501 | } | 530 | } |
| 502 | 531 | ||
| 532 | + $result = KTUtil::checkForStackCommand($sConfigVar); | ||
| 533 | + if (!empty($result)) | ||
| 534 | + { | ||
| 535 | + return $result; | ||
| 536 | + } | ||
| 537 | + | ||
| 503 | $sExecSearchPath = $oKTConfig->get("KnowledgeTree/execSearchPath"); | 538 | $sExecSearchPath = $oKTConfig->get("KnowledgeTree/execSearchPath"); |
| 504 | $sExecSearchPath .= PATH_SEPARATOR . KT_DIR . "/../common/"; | 539 | $sExecSearchPath .= PATH_SEPARATOR . KT_DIR . "/../common/"; |
| 505 | $sExecSearchPath .= PATH_SEPARATOR . KT_DIR . "/../bin/xpdf/"; | 540 | $sExecSearchPath .= PATH_SEPARATOR . KT_DIR . "/../bin/xpdf/"; |
| @@ -521,6 +556,47 @@ class KTUtil { | @@ -521,6 +556,47 @@ class KTUtil { | ||
| 521 | } | 556 | } |
| 522 | // }}} | 557 | // }}} |
| 523 | 558 | ||
| 559 | + function checkForStackCommand($configCommand) | ||
| 560 | + { | ||
| 561 | + $config = KTConfig::getSingleton(); | ||
| 562 | + $stackPath = realpath(KT_DIR . '/..'); | ||
| 563 | + | ||
| 564 | + switch ($configCommand) | ||
| 565 | + { | ||
| 566 | + case 'externalBinary/php': | ||
| 567 | + if (OS_WINDOWS) | ||
| 568 | + { | ||
| 569 | + $script = $stackPath . '/php/php.exe'; | ||
| 570 | + } | ||
| 571 | + else | ||
| 572 | + { | ||
| 573 | + $script = $stackPath . '/php/bin/php'; | ||
| 574 | + } | ||
| 575 | + break; | ||
| 576 | + case 'externalBinary/python': | ||
| 577 | + if (OS_WINDOWS) | ||
| 578 | + { | ||
| 579 | + $script = $stackPath . '/openoffice/openoffice/program/python.bat'; | ||
| 580 | + } | ||
| 581 | + else | ||
| 582 | + { | ||
| 583 | + $script = $stackPath . '/openoffice/program/python'; | ||
| 584 | + } | ||
| 585 | + break; | ||
| 586 | + case 'externalBinary/java': | ||
| 587 | + $script = $stackPath . '/j2re/bin/java'; | ||
| 588 | + break; | ||
| 589 | + default: | ||
| 590 | + return null; | ||
| 591 | + } | ||
| 592 | + if (is_file($script)) | ||
| 593 | + { | ||
| 594 | + return $script; | ||
| 595 | + } | ||
| 596 | + return false; | ||
| 597 | + } | ||
| 598 | + | ||
| 599 | + | ||
| 524 | // now accepts strings OR arrays! | 600 | // now accepts strings OR arrays! |
| 525 | // {{{ addQueryString | 601 | // {{{ addQueryString |
| 526 | function addQueryString($url, $qs) { | 602 | function addQueryString($url, $qs) { |
plugins/ktstandard/contents/BaseIndexer.php
| @@ -147,7 +147,12 @@ class KTBaseIndexerTrigger { | @@ -147,7 +147,12 @@ class KTBaseIndexerTrigger { | ||
| 147 | } else { | 147 | } else { |
| 148 | $cmdline[] = $sTempFilename; | 148 | $cmdline[] = $sTempFilename; |
| 149 | } | 149 | } |
| 150 | - $aRet = KTUtil::pexec($cmdline, $aOptions); | 150 | + |
| 151 | + if(OS_WINDOWS){ | ||
| 152 | + $aRet = KTUtil::winexec($cmdline, $aOptions); | ||
| 153 | + }else{ | ||
| 154 | + $aRet = KTUtil::pexec($cmdline, $aOptions); | ||
| 155 | + } | ||
| 151 | $this->aCommandOutput = $aRet['out']; | 156 | $this->aCommandOutput = $aRet['out']; |
| 152 | $contents = file_get_contents($sTempFilename); | 157 | $contents = file_get_contents($sTempFilename); |
| 153 | 158 |
plugins/ktstandard/contents/WordIndexer.php
| @@ -57,6 +57,7 @@ class KTWordIndexerTrigger extends KTBaseIndexerTrigger { | @@ -57,6 +57,7 @@ class KTWordIndexerTrigger extends KTBaseIndexerTrigger { | ||
| 57 | $sDir = dirname(dirname($sCommand)); | 57 | $sDir = dirname(dirname($sCommand)); |
| 58 | putenv('HOME=' . $sDir); | 58 | putenv('HOME=' . $sDir); |
| 59 | 59 | ||
| 60 | + /* | ||
| 60 | $cmdline = array($sCommand); | 61 | $cmdline = array($sCommand); |
| 61 | $cmdline = kt_array_merge($cmdline, $this->args); | 62 | $cmdline = kt_array_merge($cmdline, $this->args); |
| 62 | $cmdline[] = $sFilename; | 63 | $cmdline[] = $sFilename; |
| @@ -73,6 +74,7 @@ class KTWordIndexerTrigger extends KTBaseIndexerTrigger { | @@ -73,6 +74,7 @@ class KTWordIndexerTrigger extends KTBaseIndexerTrigger { | ||
| 73 | $this->aCommandOutput = 1; | 74 | $this->aCommandOutput = 1; |
| 74 | $contents = file_get_contents($sTempFilename); | 75 | $contents = file_get_contents($sTempFilename); |
| 75 | return $contents; | 76 | return $contents; |
| 77 | + */ | ||
| 76 | } | 78 | } |
| 77 | return parent::extract_contents($sFilename, $sTempFilename); | 79 | return parent::extract_contents($sFilename, $sTempFilename); |
| 78 | } | 80 | } |