Skip to content

Commit

Permalink
Fix failed to resolve reversed host/service -> comment relations (#…
Browse files Browse the repository at this point in the history
…858)

fixes #827
  • Loading branch information
yhabteab authored Sep 6, 2023
2 parents c626bc1 + b17c306 commit cacc770
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
6 changes: 0 additions & 6 deletions library/Icingadb/Model/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,7 @@ public function createRelations(Relations $relations)
{
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('host', Host::class)->setJoinType('LEFT');
$relations->belongsTo('host_state', HostState::class)
->setForeignKey('last_comment_id')
->setCandidateKey('id');
$relations->belongsTo('service', Service::class)->setJoinType('LEFT');
$relations->belongsTo('service_state', ServiceState::class)
->setForeignKey('last_comment_id')
->setCandidateKey('id');
$relations->belongsTo('zone', Zone::class);
}
}
2 changes: 1 addition & 1 deletion library/Icingadb/Model/HostState.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function createRelations(Relations $relations)
{
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('host', Host::class);
$relations->hasOne('last_comment', Comment::class)
$relations->hasOne('last_comment', LastHostComment::class)
->setCandidateKey('last_comment_id')
->setForeignKey('id')
->setJoinType('LEFT');
Expand Down
19 changes: 19 additions & 0 deletions library/Icingadb/Model/LastHostComment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/* Icinga DB Web | (c) 2023 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Icingadb\Model;

use ipl\Orm\Relations;

class LastHostComment extends Comment
{
public function createRelations(Relations $relations): void
{
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('zone', Zone::class);
$relations->belongsTo('state', HostState::class)
->setForeignKey('last_comment_id')
->setCandidateKey('id');
}
}
19 changes: 19 additions & 0 deletions library/Icingadb/Model/LastServiceComment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/* Icinga DB Web | (c) 2023 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Icingadb\Model;

use ipl\Orm\Relations;

class LastServiceComment extends Comment
{
public function createRelations(Relations $relations): void
{
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('zone', Zone::class);
$relations->belongsTo('state', ServiceState::class)
->setForeignKey('last_comment_id')
->setCandidateKey('id');
}
}
2 changes: 1 addition & 1 deletion library/Icingadb/Model/ServiceState.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function createRelations(Relations $relations)
{
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('service', Service::class);
$relations->hasOne('last_comment', Comment::class)
$relations->hasOne('last_comment', LastServiceComment::class)
->setCandidateKey('last_comment_id')
->setForeignKey('id')
->setJoinType('LEFT');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ protected static function collectRelations(Resolver $resolver, Model $subject, a
/** @var Relation $relation */
if (
empty($path) || (
$name === 'state'
($name === 'state' && $path[count($path) - 1] !== 'last_comment')
|| $name === 'last_comment'
|| $name === 'notificationcommand' && $path[0] === 'notification'
)
Expand Down

0 comments on commit cacc770

Please sign in to comment.