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.
62 lines
1.5 KiB
62 lines
1.5 KiB
<?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(10);
|
|
|
|
$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();
|
|
}
|
|
}
|