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,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 | // {{{ copyDirectory | 349 | // {{{ copyDirectory |
| 307 | function copyDirectory($sSrc, $sDst, $bMove = false) { | 350 | function copyDirectory($sSrc, $sDst, $bMove = false) { |
| 308 | if (file_exists($sDst)) { | 351 | if (file_exists($sDst)) { |
plugins/ktstandard/contents/BaseIndexer.php
| @@ -5,37 +5,37 @@ | @@ -5,37 +5,37 @@ | ||
| 5 | * KnowledgeTree Open Source Edition | 5 | * KnowledgeTree Open Source Edition |
| 6 | * Document Management Made Simple | 6 | * Document Management Made Simple |
| 7 | * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited | 7 | * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited |
| 8 | - * | 8 | + * |
| 9 | * This program is free software; you can redistribute it and/or modify it under | 9 | * This program is free software; you can redistribute it and/or modify it under |
| 10 | * the terms of the GNU General Public License version 3 as published by the | 10 | * the terms of the GNU General Public License version 3 as published by the |
| 11 | * Free Software Foundation. | 11 | * Free Software Foundation. |
| 12 | - * | 12 | + * |
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT | 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 16 | * details. | 16 | * details. |
| 17 | - * | 17 | + * |
| 18 | * You should have received a copy of the GNU General Public License | 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | - * | 20 | + * |
| 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, | 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. | 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 23 | - * | 23 | + * |
| 24 | * The interactive user interfaces in modified source and object code versions | 24 | * The interactive user interfaces in modified source and object code versions |
| 25 | * of this program must display Appropriate Legal Notices, as required under | 25 | * of this program must display Appropriate Legal Notices, as required under |
| 26 | * Section 5 of the GNU General Public License version 3. | 26 | * Section 5 of the GNU General Public License version 3. |
| 27 | - * | 27 | + * |
| 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, | 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 29 | * these Appropriate Legal Notices must retain the display of the "Powered by | 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 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | 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 | * Contributor( s): ______________________________________ | 34 | * Contributor( s): ______________________________________ |
| 35 | * | 35 | * |
| 36 | */ | 36 | */ |
| 37 | 37 | ||
| 38 | -class KTBaseIndexerTrigger { | 38 | +class KTBaseIndexerTrigger { |
| 39 | /** | 39 | /** |
| 40 | * Which MIME types that this indexer acts upon. | 40 | * Which MIME types that this indexer acts upon. |
| 41 | */ | 41 | */ |
| @@ -76,8 +76,8 @@ class KTBaseIndexerTrigger { | @@ -76,8 +76,8 @@ class KTBaseIndexerTrigger { | ||
| 76 | * If it is false, the temporary file will be sent as the last | 76 | * If it is false, the temporary file will be sent as the last |
| 77 | * parameter. | 77 | * parameter. |
| 78 | */ | 78 | */ |
| 79 | - var $use_pipes = true; | ||
| 80 | - | 79 | + var $use_pipes = true; |
| 80 | + | ||
| 81 | /* return a diagnostic string _if_ there is something wrong. NULL otherwise. */ | 81 | /* return a diagnostic string _if_ there is something wrong. NULL otherwise. */ |
| 82 | function getDiagnostic() { | 82 | function getDiagnostic() { |
| 83 | return null; | 83 | return null; |
| @@ -103,9 +103,10 @@ class KTBaseIndexerTrigger { | @@ -103,9 +103,10 @@ class KTBaseIndexerTrigger { | ||
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | $oKTConfig =& KTConfig::getSingleton(); | 105 | $oKTConfig =& KTConfig::getSingleton(); |
| 106 | - $sBasedir = $oKTConfig->get("urls/tmpDirectory"); | ||
| 107 | - | 106 | + $sBasedir = $oKTConfig->get("urls/tmpDirectory"); |
| 107 | + | ||
| 108 | $myfilename = tempnam($sBasedir, 'kt.' . $tempstub); | 108 | $myfilename = tempnam($sBasedir, 'kt.' . $tempstub); |
| 109 | + | ||
| 109 | if (OS_WINDOWS) { | 110 | if (OS_WINDOWS) { |
| 110 | $intermediate = tempnam($sBasedir, 'kt.' . $tempstub); | 111 | $intermediate = tempnam($sBasedir, 'kt.' . $tempstub); |
| 111 | if (!@copy($sFile, $intermediate)) { | 112 | if (!@copy($sFile, $intermediate)) { |
| @@ -114,9 +115,9 @@ class KTBaseIndexerTrigger { | @@ -114,9 +115,9 @@ class KTBaseIndexerTrigger { | ||
| 114 | } else { | 115 | } else { |
| 115 | $intermediate = $sFile; | 116 | $intermediate = $sFile; |
| 116 | } | 117 | } |
| 117 | - | 118 | + |
| 118 | $contents = $this->extract_contents($intermediate, $myfilename); | 119 | $contents = $this->extract_contents($intermediate, $myfilename); |
| 119 | - | 120 | + |
| 120 | @unlink($myfilename); | 121 | @unlink($myfilename); |
| 121 | if (OS_WINDOWS) { @unlink($intermediate); } | 122 | if (OS_WINDOWS) { @unlink($intermediate); } |
| 122 | if (empty($contents)) { | 123 | if (empty($contents)) { |
| @@ -127,14 +128,14 @@ class KTBaseIndexerTrigger { | @@ -127,14 +128,14 @@ class KTBaseIndexerTrigger { | ||
| 127 | 'document_text' => $contents, | 128 | 'document_text' => $contents, |
| 128 | ); | 129 | ); |
| 129 | $sTable = KTUtil::getTableName('document_text'); | 130 | $sTable = KTUtil::getTableName('document_text'); |
| 130 | - | 131 | + |
| 131 | // clean up the document query "stuff". | 132 | // clean up the document query "stuff". |
| 132 | // FIXME this suggests that we should move the _old_ document_searchable_text across to the old-document's id if its a checkin. | 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 | DBUtil::runQuery(array('DELETE FROM ' . $sTable . ' WHERE document_id = ?', array($this->oDocument->getId()))); | 134 | DBUtil::runQuery(array('DELETE FROM ' . $sTable . ' WHERE document_id = ?', array($this->oDocument->getId()))); |
| 134 | DBUtil::autoInsert($sTable, $aInsertValues, array('noid' => true)); | 135 | DBUtil::autoInsert($sTable, $aInsertValues, array('noid' => true)); |
| 135 | 136 | ||
| 136 | } | 137 | } |
| 137 | - | 138 | + |
| 138 | // handles certain, _very_ simple reader types. | 139 | // handles certain, _very_ simple reader types. |
| 139 | function extract_contents($sFilename, $sTempFilename) { | 140 | function extract_contents($sFilename, $sTempFilename) { |
| 140 | $sCommand = KTUtil::findCommand($this->commandconfig, $this->command); | 141 | $sCommand = KTUtil::findCommand($this->commandconfig, $this->command); |
| @@ -145,7 +146,7 @@ class KTBaseIndexerTrigger { | @@ -145,7 +146,7 @@ class KTBaseIndexerTrigger { | ||
| 145 | $cmdline = array($sCommand); | 146 | $cmdline = array($sCommand); |
| 146 | $cmdline = kt_array_merge($cmdline, $this->args); | 147 | $cmdline = kt_array_merge($cmdline, $this->args); |
| 147 | $cmdline[] = $sFilename; | 148 | $cmdline[] = $sFilename; |
| 148 | - | 149 | + |
| 149 | $aOptions = array(); | 150 | $aOptions = array(); |
| 150 | $aOptions['exec_wait'] = 'true'; | 151 | $aOptions['exec_wait'] = 'true'; |
| 151 | if ($this->use_pipes) { | 152 | if ($this->use_pipes) { |
| @@ -153,7 +154,12 @@ class KTBaseIndexerTrigger { | @@ -153,7 +154,12 @@ class KTBaseIndexerTrigger { | ||
| 153 | } else { | 154 | } else { |
| 154 | $cmdline[] = $sTempFilename; | 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 | $this->aCommandOutput = $aRet['out']; | 163 | $this->aCommandOutput = $aRet['out']; |
| 158 | $contents = file_get_contents($sTempFilename); | 164 | $contents = file_get_contents($sTempFilename); |
| 159 | 165 |
plugins/ktstandard/contents/WordIndexer.php
| @@ -5,32 +5,32 @@ | @@ -5,32 +5,32 @@ | ||
| 5 | * KnowledgeTree Open Source Edition | 5 | * KnowledgeTree Open Source Edition |
| 6 | * Document Management Made Simple | 6 | * Document Management Made Simple |
| 7 | * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited | 7 | * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited |
| 8 | - * | 8 | + * |
| 9 | * This program is free software; you can redistribute it and/or modify it under | 9 | * This program is free software; you can redistribute it and/or modify it under |
| 10 | * the terms of the GNU General Public License version 3 as published by the | 10 | * the terms of the GNU General Public License version 3 as published by the |
| 11 | * Free Software Foundation. | 11 | * Free Software Foundation. |
| 12 | - * | 12 | + * |
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT | 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 16 | * details. | 16 | * details. |
| 17 | - * | 17 | + * |
| 18 | * You should have received a copy of the GNU General Public License | 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | - * | 20 | + * |
| 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, | 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. | 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 23 | - * | 23 | + * |
| 24 | * The interactive user interfaces in modified source and object code versions | 24 | * The interactive user interfaces in modified source and object code versions |
| 25 | * of this program must display Appropriate Legal Notices, as required under | 25 | * of this program must display Appropriate Legal Notices, as required under |
| 26 | * Section 5 of the GNU General Public License version 3. | 26 | * Section 5 of the GNU General Public License version 3. |
| 27 | - * | 27 | + * |
| 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, | 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 29 | * these Appropriate Legal Notices must retain the display of the "Powered by | 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 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | 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 | * Contributor( s): ______________________________________ | 34 | * Contributor( s): ______________________________________ |
| 35 | * | 35 | * |
| 36 | */ | 36 | */ |
| @@ -45,62 +45,64 @@ class KTWordIndexerTrigger extends KTBaseIndexerTrigger { | @@ -45,62 +45,64 @@ class KTWordIndexerTrigger extends KTBaseIndexerTrigger { | ||
| 45 | var $commandconfig = 'indexer/catdoc'; // could be any application. | 45 | var $commandconfig = 'indexer/catdoc'; // could be any application. |
| 46 | var $args = array("-w", "-d", "UTF-8"); | 46 | var $args = array("-w", "-d", "UTF-8"); |
| 47 | var $use_pipes = true; | 47 | var $use_pipes = true; |
| 48 | - | 48 | + |
| 49 | function extract_contents($sFilename, $sTempFilename) { | 49 | function extract_contents($sFilename, $sTempFilename) { |
| 50 | - if (OS_WINDOWS) { | 50 | + if (OS_WINDOWS) { |
| 51 | $this->command = 'c:\antiword\antiword.exe'; | 51 | $this->command = 'c:\antiword\antiword.exe'; |
| 52 | $this->commandconfig = 'indexer/antiword'; | 52 | $this->commandconfig = 'indexer/antiword'; |
| 53 | $this->args = array(); | 53 | $this->args = array(); |
| 54 | } | 54 | } |
| 55 | putenv('LANG=en_US.UTF-8'); | 55 | putenv('LANG=en_US.UTF-8'); |
| 56 | - | 56 | + |
| 57 | $sCommand = KTUtil::findCommand($this->commandconfig, $this->command); | 57 | $sCommand = KTUtil::findCommand($this->commandconfig, $this->command); |
| 58 | if (empty($sCommand)) { | 58 | if (empty($sCommand)) { |
| 59 | return false; | 59 | return false; |
| 60 | } | 60 | } |
| 61 | - | ||
| 62 | - if (OS_WINDOWS) { | 61 | + |
| 62 | + if (OS_WINDOWS) { | ||
| 63 | $sDir = dirname(dirname($sCommand)); | 63 | $sDir = dirname(dirname($sCommand)); |
| 64 | - putenv('HOME=' . $sDir); | 64 | + putenv('HOME=' . $sDir); |
| 65 | 65 | ||
| 66 | + /* | ||
| 66 | $cmdline = array($sCommand); | 67 | $cmdline = array($sCommand); |
| 67 | $cmdline = kt_array_merge($cmdline, $this->args); | 68 | $cmdline = kt_array_merge($cmdline, $this->args); |
| 68 | $cmdline[] = $sFilename; | 69 | $cmdline[] = $sFilename; |
| 69 | - | 70 | + |
| 70 | $sCmd = KTUtil::safeShellString($cmdline); | 71 | $sCmd = KTUtil::safeShellString($cmdline); |
| 71 | $sCmd .= " >> " . escapeshellarg($sTempFilename); | 72 | $sCmd .= " >> " . escapeshellarg($sTempFilename); |
| 72 | - | 73 | + |
| 73 | $sCmd = str_replace( '/','\\',$sCmd); | 74 | $sCmd = str_replace( '/','\\',$sCmd); |
| 74 | - | 75 | + |
| 75 | $sCmd = "start /b \"kt\" " . $sCmd; | 76 | $sCmd = "start /b \"kt\" " . $sCmd; |
| 76 | - | 77 | + |
| 77 | pclose(popen($sCmd, 'r')); | 78 | pclose(popen($sCmd, 'r')); |
| 78 | - | 79 | + |
| 79 | $this->aCommandOutput = 1; | 80 | $this->aCommandOutput = 1; |
| 80 | $contents = file_get_contents($sTempFilename); | 81 | $contents = file_get_contents($sTempFilename); |
| 81 | return $contents; | 82 | return $contents; |
| 83 | + */ | ||
| 82 | } | 84 | } |
| 83 | return parent::extract_contents($sFilename, $sTempFilename); | 85 | return parent::extract_contents($sFilename, $sTempFilename); |
| 84 | } | 86 | } |
| 85 | - | 87 | + |
| 86 | function findLocalCommand() { | 88 | function findLocalCommand() { |
| 87 | if (OS_WINDOWS) { | 89 | if (OS_WINDOWS) { |
| 88 | $this->command = 'c:\antiword\antiword.exe'; | 90 | $this->command = 'c:\antiword\antiword.exe'; |
| 89 | $this->commandconfig = 'indexer/antiword'; | 91 | $this->commandconfig = 'indexer/antiword'; |
| 90 | $this->args = array(); | 92 | $this->args = array(); |
| 91 | - } | 93 | + } |
| 92 | $sCommand = KTUtil::findCommand($this->commandconfig, $this->command); | 94 | $sCommand = KTUtil::findCommand($this->commandconfig, $this->command); |
| 93 | return $sCommand; | 95 | return $sCommand; |
| 94 | } | 96 | } |
| 95 | - | 97 | + |
| 96 | function getDiagnostic() { | 98 | function getDiagnostic() { |
| 97 | $sCommand = $this->findLocalCommand(); | 99 | $sCommand = $this->findLocalCommand(); |
| 98 | - | 100 | + |
| 99 | // can't find the local command. | 101 | // can't find the local command. |
| 100 | if (empty($sCommand)) { | 102 | if (empty($sCommand)) { |
| 101 | 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); | 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 | return null; | 106 | return null; |
| 105 | } | 107 | } |
| 106 | } | 108 | } |