From a8993eba6d0ee429e746c97e626b0f08d2bc201f Mon Sep 17 00:00:00 2001 From: raviks789 <33730024+raviks789@users.noreply.github.com> Date: Thu, 22 Sep 2022 16:50:45 +0200 Subject: [PATCH] WIP --- library/Icingadb/Hook/CommentOutputHook.php | 49 +++++++++++++++++++ .../Icingadb/Widget/Detail/CommentDetail.php | 3 +- .../Icingadb/Widget/Detail/DowntimeDetail.php | 3 +- .../Icingadb/Widget/Detail/EventDetail.php | 8 +-- .../Widget/ItemList/BaseCommentListItem.php | 3 +- .../Widget/ItemList/BaseDowntimeListItem.php | 3 +- .../Widget/ItemList/BaseHistoryListItem.php | 9 ++-- 7 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 library/Icingadb/Hook/CommentOutputHook.php diff --git a/library/Icingadb/Hook/CommentOutputHook.php b/library/Icingadb/Hook/CommentOutputHook.php new file mode 100644 index 000000000..6153d5cba --- /dev/null +++ b/library/Icingadb/Hook/CommentOutputHook.php @@ -0,0 +1,49 @@ +transformComment($output); + } catch (Exception $e) { + Logger::error("Unable to process comment: %s\n%s", $e, $e->getTraceAsString()); + } + } + + return $output; + } +} diff --git a/library/Icingadb/Widget/Detail/CommentDetail.php b/library/Icingadb/Widget/Detail/CommentDetail.php index 39b80609d..71673b153 100644 --- a/library/Icingadb/Widget/Detail/CommentDetail.php +++ b/library/Icingadb/Widget/Detail/CommentDetail.php @@ -7,6 +7,7 @@ use Icinga\Date\DateFormatter; use Icinga\Module\Icingadb\Common\Auth; use Icinga\Module\Icingadb\Common\Links; +use Icinga\Module\Icingadb\Hook\CommentOutputHook; use Icinga\Module\Icingadb\Model\Comment; use Icinga\Module\Icingadb\Widget\MarkdownText; use Icinga\Module\Icingadb\Forms\Command\Object\DeleteCommentForm; @@ -35,7 +36,7 @@ protected function createComment(): array { return [ Html::tag('h2', t('Comment')), - new MarkdownText($this->comment->text) + new MarkdownText(CommentOutputHook::processComment($this->comment->text)) ]; } diff --git a/library/Icingadb/Widget/Detail/DowntimeDetail.php b/library/Icingadb/Widget/Detail/DowntimeDetail.php index 4ca447a89..e6487b741 100644 --- a/library/Icingadb/Widget/Detail/DowntimeDetail.php +++ b/library/Icingadb/Widget/Detail/DowntimeDetail.php @@ -10,6 +10,7 @@ use Icinga\Module\Icingadb\Common\Database; use Icinga\Module\Icingadb\Common\HostLink; use Icinga\Module\Icingadb\Common\Links; +use Icinga\Module\Icingadb\Hook\CommentOutputHook; use Icinga\Module\Icingadb\Widget\EmptyState; use Icinga\Module\Icingadb\Widget\MarkdownText; use Icinga\Module\Icingadb\Common\ServiceLink; @@ -75,7 +76,7 @@ protected function assemble() Html::sprintf( t('%s commented: %s', ' ..: '), $this->downtime->author, - new MarkdownText($this->downtime->comment) + new MarkdownText(CommentOutputHook::processComment($this->downtime->comment)) ) ])); diff --git a/library/Icingadb/Widget/Detail/EventDetail.php b/library/Icingadb/Widget/Detail/EventDetail.php index 23ee3d4c1..5acfa6547 100644 --- a/library/Icingadb/Widget/Detail/EventDetail.php +++ b/library/Icingadb/Widget/Detail/EventDetail.php @@ -7,11 +7,13 @@ use DateTime; use DateTimeZone; use Icinga\Date\DateFormatter; +use Icinga\File\Ini\Dom\Comment; use Icinga\Module\Icingadb\Common\Auth; use Icinga\Module\Icingadb\Common\Database; use Icinga\Module\Icingadb\Common\HostLink; use Icinga\Module\Icingadb\Common\HostStates; use Icinga\Module\Icingadb\Common\Links; +use Icinga\Module\Icingadb\Hook\CommentOutputHook; use Icinga\Module\Icingadb\Hook\ExtensionHook\ObjectDetailExtensionHook; use Icinga\Module\Icingadb\Widget\MarkdownText; use Icinga\Module\Icingadb\Common\ServiceLink; @@ -253,7 +255,7 @@ protected function assembleDowntimeEvent(DowntimeHistory $downtime) { $commentInfo = [ new HtmlElement('h2', null, Text::create(t('Comment'))), - new MarkdownText($downtime->comment) + new MarkdownText(CommentOutputHook::processComment($downtime->comment)) ]; $eventInfo = [new HtmlElement('h2', null, Text::create(t('Event Info')))]; @@ -352,7 +354,7 @@ protected function assembleCommentEvent(CommentHistory $comment) { $commentInfo = [ new HtmlElement('h2', null, Text::create(t('Comment'))), - new MarkdownText($comment->comment) + new MarkdownText(CommentOutputHook::processComment($comment->comment)) ]; $eventInfo = [new HtmlElement('h2', null, Text::create(t('Event Info')))]; @@ -464,7 +466,7 @@ protected function assembleAcknowledgeEvent(AcknowledgementHistory $acknowledgem if ($acknowledgement->comment) { $commentInfo = [ new HtmlElement('h2', null, Text::create(t('Comment'))), - new MarkdownText($acknowledgement->comment) + new MarkdownText(CommentOutputHook::processComment($acknowledgement->comment)) ]; } elseif (! isset($acknowledgement->author)) { $commentInfo[] = new EmptyState(t('This acknowledgement was set before Icinga DB history recording')); diff --git a/library/Icingadb/Widget/ItemList/BaseCommentListItem.php b/library/Icingadb/Widget/ItemList/BaseCommentListItem.php index 1a3135439..46b150b43 100644 --- a/library/Icingadb/Widget/ItemList/BaseCommentListItem.php +++ b/library/Icingadb/Widget/ItemList/BaseCommentListItem.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Icingadb\Widget\ItemList; +use Icinga\Module\Icingadb\Hook\CommentOutputHook; use ipl\Html\Html; use Icinga\Module\Icingadb\Common\HostLink; use Icinga\Module\Icingadb\Common\Icons; @@ -40,7 +41,7 @@ abstract class BaseCommentListItem extends BaseListItem protected function assembleCaption(BaseHtmlElement $caption) { - $markdownLine = new MarkdownLine($this->item->text); + $markdownLine = new MarkdownLine(CommentOutputHook::processComment($this->item->text)); $caption->getAttributes()->add($markdownLine->getAttributes()); $caption->addFrom($markdownLine); } diff --git a/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php b/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php index a9d9dd345..7b3007f4b 100644 --- a/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php +++ b/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php @@ -12,6 +12,7 @@ use Icinga\Module\Icingadb\Common\NoSubjectLink; use Icinga\Module\Icingadb\Common\ObjectLinkDisabled; use Icinga\Module\Icingadb\Common\ServiceLink; +use Icinga\Module\Icingadb\Hook\CommentOutputHook; use Icinga\Module\Icingadb\Model\Downtime; use Icinga\Module\Icingadb\Widget\MarkdownLine; use ipl\Html\BaseHtmlElement; @@ -106,7 +107,7 @@ protected function createProgress(): BaseHtmlElement protected function assembleCaption(BaseHtmlElement $caption) { - $markdownLine = new MarkdownLine($this->item->comment); + $markdownLine = new MarkdownLine(CommentOutputHook::processComment($this->item->comment)); $caption->getAttributes()->add($markdownLine->getAttributes()); $caption->addHtml( new HtmlElement( diff --git a/library/Icingadb/Widget/ItemList/BaseHistoryListItem.php b/library/Icingadb/Widget/ItemList/BaseHistoryListItem.php index 561977d37..49ab6deb7 100644 --- a/library/Icingadb/Widget/ItemList/BaseHistoryListItem.php +++ b/library/Icingadb/Widget/ItemList/BaseHistoryListItem.php @@ -9,6 +9,7 @@ use Icinga\Module\Icingadb\Common\HostStates; use Icinga\Module\Icingadb\Common\Icons; use Icinga\Module\Icingadb\Common\Links; +use Icinga\Module\Icingadb\Hook\CommentOutputHook; use Icinga\Module\Icingadb\Widget\EmptyState; use Icinga\Module\Icingadb\Widget\MarkdownLine; use Icinga\Module\Icingadb\Common\NoSubjectLink; @@ -54,7 +55,7 @@ protected function assembleCaption(BaseHtmlElement $caption) switch ($this->item->event_type) { case 'comment_add': case 'comment_remove': - $markdownLine = new MarkdownLine($this->item->comment->comment); + $markdownLine = new MarkdownLine(CommentOutputHook::processComment($this->item->comment->comment)); $caption->getAttributes()->add($markdownLine->getAttributes()); $caption->add([ new Icon(Icons::USER), @@ -65,7 +66,7 @@ protected function assembleCaption(BaseHtmlElement $caption) break; case 'downtime_end': case 'downtime_start': - $markdownLine = new MarkdownLine($this->item->downtime->comment); + $markdownLine = new MarkdownLine(CommentOutputHook::processComment($this->item->downtime->comment)); $caption->getAttributes()->add($markdownLine->getAttributes()); $caption->add([ new Icon(Icons::USER), @@ -106,7 +107,9 @@ protected function assembleCaption(BaseHtmlElement $caption) t('This acknowledgement was set before Icinga DB history recording') )); } else { - $markdownLine = new MarkdownLine($this->item->acknowledgement->comment); + $markdownLine = new MarkdownLine( + CommentOutputHook::processComment($this->item->acknowledgement->comment) + ); $caption->getAttributes()->add($markdownLine->getAttributes()); $caption->add([ new Icon(Icons::USER),