FIX Cleanup temporary file after extracting content in TikaServerTextExtractor and TikaTextExtractor

This commit is contained in:
Charlie Bergthaler 2019-06-20 17:21:05 +12:00 committed by Robbie Averill
parent 20079bd33f
commit a9270d73ad
2 changed files with 10 additions and 1 deletions

View File

@ -127,6 +127,11 @@ class TikaServerTextExtractor extends FileTextExtractor
public function getContent($file) public function getContent($file)
{ {
$tempFile = $file instanceof File ? $this->getPathFromFile($file) : $file; $tempFile = $file instanceof File ? $this->getPathFromFile($file) : $file;
return $this->getClient()->tika($tempFile); $content = $this->getClient()->tika($tempFile);
//Cleanup temp file
if ($tempFile instanceof File) {
unlink($tempFile);
}
return $content;
} }
} }

View File

@ -80,6 +80,10 @@ class TikaTextExtractor extends FileTextExtractor
$path = $file instanceof File ? $this->getPathFromFile($file) : $file; $path = $file instanceof File ? $this->getPathFromFile($file) : $file;
$command = sprintf('tika %s %s', $mode, escapeshellarg($path)); $command = sprintf('tika %s %s', $mode, escapeshellarg($path));
$code = $this->runShell($command, $output); $code = $this->runShell($command, $output);
//Cleanup temp file
if ($path instanceof File) {
unlink($path);
}
if ($code == 0) { if ($code == 0) {
return $output; return $output;