Skip to content

Commit 1760080

Browse files
authored
Merge pull request #136 from Icinga/fix/get-property-parentNode-on-null-129
SystemReport: Don't call property `parentNode()` and `setAttribute()` on null
2 parents bb59df7 + d5f1079 commit 1760080

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

library/Reporting/Reports/SystemReport.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Icinga\Module\Reporting\Reports;
66

7+
use Icinga\Application\Icinga;
78
use Icinga\Module\Reporting\Hook\ReportHook;
89
use Icinga\Module\Reporting\Timerange;
910
use ipl\Html\HtmlString;
@@ -21,20 +22,26 @@ public function getHtml(Timerange $timerange, array $config = null)
2122
phpinfo();
2223
$html = ob_get_clean();
2324

24-
$doc = new \DOMDocument();
25-
@$doc->loadHTML($html);
25+
if (! Icinga::app()->isCli()) {
26+
$doc = new \DOMDocument();
27+
@$doc->loadHTML($html);
2628

27-
$style = $doc->getElementsByTagName('style')->item(0);
28-
$style->parentNode->removeChild($style);
29+
$style = $doc->getElementsByTagName('style')->item(0);
30+
$style->parentNode->removeChild($style);
2931

30-
$title = $doc->getElementsByTagName('title')->item(0);
31-
$title->parentNode->removeChild($title);
32+
$title = $doc->getElementsByTagName('title')->item(0);
33+
$title->parentNode->removeChild($title);
3234

33-
$meta = $doc->getElementsByTagName('meta')->item(0);
34-
$meta->parentNode->removeChild($meta);
35+
$meta = $doc->getElementsByTagName('meta')->item(0);
36+
$meta->parentNode->removeChild($meta);
3537

36-
$doc->getElementsByTagName('div')->item(0)->setAttribute('class', 'system-report');
38+
$doc->getElementsByTagName('div')->item(0)->setAttribute('class', 'system-report');
3739

38-
return new HtmlString($doc->saveHTML());
40+
$html = $doc->saveHTML();
41+
} else {
42+
$html = nl2br($html);
43+
}
44+
45+
return new HtmlString($html);
3946
}
4047
}

0 commit comments

Comments
 (0)