Skip to content

Commit c9b99bb

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 3cb6097 commit c9b99bb

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

application/clicommands/DownloadCommand.php

Lines changed: 7 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,12 @@ 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+
/** @var PdfexportHook $exporter */
76+
$exporter = method_exists(PdfexportHook::class, 'first')
77+
? PdfexportHook::first()
78+
: Pdfexport::first();
79+
$content = $exporter->htmlToPdf($report->toPdf());
7480
break;
7581
case 'csv':
7682
$content = $report->toCsv();

application/controllers/ReportController.php

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

88
use Exception;
99
use Icinga\Application\Hook;
10+
use Icinga\Application\Hook\PdfexportHook;
11+
use Icinga\Application\Modules\Module;
1012
use Icinga\Module\Pdfexport\ProvidedHook\Pdfexport;
1113
use Icinga\Module\Reporting\Database;
1214
use Icinga\Module\Reporting\Model;
@@ -244,9 +246,16 @@ public function downloadAction(): void
244246

245247
switch ($type) {
246248
case 'pdf':
247-
/** @var Hook\PdfexportHook $exports */
248-
$exports = Pdfexport::first();
249-
$exports->streamPdfFromHtml($this->report->toPdf(), $name);
249+
// TODO: Remove this once the dependency on the Pdfexport module is removed
250+
if (! Module::exists('pdfexport')) {
251+
throw new Exception('The pdfexport module is not installed');
252+
}
253+
254+
/** @var PdfexportHook $exporter */
255+
$exporter = method_exists(PdfexportHook::class, 'first')
256+
? PdfexportHook::first()
257+
: Pdfexport::first();
258+
$exporter->streamPdfFromHtml($this->report->toPdf(), $name);
250259
exit;
251260
case 'csv':
252261
$response = $this->getResponse();

library/Reporting/Actions/SendMail.php

Lines changed: 7 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,12 @@ 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+
/** @var PdfexportHook $exporter */
53+
$exporter = method_exists(PdfexportHook::class, 'first')
54+
? PdfexportHook::first()
55+
: Pdfexport::first();
56+
$mail->attachPdf($exporter->htmlToPdf($report->toPdf()), $name);
5357

5458
break;
5559
case 'csv':

0 commit comments

Comments
 (0)