Skip to content

Conversation

@moreamazingnick
Copy link
Contributor

shows commands and command templates and filters by commandname in the table views

Best Regards
Nicolas

@cla-bot cla-bot bot added the cla/signed label Sep 19, 2025
Comment on lines +104 to +110
$query = $this->db->select()->from(array('c' => 'icinga_' . $table), $columns)->join(array('ici' => 'icinga_command_inheritance'),
'ici.command_id = c.id',
array());

foreach ($rels as $rel) {
$query->orWhere("parent_{$rel}_id = ?", $id);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$query = $this->db->select()->from(array('c' => 'icinga_' . $table), $columns)->join(array('ici' => 'icinga_command_inheritance'),
'ici.command_id = c.id',
array());
foreach ($rels as $rel) {
$query->orWhere("parent_{$rel}_id = ?", $id);
}
$query = $this->db->select()->from(['c' => 'icinga_' . $table], $columns)->join(
['ici' => 'icinga_command_inheritance'],
'ici.command_id = c.id',
[]
)->where('ici.parent_command_id = ?', $id);

IMO, you could rewrite the where as suggested, just makes it a bit easier to understand the code

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems not to be resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would render the $rels var useless, and might break something else

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The $rels variable comes from the $map variable. You could give an empty array there, as the relation in the map is basically used to build the column {rel}_id to filter the objects. And since for command you filter its inheritance table. You could directly filter it in the query.

Or you could do the below, where you add the join and the filter to the query only if the table is 'command', and everything remains same. This solution also results in minimal changes to the existing code. You should still give empty array for command ('command' => []) in $map variable. Also, looking at it again I find this solution better.

        $query = $this->db->select()->from(['c' => "icinga_$table"], $columns);
        if ($table === "command") {
            $query->join(
                ['ici' => 'icinga_command_inheritance'],
                'ici.command_id = c.id',
                []
            )->where('ici.parent_command_id = ?', $id);
        }

        foreach ($rels as $rel) {
            $query->orWhere("{$rel}_id = ?", $id);
        }

Comment on lines +104 to +110
$query = $this->db->select()->from(array('c' => 'icinga_' . $table), $columns)->join(array('ici' => 'icinga_command_inheritance'),
'ici.command_id = c.id',
array());

foreach ($rels as $rel) {
$query->orWhere("parent_{$rel}_id = ?", $id);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems not to be resolved

Co-authored-by: Ravi Kumar Kempapura Srinivasa <[email protected]>
Comment on lines +104 to +110
$query = $this->db->select()->from(array('c' => 'icinga_' . $table), $columns)->join(array('ici' => 'icinga_command_inheritance'),
'ici.command_id = c.id',
array());

foreach ($rels as $rel) {
$query->orWhere("parent_{$rel}_id = ?", $id);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The $rels variable comes from the $map variable. You could give an empty array there, as the relation in the map is basically used to build the column {rel}_id to filter the objects. And since for command you filter its inheritance table. You could directly filter it in the query.

Or you could do the below, where you add the join and the filter to the query only if the table is 'command', and everything remains same. This solution also results in minimal changes to the existing code. You should still give empty array for command ('command' => []) in $map variable. Also, looking at it again I find this solution better.

        $query = $this->db->select()->from(['c' => "icinga_$table"], $columns);
        if ($table === "command") {
            $query->join(
                ['ici' => 'icinga_command_inheritance'],
                'ici.command_id = c.id',
                []
            )->where('ici.parent_command_id = ?', $id);
        }

        foreach ($rels as $rel) {
            $query->orWhere("{$rel}_id = ?", $id);
        }

'host' => ['check_command', 'event_command'],
'service' => ['check_command', 'event_command'],
'notification' => ['command'],
'command' => ['command'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'command' => ['command'],
'command' => [],

This could be an empty array, as this is basically used to build the command id column for the table to filter the objects using the corresponding command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants