Skip to content

Commit 59dede0

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 59dede0

4 files changed

Lines changed: 44 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: 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':

module.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
title: Reporting
2+
version: 1.1.0
3+
description: Reporting module for Icinga Web 2
4+
5+
depends:
6+
icingaweb: "^2.10.0"
7+
libraries:
8+
icinga-php-library:
9+
- ">=1.0.0"
10+
- "^0.16.0-dev"
11+
icinga-php-thirdparty:
12+
- ">=1.0.0"
13+
- "^0.16.0-dev"
14+
modules:
15+
pdfexport: ">=0.13.0"
16+
any-of:
17+
icingadb: ">=1.0.0"
18+
monitoring: "^2.10.0"
19+

0 commit comments

Comments
 (0)