X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/1c7128c2cb08271aa456951f6d6b4ce930df5cb5..refs/pull/5259/head:/app/Entities/Tools/PdfGenerator.php diff --git a/app/Entities/Tools/PdfGenerator.php b/app/Entities/Tools/PdfGenerator.php index 4f23ad334..79cd1b02f 100644 --- a/app/Entities/Tools/PdfGenerator.php +++ b/app/Entities/Tools/PdfGenerator.php @@ -5,6 +5,7 @@ namespace BookStack\Entities\Tools; use BookStack\Exceptions\PdfExportException; use Knp\Snappy\Pdf as SnappyPdf; use Dompdf\Dompdf; +use Symfony\Component\Process\Exception\ProcessTimedOutException; use Symfony\Component\Process\Process; class PdfGenerator @@ -76,7 +77,7 @@ class PdfGenerator $replacementsByPlaceholder = [ '{input_html_path}' => $inputHtml, - '{output_html_path}' => $outputPdf, + '{output_pdf_path}' => $outputPdf, ]; foreach ($replacementsByPlaceholder as $placeholder => $replacement) { @@ -85,9 +86,15 @@ class PdfGenerator file_put_contents($inputHtml, $html); + $timeout = intval(config('exports.pdf_command_timeout')); $process = Process::fromShellCommandline($command); - $process->setTimeout(15); - $process->run(); + $process->setTimeout($timeout); + + try { + $process->run(); + } catch (ProcessTimedOutException $e) { + throw new PdfExportException("PDF Export via command failed due to timeout at {$timeout} second(s)"); + } if (!$process->isSuccessful()) { throw new PdfExportException("PDF Export via command failed with exit code {$process->getExitCode()}, stdout: {$process->getOutput()}, stderr: {$process->getErrorOutput()}");