Commit 6f868b05 authored by Adrien Morais-Mestre's avatar Adrien Morais-Mestre Committed by Thomas Untoja
Browse files

fix(resource): correctly display comments for DT and ACK (#10914)

* fix(resource): correctly display comments for DT and ACK

This reverts commit 94e35535 and fixes some issues regarding phpstan

* centreon-bot: patch coding style errors found
parent 0af5502b
......@@ -159,26 +159,11 @@ final class AcknowledgementRepositoryRDB extends AbstractRepositoryDRB implement
AND acg.acl_group_activate = \'1\'
AND acg.acl_group_id IN (' . $this->accessGroupIdToString($this->accessGroups) . ') ';
$request = 'SELECT
ack.acknowledgement_id,
ack.entry_time,
ack.host_id,
ack.service_id,
ack.author,
`cmts`.data AS `comment_data`,
ack.deletion_time,
ack.instance_id,
ack.notify_contacts,
ack.persistent_comment,
ack.state,
ack.sticky,
ack.type,
contact.contact_id AS `author_id`
$request =
'SELECT ack.*, contact.contact_id AS author_id
FROM `:dbstg`.acknowledgements ack
LEFT JOIN `:db`.contact
ON contact.contact_alias = ack.author
LEFT JOIN `:dbstg`.`comments` AS `cmts`
ON `cmts`.host_id = ack.host_id AND `cmts`.deletion_time IS NULL'
ON contact.contact_alias = ack.author'
. $accessGroupFilter
. 'WHERE ack.host_id = :host_id
AND ack.service_id = 0';
......@@ -210,27 +195,11 @@ final class AcknowledgementRepositoryRDB extends AbstractRepositoryDRB implement
AND acg.acl_group_activate = \'1\'
AND acg.acl_group_id IN (' . $this->accessGroupIdToString($this->accessGroups) . ') ';
$request = 'SELECT
ack.acknowledgement_id,
ack.entry_time,
ack.host_id,
ack.service_id,
ack.author,
`cmts`.data AS `comment_data`,
ack.deletion_time,
ack.instance_id,
ack.notify_contacts,
ack.persistent_comment,
ack.state,
ack.sticky,
ack.type,
contact.contact_id AS `author_id`
$request =
'SELECT ack.*, contact.contact_id AS author_id
FROM `:dbstg`.acknowledgements ack
LEFT JOIN `:db`.contact
ON contact.contact_alias = ack.author
LEFT JOIN `:dbstg`.`comments` AS `cmts`
ON `cmts`.host_id = ack.host_id AND `cmts`.service_id = ack.host_id
AND `cmts`.deletion_time IS NULL'
ON contact.contact_alias = ack.author'
. $accessGroupFilter
. 'WHERE ack.host_id = :host_id
AND ack.service_id = :service_id';
......
......@@ -380,32 +380,11 @@ class DowntimeRepositoryRDB extends AbstractRepositoryDRB implements DowntimeRep
. $this->accessGroupIdToString($this->accessGroups) . ')';
}
$request = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT
dwt.downtime_id,
dwt.entry_time,
dwt.host_id,
dwt.service_id,
dwt.author,
dwt.cancelled,
`cmts`.data AS `comment_data`,
dwt.deletion_time,
dwt.duration,
dwt.end_time,
dwt.fixed,
dwt.instance_id,
dwt.internal_id,
dwt.start_time,
dwt.actual_start_time,
dwt.actual_end_time,
dwt.started,
dwt.triggered_by,
dwt.type,
contact.contact_id AS `author_id`
$request =
'SELECT SQL_CALC_FOUND_ROWS DISTINCT dwt.*, contact.contact_id AS author_id
FROM `:dbstg`.downtimes dwt
LEFT JOIN `:db`.`contact`
ON contact.contact_alias = dwt.author
LEFT JOIN `:dbstg`.`comments` AS `cmts`
ON `cmts`.host_id = dwt.host_id AND `cmts`.service_id = dwt.service_id
INNER JOIN `:dbstg`.hosts
ON hosts.host_id = dwt.host_id
AND dwt.host_id = :host_id'
......@@ -544,27 +523,8 @@ class DowntimeRepositoryRDB extends AbstractRepositoryDRB implements DowntimeRep
. $this->accessGroupIdToString($this->accessGroups) . ')';
}
$request = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT
dwt.downtime_id,
dwt.entry_time,
dwt.host_id,
dwt.service_id,
dwt.author,
dwt.cancelled,
`cmts`.data AS `comment_data`,
dwt.deletion_time,
dwt.duration,
dwt.end_time,
dwt.fixed,
dwt.instance_id,
dwt.internal_id,
dwt.start_time,
dwt.actual_start_time,
dwt.actual_end_time,
dwt.started,
dwt.triggered_by,
dwt.type,
contact.contact_id AS `author_id`
$request =
'SELECT SQL_CALC_FOUND_ROWS DISTINCT dwt.*, contact.contact_id AS author_id
FROM `:dbstg`.downtimes dwt
INNER JOIN `:dbstg`.hosts
ON hosts.host_id = dwt.host_id
......@@ -574,10 +534,7 @@ class DowntimeRepositoryRDB extends AbstractRepositoryDRB implements DowntimeRep
AND dwt.host_id = :host_id
AND srv.service_id = :service_id
LEFT JOIN `:db`.`contact`
ON contact.contact_alias = dwt.author
LEFT JOIN `:dbstg`.`comments` AS `cmts`
ON `cmts`.host_id = dwt.host_id AND `cmts`.service_id = dwt.service_id
AND `cmts`.deletion_time IS NULL'
ON contact.contact_alias = dwt.author'
. $aclRequest;
$this->sqlRequestTranslator->addSearchValue(':host_id', [\PDO::PARAM_INT => $hostId]);
......
......@@ -1846,37 +1846,13 @@ final class MonitoringRepositoryRDB extends AbstractRepositoryDRB implements Mon
return $downtimes;
}
$sql = 'SELECT
d.downtime_id,
d.entry_time,
d.host_id,
d.service_id,
d.author,
d.cancelled,
`cmts`.data AS `comment_data`,
d.deletion_time,
d.duration,
d.end_time,
d.fixed,
d.instance_id,
d.internal_id,
d.start_time,
d.actual_start_time,
d.actual_end_time,
d.started,
d.triggered_by,
d.type,
c.contact_id AS `author_id`
FROM `:dbstg`.`downtimes` AS `d`
LEFT JOIN `:db`.contact AS `c` ON c.contact_alias = d.author
LEFT JOIN `:dbstg`.`comments` AS `cmts`
ON `cmts`.host_id = d.host_id AND `cmts`.service_id = d.service_id
AND `cmts`.deletion_time IS NULL
WHERE d.host_id = :hostId AND d.service_id = :serviceId
AND d.deletion_time IS NULL AND d.cancelled = 0 AND ((NOW() BETWEEN FROM_UNIXTIME(d.actual_start_time)
AND FROM_UNIXTIME(d.actual_end_time)) OR ((NOW() > FROM_UNIXTIME(d.actual_start_time)
AND d.actual_end_time IS NULL)))
ORDER BY d.entry_time DESC';
$sql = 'SELECT d.*, c.contact_id AS `author_id` FROM `:dbstg`.`downtimes` AS `d` '
. 'LEFT JOIN `:db`.contact AS `c` ON c.contact_alias = d.author '
. 'WHERE d.host_id = :hostId AND d.service_id = :serviceId '
. 'AND d.deletion_time IS NULL AND ((NOW() BETWEEN FROM_UNIXTIME(d.actual_start_time) '
. 'AND FROM_UNIXTIME(d.actual_end_time)) OR ((NOW() > FROM_UNIXTIME(d.actual_start_time) '
. 'AND d.actual_end_time IS NULL))) '
. 'ORDER BY d.entry_time DESC';
$request = $this->translateDbName($sql);
$statement = $this->db->prepare($request);
......@@ -1905,28 +1881,10 @@ final class MonitoringRepositoryRDB extends AbstractRepositoryDRB implements Mon
return $acks;
}
$sql = 'SELECT
a.acknowledgement_id,
a.entry_time,
a.host_id,
a.service_id,
a.author,
`cmts`.data AS `comment_data`,
a.deletion_time,
a.instance_id,
a.notify_contacts,
a.persistent_comment,
a.state,
a.sticky,
a.type,
c.contact_id AS `author_id`
FROM `:dbstg`.`acknowledgements` AS `a`
LEFT JOIN `:db`.contact AS `c` ON c.contact_alias = a.author
LEFT JOIN `:dbstg`.`comments` AS `cmts`
ON `cmts`.host_id = a.host_id AND `cmts`.service_id = a.service_id
AND `cmts`.deletion_time IS NULL
WHERE a.host_id = :hostId AND a.service_id = :serviceId AND a.deletion_time IS NULL
ORDER BY a.entry_time DESC';
$sql = 'SELECT a.*, c.contact_id AS `author_id` FROM `:dbstg`.`acknowledgements` AS `a` '
. 'LEFT JOIN `:db`.contact AS `c` ON c.contact_alias = a.author '
. 'WHERE a.host_id = :hostId AND a.service_id = :serviceId AND a.deletion_time IS NULL '
. 'ORDER BY a.entry_time DESC';
$request = $this->translateDbName($sql);
$statement = $this->db->prepare($request);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment