Repo for the search and displace ingest module that takes odf, docx and pdf and transforms it into .md to be used with search and displace operations
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
namespace App\Ingest;
use Symfony\Component\Process\Process;
class Office { protected $id; protected $directory;
public function __construct() { $this->id = uniqid(); $this->directory = 'soffice-dir-' . $this->id;
(new Process(['export HOME=' . env('USER_HOME_PATH')]))->run(); }
public function run($convertTo, $filePath, $directoryPath) { $this->makeTemporaryDirectory();
$success = $this->runConversion($convertTo, $filePath, $directoryPath);
// @TODO Does not work at the moment.
// $this->removeTemporaryDirectory();
return $success; }
protected function runConversion($convertTo, $filePath, $directoryPath) { $process = new Process([ 'soffice', '--accept="pipe,name=soffice-pipe-' . $this->id . ';urp;StarOffice.ServiceMananger"', '-env:UserInstallation=file:///tmp/' . $this->directory, '--headless', '--convert-to', $convertTo, $filePath, '--outdir', $directoryPath ]);
$process->setTimeout(20);
$process->run();
return $process->isSuccessful(); }
protected function makeTemporaryDirectory() { (new Process(['mkdir /tmp/' . $this->directory]))->run(); }
protected function removeTemporaryDirectory() { (new Process(['rm -rf /tmp/' . $this->directory]))->run(); } }
|