diff --git a/application/controllers/IncidentController.php b/application/controllers/IncidentController.php index d529691e1..b6695aa2d 100644 --- a/application/controllers/IncidentController.php +++ b/application/controllers/IncidentController.php @@ -27,6 +27,7 @@ public function indexAction(): void $query = Incident::on(Database::get()) ->with(['object', 'object.source']) + ->withColumns('object.id_tags') ->filter(Filter::equal('incident.id', $id)); $this->applyRestrictions($query); diff --git a/application/controllers/IncidentsController.php b/application/controllers/IncidentsController.php index 93a42a4bf..082a4f6a5 100644 --- a/application/controllers/IncidentsController.php +++ b/application/controllers/IncidentsController.php @@ -29,7 +29,8 @@ public function indexAction(): void $this->addTitleTab(t('Incidents')); $incidents = Incident::on(Database::get()) - ->with('object'); + ->with('object') + ->withColumns('object.id_tags'); $limitControl = $this->createLimitControl(); $sortControl = $this->createSortControl( diff --git a/library/Notifications/Model/Incident.php b/library/Notifications/Model/Incident.php index acb5f64e4..0cff661ec 100644 --- a/library/Notifications/Model/Incident.php +++ b/library/Notifications/Model/Incident.php @@ -4,11 +4,15 @@ namespace Icinga\Module\Notifications\Model; +use Icinga\Module\Notifications\Common\Database; use ipl\Orm\Behavior\Binary; use ipl\Orm\Behavior\MillisecondTimestamp; use ipl\Orm\Behaviors; use ipl\Orm\Model; +use ipl\Orm\Query; use ipl\Orm\Relations; +use ipl\Sql\Connection; +use ipl\Sql\Select; class Incident extends Model { @@ -52,6 +56,19 @@ public function getDefaultSort() return ['incident.severity desc, incident.started_at']; } + public static function on(Connection $db) + { + $query = parent::on($db); + + $query->on(Query::ON_SELECT_ASSEMBLED, function (Select $select) use ($query) { + if (isset($query->getUtilize()['incident.object.object_id_tag'])) { + Database::registerGroupBy($query, $select); + } + }); + + return $query; + } + public function createBehaviors(Behaviors $behaviors) { $behaviors->add(new Binary(['object_id'])); diff --git a/library/Notifications/Widget/Detail/IncidentDetail.php b/library/Notifications/Widget/Detail/IncidentDetail.php index c3dba4a47..010239319 100644 --- a/library/Notifications/Widget/Detail/IncidentDetail.php +++ b/library/Notifications/Widget/Detail/IncidentDetail.php @@ -7,7 +7,6 @@ use Icinga\Module\Notifications\Common\Database; use Icinga\Module\Notifications\Model\Incident; use Icinga\Module\Notifications\Model\Objects; -use Icinga\Module\Notifications\Model\Source; use Icinga\Module\Notifications\Widget\EventSourceBadge; use Icinga\Module\Notifications\Widget\ItemList\IncidentContactList; use Icinga\Module\Notifications\Widget\ItemList\IncidentHistoryList; @@ -16,7 +15,8 @@ use ipl\Html\Html; use ipl\Html\HtmlElement; use ipl\Html\Table; -use ipl\Stdlib\Filter; +use ipl\Orm\Query; +use ipl\Sql\Select; use ipl\Web\Widget\Link; use ipl\Web\Widget\StateBall; @@ -93,22 +93,28 @@ protected function createRelatedObject() protected function createHistory() { + $history = $this->incident->incident_history + ->with([ + 'event', + 'event.object', + 'event.object.source', + 'contact', + 'rule', + 'rule_escalation', + 'contactgroup', + 'schedule', + 'channel' + ]); + + $history + ->withColumns('event.object.id_tags') + ->on(Query::ON_SELECT_ASSEMBLED, function (Select $select) use ($history) { + Database::registerGroupBy($history, $select); + }); + return [ Html::tag('h2', t('Incident History')), - new IncidentHistoryList( - $this->incident->incident_history - ->with([ - 'event', - 'event.object', - 'event.object.source', - 'contact', - 'rule', - 'rule_escalation', - 'contactgroup', - 'schedule', - 'channel' - ]) - ) + new IncidentHistoryList($history) ]; }