Browse Source

Analyze performance command fix. WIP Converting PDF to DOCX for apply SD on original document operation

dev
Orzu Ionut 3 years ago
parent
commit
9fbec23150
  1. 5
      app/Console/Commands/AnalyzePerformance.php
  2. 15
      app/Ingest/DataJsonConvertor.php
  3. 2
      app/Ingest/DocxConvertor.php
  4. 16
      app/Ingest/Office.php

5
app/Console/Commands/AnalyzePerformance.php

@ -58,10 +58,13 @@ class AnalyzePerformance extends Command
$redis->set('analyze_performance_remaining_files', count($allFiles));
foreach ($allFiles as $index => $file) {
$document = new UploadedFile($file, "File {$index}");
$handler = new DocumentHandler(
$index,
'md',
new UploadedFile($file, "File {$index}"),
$document->getMimeType(),
$document,
false
);

15
app/Ingest/DataJsonConvertor.php

@ -53,8 +53,14 @@ class DataJsonConvertor extends AbstractConvertor
{
$office = new Office();
$convertTo = 'docx';
if ($this->fileIsPDF($this->path)) {
$convertTo = 'docx:writer_pdf_Export';
}
$success = $office->run(
'docx',
$convertTo,
$this->storage->path($this->path),
$this->storage->path($this->directoryPath)
);
@ -73,4 +79,11 @@ class DataJsonConvertor extends AbstractConvertor
$this->type = 'docx';
}
protected function fileIsPDF($filePath)
{
$s = '.pdf';
return substr($filePath, - strlen($s)) === $s;
}
}

2
app/Ingest/DocxConvertor.php

@ -53,7 +53,7 @@ class DocxConvertor extends AbstractConvertor
*/
public function convertToPdfWithLibreOffice()
{
$this->convertToFormat('pdf');
$this->convertToFormat('pdf:writer_pdf_Export');
}
/**

16
app/Ingest/Office.php

@ -31,15 +31,8 @@ class Office
protected function runConversion($convertTo, $filePath, $directoryPath)
{
$pdfAdditionalOption = '';
if ($this->fileIsPDF($filePath)) {
$pdfAdditionalOption = "--infilter='writer_pdf_import'";
}
$process = new Process([
'soffice',
$pdfAdditionalOption,
'--accept="pipe,name=soffice-pipe-' . $this->id . ';urp;StarOffice.ServiceMananger"',
'-env:UserInstallation=file:///tmp/' . $this->directory,
'--headless',
@ -50,20 +43,13 @@ class Office
$directoryPath
]);
$process->setTimeout(10);
$process->setTimeout(20);
$process->run();
return $process->isSuccessful();
}
protected function fileIsPDF($filePath)
{
$s = '.pdf';
return substr($filePath, - strlen($s)) === $s;
}
protected function makeTemporaryDirectory()
{
(new Process(['mkdir /tmp/' . $this->directory]))->run();

Loading…
Cancel
Save