Commit a26bf018ff795538af563dd73f17b87f6829b2cc
1 parent
d76d048f
Replaced unzip binary with peclzip to avoid permissions errors
Jira: KTS-4507 PT: 1697701 Committed by: Megan Watson
Showing
2 changed files
with
25 additions
and
1 deletions
search2/indexing/extractors/OpenOfficeTextExtractor.inc.php
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | +require_once(KT_DIR.'/thirdparty/peclzip/pclzip.lib.php'); | |
| 4 | + | |
| 3 | 5 | /** |
| 4 | 6 | * $Id:$ |
| 5 | 7 | * |
| ... | ... | @@ -41,11 +43,13 @@ class OpenOfficeTextExtractor extends ExternalDocumentExtractor |
| 41 | 43 | { |
| 42 | 44 | public function __construct() |
| 43 | 45 | { |
| 46 | + /* *** Replaced unzip binary with pclzip *** | |
| 44 | 47 | $config = KTConfig::getSingleton(); |
| 45 | 48 | |
| 46 | 49 | $this->unzip = KTUtil::findCommand("import/unzip", 'unzip'); |
| 47 | 50 | $this->unzip = str_replace('\\','/',$this->unzip); |
| 48 | 51 | $this->unzip_params = $config->get('extractorParameters/unzip', '"{source}" "{part}" -d "{target_dir}"'); |
| 52 | + */ | |
| 49 | 53 | parent::__construct(); |
| 50 | 54 | } |
| 51 | 55 | |
| ... | ... | @@ -94,6 +98,14 @@ class OpenOfficeTextExtractor extends ExternalDocumentExtractor |
| 94 | 98 | $this->sourcefile = str_replace('\\','/',$this->sourcefile); |
| 95 | 99 | $this->openxml_dir = str_replace('\\','/',$this->openxml_dir); |
| 96 | 100 | |
| 101 | + $archive = new PclZip($this->sourcefile); | |
| 102 | + | |
| 103 | + if ($archive->extract(PCLZIP_OPT_PATH, $this->openxml_dir) == 0){ | |
| 104 | + $this->output = _kt('Failed to extract content'); | |
| 105 | + return false; | |
| 106 | + } | |
| 107 | + | |
| 108 | + /* *** Original code using the unzip binary *** | |
| 97 | 109 | $cmd = '"' . $this->unzip . '"' . ' ' . str_replace( |
| 98 | 110 | array('{source}','{part}', '{target_dir}'), |
| 99 | 111 | array($this->sourcefile, 'content.xml',$this->openxml_dir), $this->unzip_params); |
| ... | ... | @@ -105,6 +117,7 @@ class OpenOfficeTextExtractor extends ExternalDocumentExtractor |
| 105 | 117 | $this->output = _kt('Failed to execute command: ') . $cmd; |
| 106 | 118 | return false; |
| 107 | 119 | } |
| 120 | + *** End unzip code *** */ | |
| 108 | 121 | |
| 109 | 122 | $filename = $this->openxml_dir . '/content.xml'; |
| 110 | 123 | if (!file_exists($filename)) |
| ... | ... | @@ -134,4 +147,4 @@ class OpenOfficeTextExtractor extends ExternalDocumentExtractor |
| 134 | 147 | |
| 135 | 148 | } |
| 136 | 149 | |
| 137 | 150 | -?> |
| 151 | +?> | |
| 138 | 152 | \ No newline at end of file | ... | ... |
search2/indexing/extractors/OpenXmlTextExtractor.inc.php
| ... | ... | @@ -43,9 +43,11 @@ class OpenXmlTextExtractor extends ExternalDocumentExtractor |
| 43 | 43 | { |
| 44 | 44 | $config = KTConfig::getSingleton(); |
| 45 | 45 | |
| 46 | + /* ** Using peclzip instead of the unzip binary ** | |
| 46 | 47 | $this->unzip = KTUtil::findCommand("import/unzip", 'unzip'); |
| 47 | 48 | $this->unzip = str_replace('\\','/',$this->unzip); |
| 48 | 49 | $this->unzip_params = $config->get('extractorParameters/unzip', '"{source}" "{part}" -d "{target_dir}"'); |
| 50 | + */ | |
| 49 | 51 | parent::__construct(); |
| 50 | 52 | } |
| 51 | 53 | |
| ... | ... | @@ -158,6 +160,14 @@ class OpenXmlTextExtractor extends ExternalDocumentExtractor |
| 158 | 160 | $this->sourcefile = str_replace('\\','/',$this->sourcefile); |
| 159 | 161 | $this->openxml_dir = str_replace('\\','/',$this->openxml_dir); |
| 160 | 162 | |
| 163 | + $archive = new PclZip($this->sourcefile); | |
| 164 | + | |
| 165 | + if ($archive->extract(PCLZIP_OPT_PATH, $this->openxml_dir) == 0){ | |
| 166 | + $this->output = _kt('Failed to extract content'); | |
| 167 | + return false; | |
| 168 | + } | |
| 169 | + | |
| 170 | + /* *** Original code using the unzip binary *** | |
| 161 | 171 | $cmd = '"' . $this->unzip . '"' . ' ' . str_replace( |
| 162 | 172 | array('{source}','{part}', '{target_dir}'), |
| 163 | 173 | array($this->sourcefile, '*Content_Types*.xml',$this->openxml_dir), $this->unzip_params); |
| ... | ... | @@ -169,6 +179,7 @@ class OpenXmlTextExtractor extends ExternalDocumentExtractor |
| 169 | 179 | $this->output = _kt('Failed to execute command: ') . $cmd; |
| 170 | 180 | return false; |
| 171 | 181 | } |
| 182 | + *** End unzip code *** */ | |
| 172 | 183 | |
| 173 | 184 | $filename = $this->openxml_dir . '/[Content_Types].xml'; |
| 174 | 185 | if (!file_exists($filename)) | ... | ... |