From b17c30632d4915884e0855365b169b60d59a892d Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Fri, 1 Sep 2023 14:48:47 +0200 Subject: [PATCH] Fix failed to resolve reversed `host/service` -> `comment` relations --- library/Icingadb/Model/Comment.php | 6 ------ library/Icingadb/Model/HostState.php | 2 +- library/Icingadb/Model/LastHostComment.php | 19 +++++++++++++++++++ library/Icingadb/Model/LastServiceComment.php | 19 +++++++++++++++++++ library/Icingadb/Model/ServiceState.php | 2 +- .../Control/SearchBar/ObjectSuggestions.php | 2 +- 6 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 library/Icingadb/Model/LastHostComment.php create mode 100644 library/Icingadb/Model/LastServiceComment.php diff --git a/library/Icingadb/Model/Comment.php b/library/Icingadb/Model/Comment.php index e010524c..bcdd5e05 100644 --- a/library/Icingadb/Model/Comment.php +++ b/library/Icingadb/Model/Comment.php @@ -108,13 +108,7 @@ class Comment extends Model { $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); } } diff --git a/library/Icingadb/Model/HostState.php b/library/Icingadb/Model/HostState.php index baeb0a57..efa27528 100644 --- a/library/Icingadb/Model/HostState.php +++ b/library/Icingadb/Model/HostState.php @@ -61,7 +61,7 @@ class HostState extends State { $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'); diff --git a/library/Icingadb/Model/LastHostComment.php b/library/Icingadb/Model/LastHostComment.php new file mode 100644 index 00000000..621b2044 --- /dev/null +++ b/library/Icingadb/Model/LastHostComment.php @@ -0,0 +1,19 @@ +belongsTo('environment', Environment::class); + $relations->belongsTo('zone', Zone::class); + $relations->belongsTo('state', HostState::class) + ->setForeignKey('last_comment_id') + ->setCandidateKey('id'); + } +} diff --git a/library/Icingadb/Model/LastServiceComment.php b/library/Icingadb/Model/LastServiceComment.php new file mode 100644 index 00000000..4d44f11e --- /dev/null +++ b/library/Icingadb/Model/LastServiceComment.php @@ -0,0 +1,19 @@ +belongsTo('environment', Environment::class); + $relations->belongsTo('zone', Zone::class); + $relations->belongsTo('state', ServiceState::class) + ->setForeignKey('last_comment_id') + ->setCandidateKey('id'); + } +} diff --git a/library/Icingadb/Model/ServiceState.php b/library/Icingadb/Model/ServiceState.php index 1448dd01..c5daa08c 100644 --- a/library/Icingadb/Model/ServiceState.php +++ b/library/Icingadb/Model/ServiceState.php @@ -58,7 +58,7 @@ class ServiceState extends State { $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'); diff --git a/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php b/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php index db2c84d8..b89e7291 100644 --- a/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php +++ b/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php @@ -387,7 +387,7 @@ class ObjectSuggestions extends Suggestions /** @var Relation $relation */ if ( empty($path) || ( - $name === 'state' + ($name === 'state' && $path[count($path) - 1] !== 'last_comment') || $name === 'last_comment' || $name === 'notificationcommand' && $path[0] === 'notification' )