Skip to content

Commit

Permalink
Merge pull request #42 from neopheus/add-logs
Browse files Browse the repository at this point in the history
Add Logs
  • Loading branch information
ncjoes authored Jul 3, 2023
2 parents f5e0502 + 143eca2 commit 0fc1081
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/OfficeConverter/OfficeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class OfficeConverter
private $basename;
/** @var bool */
private $prefixExecWithExportHome;
/** @var string */
private $logPath;

/**
* OfficeConverter constructor.
Expand All @@ -25,10 +27,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 @@ -84,7 +86,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 @@ -114,6 +116,9 @@ protected function setup($tempPath, $bin, $prefixExecWithExportHome)

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

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

/**
Expand All @@ -126,8 +131,9 @@ protected function makeCommand($outputDirectory, $outputExtension)
{
$oriFile = escapeshellarg($this->file);
$outputDirectory = escapeshellarg($outputDirectory);
$logCmd = $this->logPath ? ">> {$this->logPath}" : "";

return "{$this->bin} --headless --convert-to {$outputExtension} {$oriFile} --outdir {$outputDirectory}";
return "{$this->bin} --headless --convert-to {$outputExtension} {$oriFile} --outdir {$outputDirectory} {$logCmd}";
}

/**
Expand Down

0 comments on commit 0fc1081

Please sign in to comment.