Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion application/clicommands/DownloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,7 +71,11 @@
$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());

Check failure on line 78 in application/clicommands/DownloadCommand.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Cannot call method htmlToPdf() on mixed.

Check failure on line 78 in application/clicommands/DownloadCommand.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Cannot call method htmlToPdf() on mixed.

Check failure on line 78 in application/clicommands/DownloadCommand.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Cannot call method htmlToPdf() on mixed.

Check failure on line 78 in application/clicommands/DownloadCommand.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Cannot call method htmlToPdf() on mixed.
break;
case 'csv':
$content = $report->toCsv();
Expand Down
9 changes: 6 additions & 3 deletions application/controllers/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
21 changes: 7 additions & 14 deletions library/Reporting/Actions/SendMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +15,6 @@
use ipl\Stdlib\Str;
use ipl\Validator\CallbackValidator;
use ipl\Validator\EmailAddressValidator;
use Throwable;

class SendMail extends ActionHook
{
Expand Down Expand Up @@ -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);

Expand Down
Loading