diff --git a/application/clicommands/DownloadCommand.php b/application/clicommands/DownloadCommand.php index dda234e3..f5297044 100644 --- a/application/clicommands/DownloadCommand.php +++ b/application/clicommands/DownloadCommand.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Reporting\Clicommands; +use Icinga\Application\Hook\PdfexportHook; use Icinga\Exception\NotFoundError; use Icinga\Module\Pdfexport\ProvidedHook\Pdfexport; use Icinga\Module\Reporting\Cli\Command; @@ -70,7 +71,11 @@ public function defaultAction() $format = strtolower($format); switch ($format) { case 'pdf': - $content = Pdfexport::first()->htmlToPdf($report->toPdf()); + // TODO: Remove this once the dependency on the Pdfexport module is removed + $exporter = method_exists(PdfexportHook::class, 'first') + ? PdfexportHook::first() + : Pdfexport::first(); + $content = $exporter->htmlToPdf($report->toPdf()); break; case 'csv': $content = $report->toCsv(); diff --git a/application/controllers/ReportController.php b/application/controllers/ReportController.php index ed843387..c05aef6c 100644 --- a/application/controllers/ReportController.php +++ b/application/controllers/ReportController.php @@ -7,6 +7,7 @@ use Exception; use Icinga\Application\Hook; +use Icinga\Application\Hook\PdfexportHook; use Icinga\Module\Pdfexport\ProvidedHook\Pdfexport; use Icinga\Module\Reporting\Database; use Icinga\Module\Reporting\Model; @@ -244,9 +245,11 @@ public function downloadAction(): void switch ($type) { case 'pdf': - /** @var Hook\PdfexportHook $exports */ - $exports = Pdfexport::first(); - $exports->streamPdfFromHtml($this->report->toPdf(), $name); + // TODO: Remove this once the dependency on the Pdfexport module is removed + $exporter = method_exists(PdfexportHook::class, 'first') + ? PdfexportHook::first() + : Pdfexport::first(); + $exporter->streamPdfFromHtml($this->report->toPdf(), $name); exit; case 'csv': $response = $this->getResponse(); diff --git a/library/Reporting/Actions/SendMail.php b/library/Reporting/Actions/SendMail.php index 73138a64..355d1303 100644 --- a/library/Reporting/Actions/SendMail.php +++ b/library/Reporting/Actions/SendMail.php @@ -6,7 +6,7 @@ namespace Icinga\Module\Reporting\Actions; use Icinga\Application\Config; -use Icinga\Application\Logger; +use Icinga\Application\Hook\PdfexportHook; use Icinga\Module\Pdfexport\ProvidedHook\Pdfexport; use Icinga\Module\Reporting\Hook\ActionHook; use Icinga\Module\Reporting\Mail; @@ -15,7 +15,6 @@ use ipl\Stdlib\Str; use ipl\Validator\CallbackValidator; use ipl\Validator\EmailAddressValidator; -use Throwable; class SendMail extends ActionHook { @@ -49,19 +48,13 @@ public function execute(Report $report, array $config) switch ($config['type']) { case 'pdf': - /** @var Pdfexport $exporter */ - $exporter = Pdfexport::first(); - $exporter->asyncHtmlToPdf($report->toPdf())->then( - function ($pdf) use ($mail, $name, $recipients) { - $mail->attachPdf($pdf, $name); - $mail->send(null, $recipients); - } - )->catch(function (Throwable $e) { - Logger::error($e); - Logger::debug($e->getTraceAsString()); - }); + // TODO: Remove this once the dependency on the Pdfexport module is removed + $exporter = method_exists(PdfexportHook::class, 'first') + ? PdfexportHook::first() + : Pdfexport::first(); + $mail->attachPdf($exporter->htmlToPdf($report->toPdf()), $name); - return; + break; case 'csv': $mail->attachCsv($report->toCsv(), $name);