From bfe31b701eb5986c684bd0a9c5acfcb9091da279 Mon Sep 17 00:00:00 2001 From: megan_w Date: Thu, 17 Jan 2008 13:21:12 +0000 Subject: [PATCH] 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. --- lib/util/ktutil.inc | 43 +++++++++++++++++++++++++++++++++++++++++++ plugins/ktstandard/contents/BaseIndexer.php | 46 ++++++++++++++++++++++++++-------------------- plugins/ktstandard/contents/WordIndexer.php | 52 +++++++++++++++++++++++++++------------------------- 3 files changed, 96 insertions(+), 45 deletions(-) diff --git a/lib/util/ktutil.inc b/lib/util/ktutil.inc index a2dfecd..8bfa9d5 100644 --- a/lib/util/ktutil.inc +++ b/lib/util/ktutil.inc @@ -303,6 +303,49 @@ class KTUtil { } // }}} + + // {{{ winexec + /** + * Execute a command on a windows platform. + */ + function winexec($aCmd, $aOptions = null) { + if (is_array($aCmd)) { + $sCmd = KTUtil::safeShellString($aCmd); + } else { + $sCmd = $aCmd; + } + $sAppend = KTUtil::arrayGet($aOptions, 'append'); + if ($sAppend) { + $sCmd .= " >> " . escapeshellarg($sAppend); + } + + $sCmd = str_replace( '/','\\',$sCmd); + + // Set wait to true if the execute must wait for the script to complete before continuing + $wait = true; + if(isset($aOptions['exec_wait']) && ($aOptions['exec_wait'] == 'false')){ + $wait = false; + } + + // Iterate through the various execute functions till one works. + $WshShell = new COM("WScript.Shell"); + $res = $WshShell->Run($sCmd, 0, $wait); + + if($res){ + return $res; + } + + $sCmd = "start /b \"kt\" " . $sCmd; + $fp = popen($sCmd, 'r'); + fclose($fp); + + if($wait){ + sleep(1); + } + return 1; + } + // }}} + // {{{ copyDirectory function copyDirectory($sSrc, $sDst, $bMove = false) { if (file_exists($sDst)) { diff --git a/plugins/ktstandard/contents/BaseIndexer.php b/plugins/ktstandard/contents/BaseIndexer.php index 13a97f7..04eb62d 100644 --- a/plugins/ktstandard/contents/BaseIndexer.php +++ b/plugins/ktstandard/contents/BaseIndexer.php @@ -5,37 +5,37 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ * */ -class KTBaseIndexerTrigger { +class KTBaseIndexerTrigger { /** * Which MIME types that this indexer acts upon. */ @@ -76,8 +76,8 @@ class KTBaseIndexerTrigger { * If it is false, the temporary file will be sent as the last * parameter. */ - var $use_pipes = true; - + var $use_pipes = true; + /* return a diagnostic string _if_ there is something wrong. NULL otherwise. */ function getDiagnostic() { return null; @@ -103,9 +103,10 @@ class KTBaseIndexerTrigger { } $oKTConfig =& KTConfig::getSingleton(); - $sBasedir = $oKTConfig->get("urls/tmpDirectory"); - + $sBasedir = $oKTConfig->get("urls/tmpDirectory"); + $myfilename = tempnam($sBasedir, 'kt.' . $tempstub); + if (OS_WINDOWS) { $intermediate = tempnam($sBasedir, 'kt.' . $tempstub); if (!@copy($sFile, $intermediate)) { @@ -114,9 +115,9 @@ class KTBaseIndexerTrigger { } else { $intermediate = $sFile; } - + $contents = $this->extract_contents($intermediate, $myfilename); - + @unlink($myfilename); if (OS_WINDOWS) { @unlink($intermediate); } if (empty($contents)) { @@ -127,14 +128,14 @@ class KTBaseIndexerTrigger { 'document_text' => $contents, ); $sTable = KTUtil::getTableName('document_text'); - + // clean up the document query "stuff". // FIXME this suggests that we should move the _old_ document_searchable_text across to the old-document's id if its a checkin. DBUtil::runQuery(array('DELETE FROM ' . $sTable . ' WHERE document_id = ?', array($this->oDocument->getId()))); DBUtil::autoInsert($sTable, $aInsertValues, array('noid' => true)); } - + // handles certain, _very_ simple reader types. function extract_contents($sFilename, $sTempFilename) { $sCommand = KTUtil::findCommand($this->commandconfig, $this->command); @@ -145,7 +146,7 @@ class KTBaseIndexerTrigger { $cmdline = array($sCommand); $cmdline = kt_array_merge($cmdline, $this->args); $cmdline[] = $sFilename; - + $aOptions = array(); $aOptions['exec_wait'] = 'true'; if ($this->use_pipes) { @@ -153,7 +154,12 @@ class KTBaseIndexerTrigger { } else { $cmdline[] = $sTempFilename; } - $aRet = KTUtil::pexec($cmdline, $aOptions); + + if(OS_WINDOWS){ + $aRet = KTUtil::winexec($cmdline, $aOptions); + }else{ + $aRet = KTUtil::pexec($cmdline, $aOptions); + } $this->aCommandOutput = $aRet['out']; $contents = file_get_contents($sTempFilename); diff --git a/plugins/ktstandard/contents/WordIndexer.php b/plugins/ktstandard/contents/WordIndexer.php index 0d7662d..d288b2a 100644 --- a/plugins/ktstandard/contents/WordIndexer.php +++ b/plugins/ktstandard/contents/WordIndexer.php @@ -5,32 +5,32 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ * */ @@ -45,62 +45,64 @@ class KTWordIndexerTrigger extends KTBaseIndexerTrigger { var $commandconfig = 'indexer/catdoc'; // could be any application. var $args = array("-w", "-d", "UTF-8"); var $use_pipes = true; - + function extract_contents($sFilename, $sTempFilename) { - if (OS_WINDOWS) { + if (OS_WINDOWS) { $this->command = 'c:\antiword\antiword.exe'; $this->commandconfig = 'indexer/antiword'; $this->args = array(); } putenv('LANG=en_US.UTF-8'); - + $sCommand = KTUtil::findCommand($this->commandconfig, $this->command); if (empty($sCommand)) { return false; } - - if (OS_WINDOWS) { + + if (OS_WINDOWS) { $sDir = dirname(dirname($sCommand)); - putenv('HOME=' . $sDir); + putenv('HOME=' . $sDir); + /* $cmdline = array($sCommand); $cmdline = kt_array_merge($cmdline, $this->args); $cmdline[] = $sFilename; - + $sCmd = KTUtil::safeShellString($cmdline); $sCmd .= " >> " . escapeshellarg($sTempFilename); - + $sCmd = str_replace( '/','\\',$sCmd); - + $sCmd = "start /b \"kt\" " . $sCmd; - + pclose(popen($sCmd, 'r')); - + $this->aCommandOutput = 1; $contents = file_get_contents($sTempFilename); return $contents; + */ } return parent::extract_contents($sFilename, $sTempFilename); } - + function findLocalCommand() { if (OS_WINDOWS) { $this->command = 'c:\antiword\antiword.exe'; $this->commandconfig = 'indexer/antiword'; $this->args = array(); - } + } $sCommand = KTUtil::findCommand($this->commandconfig, $this->command); return $sCommand; } - + function getDiagnostic() { $sCommand = $this->findLocalCommand(); - + // can't find the local command. if (empty($sCommand)) { return sprintf(_kt('Unable to find required command for indexing. Please ensure that %s is installed and in the %s Path. For more information on indexers and helper applications, please visit the %s site.'), $this->command, APP_NAME, $this->support_url, APP_NAME); } - + return null; } } -- libgit2 0.21.4