Skip to content

Commit 0e31bdb

Browse files
committed
Check if the first method exists on the Hook abstract class
This is a temporary solution until we break support with older pdfexport module versions.
1 parent e3becd6 commit 0e31bdb

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

application/clicommands/DownloadCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace Icinga\Module\Reporting\Clicommands;
77

8+
use Icinga\Application\Hook\PdfexportHook;
89
use Icinga\Exception\NotFoundError;
910
use Icinga\Module\Pdfexport\ProvidedHook\Pdfexport;
1011
use Icinga\Module\Reporting\Cli\Command;
@@ -70,7 +71,11 @@ public function defaultAction()
7071
$format = strtolower($format);
7172
switch ($format) {
7273
case 'pdf':
73-
$content = Pdfexport::first()->htmlToPdf($report->toPdf());
74+
// TODO: Remove this once the dependency on the Pdfexport module is removed
75+
$exporter = method_exists(PdfexportHook::class, 'first')
76+
? PdfexportHook::first()
77+
: Pdfexport::first();
78+
$content = $exporter->htmlToPdf($report->toPdf());
7479
break;
7580
case 'csv':
7681
$content = $report->toCsv();

application/controllers/ReportController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Exception;
99
use Icinga\Application\Hook;
10+
use Icinga\Application\Hook\PdfexportHook;
1011
use Icinga\Module\Pdfexport\ProvidedHook\Pdfexport;
1112
use Icinga\Module\Reporting\Database;
1213
use Icinga\Module\Reporting\Model;
@@ -244,9 +245,11 @@ public function downloadAction(): void
244245

245246
switch ($type) {
246247
case 'pdf':
247-
/** @var Hook\PdfexportHook $exports */
248-
$exports = Pdfexport::first();
249-
$exports->streamPdfFromHtml($this->report->toPdf(), $name);
248+
// TODO: Remove this once the dependency on the Pdfexport module is removed
249+
$exporter = method_exists(PdfexportHook::class, 'first')
250+
? PdfexportHook::first()
251+
: Pdfexport::first();
252+
$exporter->streamPdfFromHtml($this->report->toPdf(), $name);
250253
exit;
251254
case 'csv':
252255
$response = $this->getResponse();

library/Reporting/Actions/SendMail.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Icinga\Module\Reporting\Actions;
77

88
use Icinga\Application\Config;
9-
use Icinga\Application\Logger;
9+
use Icinga\Application\Hook\PdfexportHook;
1010
use Icinga\Module\Pdfexport\ProvidedHook\Pdfexport;
1111
use Icinga\Module\Reporting\Hook\ActionHook;
1212
use Icinga\Module\Reporting\Mail;
@@ -15,7 +15,6 @@
1515
use ipl\Stdlib\Str;
1616
use ipl\Validator\CallbackValidator;
1717
use ipl\Validator\EmailAddressValidator;
18-
use Throwable;
1918

2019
class SendMail extends ActionHook
2120
{
@@ -49,7 +48,11 @@ public function execute(Report $report, array $config)
4948

5049
switch ($config['type']) {
5150
case 'pdf':
52-
$mail->attachPdf(Pdfexport::first()->htmlToPdf($report->toPdf()), $name);
51+
// TODO: Remove this once the dependency on the Pdfexport module is removed
52+
$exporter = method_exists(PdfexportHook::class, 'first')
53+
? PdfexportHook::first()
54+
: Pdfexport::first();
55+
$mail->attachPdf($exporter->htmlToPdf($report->toPdf()), $name);
5356

5457
break;
5558
case 'csv':

0 commit comments

Comments
 (0)