Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ncjoes authored Jul 3, 2023
2 parents 50bebcd + 0fc1081 commit 9f88fd8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require" : {
"php" : ">=5.4.4"
"php" : "^7.3|^8.0"
},
"require-dev" : {
"phpunit/phpunit": "7.*",
Expand Down
12 changes: 9 additions & 3 deletions src/OfficeConverter/OfficeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class OfficeConverter
private $prefixExecWithExportHome;
/** @var string */
private $filter = '';
private $logPath;

/**
* OfficeConverter constructor.
Expand All @@ -27,10 +28,10 @@ class OfficeConverter
* @param string $bin
* @param bool $prefixExecWithExportHome
*/
public function __construct($filename, $tempPath = null, $bin = 'libreoffice', $prefixExecWithExportHome = true)
public function __construct($filename, $tempPath = null, $bin = 'libreoffice', $prefixExecWithExportHome = true, $logPath = null)
{
if ($this->open($filename)) {
$this->setup($tempPath, $bin, $prefixExecWithExportHome);
$this->setup($tempPath, $bin, $prefixExecWithExportHome, $logPath);
}
}

Expand Down Expand Up @@ -86,7 +87,7 @@ protected function open($filename)
*
* @throws OfficeConverterException
*/
protected function setup($tempPath, $bin, $prefixExecWithExportHome)
protected function setup($tempPath, $bin, $prefixExecWithExportHome, $logPath)
{
//basename
$this->basename = pathinfo($this->file, PATHINFO_BASENAME);
Expand Down Expand Up @@ -116,6 +117,9 @@ protected function setup($tempPath, $bin, $prefixExecWithExportHome)

//use prefix export home or not
$this->prefixExecWithExportHome = $prefixExecWithExportHome;

// log path
$this->logPath = realpath($logPath);
}

/**
Expand All @@ -128,6 +132,7 @@ protected function makeCommand($outputDirectory, $outputExtension)
{
$oriFile = escapeshellarg($this->file);
$outputDirectory = escapeshellarg($outputDirectory);
$logCmd = $this->logPath ? ">> {$this->logPath}" : "";

return "{$this->bin} --headless --convert-to {$outputExtension}{$this->filter} {$oriFile} --outdir {$outputDirectory}";
}
Expand Down Expand Up @@ -226,6 +231,7 @@ private function getAllowedConverter($extension = null)
'Jfif' => ['pdf'],
'rtf' => ['docx', 'txt', 'pdf'],
'txt' => ['pdf', 'odt', 'doc', 'docx', 'html'],
'csv' => ['pdf'],
];

if (null !== $extension) {
Expand Down

0 comments on commit 9f88fd8

Please sign in to comment.