Commit 0cc768dd158cc08054cc025605abbdea4da4652e

Authored by Megan Watson
1 parent 362b659e

KTS-2811

"KnowledgeTree Indexer plugin not indexing in 3.4.5 on a windows machine"
Fixed. Replaced the exec function on the word indexer with popen.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen




git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7897 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/ktstandard/contents/BaseIndexer.php
... ... @@ -147,6 +147,7 @@ class KTBaseIndexerTrigger {
147 147 $cmdline[] = $sFilename;
148 148  
149 149 $aOptions = array();
  150 + $aOptions['exec_wait'] = 'true';
150 151 if ($this->use_pipes) {
151 152 $aOptions["append"] = $sTempFilename;
152 153 } else {
... ...
plugins/ktstandard/contents/OpenDocumentIndexer.php
... ... @@ -118,7 +118,10 @@ class KTOpenDocumentIndexerTrigger extends KTBaseIndexerTrigger {
118 118 if (empty($sUnzipCommand)) {
119 119 return;
120 120 }
121   - $this->sTmpPath = tempnam('/tmp', 'opendocumentextract');
  121 + $oKTConfig =& KTConfig::getSingleton();
  122 + $sBasedir = $oKTConfig->get("urls/tmpDirectory");
  123 +
  124 + $this->sTmpPath = tempnam($sBasedir, 'opendocumentextract');
122 125 if ($this->sTmpPath === false) {
123 126 return;
124 127 }
... ... @@ -131,14 +134,20 @@ class KTOpenDocumentIndexerTrigger extends KTBaseIndexerTrigger {
131 134 "-d", $this->sTmpPath,
132 135 $sFilename,
133 136 );
134   - KTUtil::pexec($sCmd);
  137 + KTUtil::pexec($sCmd, array('exec_wait' => 'true'));
135 138  
136 139 $sManifest = sprintf("%s/%s", $this->sTmpPath, "META-INF/manifest.xml");
  140 + if (OS_WINDOWS) {
  141 + $sManifest = str_replace( '/','\\',$sManifest);
  142 + }
137 143 if (!file_exists($sManifest)) {
138 144 $this->cleanup();
139 145 return;
140 146 }
141 147 $sContentFile = sprintf("%s/%s", $this->sTmpPath, "content.xml");
  148 + if (OS_WINDOWS) {
  149 + $sContentFile = str_replace( '/','\\',$sContentFile );
  150 + }
142 151 if (!file_exists($sContentFile)) {
143 152 $this->cleanup();
144 153 return;
... ... @@ -152,7 +161,8 @@ class KTOpenDocumentIndexerTrigger extends KTBaseIndexerTrigger {
152 161 }
153 162  
154 163 function cleanup() {
155   - KTUtil::deleteDirectory($this->sTmpPath);
  164 + return;
  165 + //KTUtil::deleteDirectory($this->sTmpPath);
156 166 }
157 167 }
158 168  
... ...
plugins/ktstandard/contents/WordIndexer.php
... ... @@ -51,12 +51,35 @@ class KTWordIndexerTrigger extends KTBaseIndexerTrigger {
51 51 $this->command = 'c:\antiword\antiword.exe';
52 52 $this->commandconfig = 'indexer/antiword';
53 53 $this->args = array();
  54 + }
  55 + putenv('LANG=en_US.UTF-8');
  56 +
  57 + $sCommand = KTUtil::findCommand($this->commandconfig, $this->command);
  58 + if (empty($sCommand)) {
  59 + return false;
  60 + }
  61 +
  62 + if (OS_WINDOWS) {
  63 + $sDir = dirname(dirname($sCommand));
  64 + putenv('HOME=' . $sDir);
54 65  
55   - $sCommand = KTUtil::findCommand($this->commandconfig, $this->command);
56   - $sDir = dirname(dirname($sCommand));
57   - putenv('HOME=' . $sDir);
  66 + $cmdline = array($sCommand);
  67 + $cmdline = kt_array_merge($cmdline, $this->args);
  68 + $cmdline[] = $sFilename;
  69 +
  70 + $sCmd = KTUtil::safeShellString($cmdline);
  71 + $sCmd .= " >> " . escapeshellarg($sTempFilename);
  72 +
  73 + $sCmd = str_replace( '/','\\',$sCmd);
  74 +
  75 + $sCmd = "start /b \"kt\" " . $sCmd;
  76 +
  77 + pclose(popen($sCmd, 'r'));
  78 +
  79 + $this->aCommandOutput = 1;
  80 + $contents = file_get_contents($sTempFilename);
  81 + return $contents;
58 82 }
59   - putenv('LANG=en_US.UTF-8');
60 83 return parent::extract_contents($sFilename, $sTempFilename);
61 84 }
62 85  
... ...