Commit bfe31b701eb5986c684bd0a9c5acfcb9091da279
1 parent
e352c4d7
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/trunk@7926 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
96 additions
and
45 deletions
lib/util/ktutil.inc
| ... | ... | @@ -303,6 +303,49 @@ class KTUtil { |
| 303 | 303 | } |
| 304 | 304 | // }}} |
| 305 | 305 | |
| 306 | + | |
| 307 | + // {{{ winexec | |
| 308 | + /** | |
| 309 | + * Execute a command on a windows platform. | |
| 310 | + */ | |
| 311 | + function winexec($aCmd, $aOptions = null) { | |
| 312 | + if (is_array($aCmd)) { | |
| 313 | + $sCmd = KTUtil::safeShellString($aCmd); | |
| 314 | + } else { | |
| 315 | + $sCmd = $aCmd; | |
| 316 | + } | |
| 317 | + $sAppend = KTUtil::arrayGet($aOptions, 'append'); | |
| 318 | + if ($sAppend) { | |
| 319 | + $sCmd .= " >> " . escapeshellarg($sAppend); | |
| 320 | + } | |
| 321 | + | |
| 322 | + $sCmd = str_replace( '/','\\',$sCmd); | |
| 323 | + | |
| 324 | + // Set wait to true if the execute must wait for the script to complete before continuing | |
| 325 | + $wait = true; | |
| 326 | + if(isset($aOptions['exec_wait']) && ($aOptions['exec_wait'] == 'false')){ | |
| 327 | + $wait = false; | |
| 328 | + } | |
| 329 | + | |
| 330 | + // Iterate through the various execute functions till one works. | |
| 331 | + $WshShell = new COM("WScript.Shell"); | |
| 332 | + $res = $WshShell->Run($sCmd, 0, $wait); | |
| 333 | + | |
| 334 | + if($res){ | |
| 335 | + return $res; | |
| 336 | + } | |
| 337 | + | |
| 338 | + $sCmd = "start /b \"kt\" " . $sCmd; | |
| 339 | + $fp = popen($sCmd, 'r'); | |
| 340 | + fclose($fp); | |
| 341 | + | |
| 342 | + if($wait){ | |
| 343 | + sleep(1); | |
| 344 | + } | |
| 345 | + return 1; | |
| 346 | + } | |
| 347 | + // }}} | |
| 348 | + | |
| 306 | 349 | // {{{ copyDirectory |
| 307 | 350 | function copyDirectory($sSrc, $sDst, $bMove = false) { |
| 308 | 351 | if (file_exists($sDst)) { | ... | ... |
plugins/ktstandard/contents/BaseIndexer.php
| ... | ... | @@ -5,37 +5,37 @@ |
| 5 | 5 | * KnowledgeTree Open Source Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited |
| 8 | - * | |
| 8 | + * | |
| 9 | 9 | * This program is free software; you can redistribute it and/or modify it under |
| 10 | 10 | * the terms of the GNU General Public License version 3 as published by the |
| 11 | 11 | * Free Software Foundation. |
| 12 | - * | |
| 12 | + * | |
| 13 | 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 16 | 16 | * details. |
| 17 | - * | |
| 17 | + * | |
| 18 | 18 | * You should have received a copy of the GNU General Public License |
| 19 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | - * | |
| 20 | + * | |
| 21 | 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 22 | 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 23 | - * | |
| 23 | + * | |
| 24 | 24 | * The interactive user interfaces in modified source and object code versions |
| 25 | 25 | * of this program must display Appropriate Legal Notices, as required under |
| 26 | 26 | * Section 5 of the GNU General Public License version 3. |
| 27 | - * | |
| 27 | + * | |
| 28 | 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 29 | 29 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 30 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 30 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 31 | 31 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 32 | - * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | - * copyright notice. | |
| 32 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | + * copyright notice. | |
| 34 | 34 | * Contributor( s): ______________________________________ |
| 35 | 35 | * |
| 36 | 36 | */ |
| 37 | 37 | |
| 38 | -class KTBaseIndexerTrigger { | |
| 38 | +class KTBaseIndexerTrigger { | |
| 39 | 39 | /** |
| 40 | 40 | * Which MIME types that this indexer acts upon. |
| 41 | 41 | */ |
| ... | ... | @@ -76,8 +76,8 @@ class KTBaseIndexerTrigger { |
| 76 | 76 | * If it is false, the temporary file will be sent as the last |
| 77 | 77 | * parameter. |
| 78 | 78 | */ |
| 79 | - var $use_pipes = true; | |
| 80 | - | |
| 79 | + var $use_pipes = true; | |
| 80 | + | |
| 81 | 81 | /* return a diagnostic string _if_ there is something wrong. NULL otherwise. */ |
| 82 | 82 | function getDiagnostic() { |
| 83 | 83 | return null; |
| ... | ... | @@ -103,9 +103,10 @@ class KTBaseIndexerTrigger { |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | $oKTConfig =& KTConfig::getSingleton(); |
| 106 | - $sBasedir = $oKTConfig->get("urls/tmpDirectory"); | |
| 107 | - | |
| 106 | + $sBasedir = $oKTConfig->get("urls/tmpDirectory"); | |
| 107 | + | |
| 108 | 108 | $myfilename = tempnam($sBasedir, 'kt.' . $tempstub); |
| 109 | + | |
| 109 | 110 | if (OS_WINDOWS) { |
| 110 | 111 | $intermediate = tempnam($sBasedir, 'kt.' . $tempstub); |
| 111 | 112 | if (!@copy($sFile, $intermediate)) { |
| ... | ... | @@ -114,9 +115,9 @@ class KTBaseIndexerTrigger { |
| 114 | 115 | } else { |
| 115 | 116 | $intermediate = $sFile; |
| 116 | 117 | } |
| 117 | - | |
| 118 | + | |
| 118 | 119 | $contents = $this->extract_contents($intermediate, $myfilename); |
| 119 | - | |
| 120 | + | |
| 120 | 121 | @unlink($myfilename); |
| 121 | 122 | if (OS_WINDOWS) { @unlink($intermediate); } |
| 122 | 123 | if (empty($contents)) { |
| ... | ... | @@ -127,14 +128,14 @@ class KTBaseIndexerTrigger { |
| 127 | 128 | 'document_text' => $contents, |
| 128 | 129 | ); |
| 129 | 130 | $sTable = KTUtil::getTableName('document_text'); |
| 130 | - | |
| 131 | + | |
| 131 | 132 | // clean up the document query "stuff". |
| 132 | 133 | // FIXME this suggests that we should move the _old_ document_searchable_text across to the old-document's id if its a checkin. |
| 133 | 134 | DBUtil::runQuery(array('DELETE FROM ' . $sTable . ' WHERE document_id = ?', array($this->oDocument->getId()))); |
| 134 | 135 | DBUtil::autoInsert($sTable, $aInsertValues, array('noid' => true)); |
| 135 | 136 | |
| 136 | 137 | } |
| 137 | - | |
| 138 | + | |
| 138 | 139 | // handles certain, _very_ simple reader types. |
| 139 | 140 | function extract_contents($sFilename, $sTempFilename) { |
| 140 | 141 | $sCommand = KTUtil::findCommand($this->commandconfig, $this->command); |
| ... | ... | @@ -145,7 +146,7 @@ class KTBaseIndexerTrigger { |
| 145 | 146 | $cmdline = array($sCommand); |
| 146 | 147 | $cmdline = kt_array_merge($cmdline, $this->args); |
| 147 | 148 | $cmdline[] = $sFilename; |
| 148 | - | |
| 149 | + | |
| 149 | 150 | $aOptions = array(); |
| 150 | 151 | $aOptions['exec_wait'] = 'true'; |
| 151 | 152 | if ($this->use_pipes) { |
| ... | ... | @@ -153,7 +154,12 @@ class KTBaseIndexerTrigger { |
| 153 | 154 | } else { |
| 154 | 155 | $cmdline[] = $sTempFilename; |
| 155 | 156 | } |
| 156 | - $aRet = KTUtil::pexec($cmdline, $aOptions); | |
| 157 | + | |
| 158 | + if(OS_WINDOWS){ | |
| 159 | + $aRet = KTUtil::winexec($cmdline, $aOptions); | |
| 160 | + }else{ | |
| 161 | + $aRet = KTUtil::pexec($cmdline, $aOptions); | |
| 162 | + } | |
| 157 | 163 | $this->aCommandOutput = $aRet['out']; |
| 158 | 164 | $contents = file_get_contents($sTempFilename); |
| 159 | 165 | ... | ... |
plugins/ktstandard/contents/WordIndexer.php
| ... | ... | @@ -5,32 +5,32 @@ |
| 5 | 5 | * KnowledgeTree Open Source Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited |
| 8 | - * | |
| 8 | + * | |
| 9 | 9 | * This program is free software; you can redistribute it and/or modify it under |
| 10 | 10 | * the terms of the GNU General Public License version 3 as published by the |
| 11 | 11 | * Free Software Foundation. |
| 12 | - * | |
| 12 | + * | |
| 13 | 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 16 | 16 | * details. |
| 17 | - * | |
| 17 | + * | |
| 18 | 18 | * You should have received a copy of the GNU General Public License |
| 19 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | - * | |
| 20 | + * | |
| 21 | 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 22 | 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 23 | - * | |
| 23 | + * | |
| 24 | 24 | * The interactive user interfaces in modified source and object code versions |
| 25 | 25 | * of this program must display Appropriate Legal Notices, as required under |
| 26 | 26 | * Section 5 of the GNU General Public License version 3. |
| 27 | - * | |
| 27 | + * | |
| 28 | 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 29 | 29 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 30 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 30 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 31 | 31 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 32 | - * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | - * copyright notice. | |
| 32 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | + * copyright notice. | |
| 34 | 34 | * Contributor( s): ______________________________________ |
| 35 | 35 | * |
| 36 | 36 | */ |
| ... | ... | @@ -45,62 +45,64 @@ class KTWordIndexerTrigger extends KTBaseIndexerTrigger { |
| 45 | 45 | var $commandconfig = 'indexer/catdoc'; // could be any application. |
| 46 | 46 | var $args = array("-w", "-d", "UTF-8"); |
| 47 | 47 | var $use_pipes = true; |
| 48 | - | |
| 48 | + | |
| 49 | 49 | function extract_contents($sFilename, $sTempFilename) { |
| 50 | - if (OS_WINDOWS) { | |
| 50 | + if (OS_WINDOWS) { | |
| 51 | 51 | $this->command = 'c:\antiword\antiword.exe'; |
| 52 | 52 | $this->commandconfig = 'indexer/antiword'; |
| 53 | 53 | $this->args = array(); |
| 54 | 54 | } |
| 55 | 55 | putenv('LANG=en_US.UTF-8'); |
| 56 | - | |
| 56 | + | |
| 57 | 57 | $sCommand = KTUtil::findCommand($this->commandconfig, $this->command); |
| 58 | 58 | if (empty($sCommand)) { |
| 59 | 59 | return false; |
| 60 | 60 | } |
| 61 | - | |
| 62 | - if (OS_WINDOWS) { | |
| 61 | + | |
| 62 | + if (OS_WINDOWS) { | |
| 63 | 63 | $sDir = dirname(dirname($sCommand)); |
| 64 | - putenv('HOME=' . $sDir); | |
| 64 | + putenv('HOME=' . $sDir); | |
| 65 | 65 | |
| 66 | + /* | |
| 66 | 67 | $cmdline = array($sCommand); |
| 67 | 68 | $cmdline = kt_array_merge($cmdline, $this->args); |
| 68 | 69 | $cmdline[] = $sFilename; |
| 69 | - | |
| 70 | + | |
| 70 | 71 | $sCmd = KTUtil::safeShellString($cmdline); |
| 71 | 72 | $sCmd .= " >> " . escapeshellarg($sTempFilename); |
| 72 | - | |
| 73 | + | |
| 73 | 74 | $sCmd = str_replace( '/','\\',$sCmd); |
| 74 | - | |
| 75 | + | |
| 75 | 76 | $sCmd = "start /b \"kt\" " . $sCmd; |
| 76 | - | |
| 77 | + | |
| 77 | 78 | pclose(popen($sCmd, 'r')); |
| 78 | - | |
| 79 | + | |
| 79 | 80 | $this->aCommandOutput = 1; |
| 80 | 81 | $contents = file_get_contents($sTempFilename); |
| 81 | 82 | return $contents; |
| 83 | + */ | |
| 82 | 84 | } |
| 83 | 85 | return parent::extract_contents($sFilename, $sTempFilename); |
| 84 | 86 | } |
| 85 | - | |
| 87 | + | |
| 86 | 88 | function findLocalCommand() { |
| 87 | 89 | if (OS_WINDOWS) { |
| 88 | 90 | $this->command = 'c:\antiword\antiword.exe'; |
| 89 | 91 | $this->commandconfig = 'indexer/antiword'; |
| 90 | 92 | $this->args = array(); |
| 91 | - } | |
| 93 | + } | |
| 92 | 94 | $sCommand = KTUtil::findCommand($this->commandconfig, $this->command); |
| 93 | 95 | return $sCommand; |
| 94 | 96 | } |
| 95 | - | |
| 97 | + | |
| 96 | 98 | function getDiagnostic() { |
| 97 | 99 | $sCommand = $this->findLocalCommand(); |
| 98 | - | |
| 100 | + | |
| 99 | 101 | // can't find the local command. |
| 100 | 102 | if (empty($sCommand)) { |
| 101 | 103 | return sprintf(_kt('Unable to find required command for indexing. Please ensure that <strong>%s</strong> is installed and in the %s Path. For more information on indexers and helper applications, please <a href="%s">visit the %s site</a>.'), $this->command, APP_NAME, $this->support_url, APP_NAME); |
| 102 | 104 | } |
| 103 | - | |
| 105 | + | |
| 104 | 106 | return null; |
| 105 | 107 | } |
| 106 | 108 | } | ... | ... |