Commit 5695178570eee6ece2eb40ddd1708a4bf801f021

Authored by kevin_fourie
1 parent 7fc73fd3

Merged in from DEV trunk...

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/STABLE/branches/3.4.6-Release-Branch@7901 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/ktstandard/contents/BaseIndexer.php
... ... @@ -141,6 +141,7 @@ class KTBaseIndexerTrigger {
141 141 $cmdline[] = $sFilename;
142 142  
143 143 $aOptions = array();
  144 + $aOptions['exec_wait'] = 'true';
144 145 if ($this->use_pipes) {
145 146 $aOptions["append"] = $sTempFilename;
146 147 } else {
... ...
plugins/ktstandard/contents/OpenDocumentIndexer.php
... ... @@ -112,7 +112,10 @@ class KTOpenDocumentIndexerTrigger extends KTBaseIndexerTrigger {
112 112 if (empty($sUnzipCommand)) {
113 113 return;
114 114 }
115   - $this->sTmpPath = tempnam('/tmp', 'opendocumentextract');
  115 + $oKTConfig =& KTConfig::getSingleton();
  116 + $sBasedir = $oKTConfig->get("urls/tmpDirectory");
  117 +
  118 + $this->sTmpPath = tempnam($sBasedir, 'opendocumentextract');
116 119 if ($this->sTmpPath === false) {
117 120 return;
118 121 }
... ... @@ -125,14 +128,20 @@ class KTOpenDocumentIndexerTrigger extends KTBaseIndexerTrigger {
125 128 "-d", $this->sTmpPath,
126 129 $sFilename,
127 130 );
128   - KTUtil::pexec($sCmd);
  131 + KTUtil::pexec($sCmd, array('exec_wait' => 'true'));
129 132  
130 133 $sManifest = sprintf("%s/%s", $this->sTmpPath, "META-INF/manifest.xml");
  134 + if (OS_WINDOWS) {
  135 + $sManifest = str_replace( '/','\\',$sManifest);
  136 + }
131 137 if (!file_exists($sManifest)) {
132 138 $this->cleanup();
133 139 return;
134 140 }
135 141 $sContentFile = sprintf("%s/%s", $this->sTmpPath, "content.xml");
  142 + if (OS_WINDOWS) {
  143 + $sContentFile = str_replace( '/','\\',$sContentFile );
  144 + }
136 145 if (!file_exists($sContentFile)) {
137 146 $this->cleanup();
138 147 return;
... ... @@ -146,7 +155,8 @@ class KTOpenDocumentIndexerTrigger extends KTBaseIndexerTrigger {
146 155 }
147 156  
148 157 function cleanup() {
149   - KTUtil::deleteDirectory($this->sTmpPath);
  158 + return;
  159 + //KTUtil::deleteDirectory($this->sTmpPath);
150 160 }
151 161 }
152 162  
... ...
plugins/ktstandard/contents/WordIndexer.php
... ... @@ -45,12 +45,35 @@ class KTWordIndexerTrigger extends KTBaseIndexerTrigger {
45 45 $this->command = 'c:\antiword\antiword.exe';
46 46 $this->commandconfig = 'indexer/antiword';
47 47 $this->args = array();
  48 + }
  49 + putenv('LANG=en_US.UTF-8');
48 50  
49 51 $sCommand = KTUtil::findCommand($this->commandconfig, $this->command);
50   - $sDir = dirname(dirname($sCommand));
51   - putenv('HOME=' . $sDir);
  52 + if (empty($sCommand)) {
  53 + return false;
  54 + }
  55 +
  56 + if (OS_WINDOWS) {
  57 + $sDir = dirname(dirname($sCommand));
  58 + putenv('HOME=' . $sDir);
  59 +
  60 + $cmdline = array($sCommand);
  61 + $cmdline = kt_array_merge($cmdline, $this->args);
  62 + $cmdline[] = $sFilename;
  63 +
  64 + $sCmd = KTUtil::safeShellString($cmdline);
  65 + $sCmd .= " >> " . escapeshellarg($sTempFilename);
  66 +
  67 + $sCmd = str_replace( '/','\\',$sCmd);
  68 +
  69 + $sCmd = "start /b \"kt\" " . $sCmd;
  70 +
  71 + pclose(popen($sCmd, 'r'));
  72 +
  73 + $this->aCommandOutput = 1;
  74 + $contents = file_get_contents($sTempFilename);
  75 + return $contents;
52 76 }
53   - putenv('LANG=en_US.UTF-8');
54 77 return parent::extract_contents($sFilename, $sTempFilename);
55 78 }
56 79  
... ...