From 8f631df859c20ff5ac77ab14e74d6f7dfb1fad8f Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Thu, 4 Jan 2018 16:50:46 +0100 Subject: [PATCH] fix(sql): add index in centreon_acl for topcounter Refs: #5974 --- .../status/TopCounter/xml/statusCounter.php | 9 ++-- www/install/createTablesCentstorage.sql | 3 +- www/install/insertBaseConf.sql | 2 +- www/install/php/Update-2.8.17_to_2.8.18.php | 49 +++++++++++++++++++ .../centreon/Update-DB-2.8.17_to_2.8.18.sql | 2 + 5 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 www/install/php/Update-2.8.17_to_2.8.18.php create mode 100644 www/install/sql/centreon/Update-DB-2.8.17_to_2.8.18.sql diff --git a/www/include/monitoring/status/TopCounter/xml/statusCounter.php b/www/include/monitoring/status/TopCounter/xml/statusCounter.php index 88b511c6062..9bc29481079 100644 --- a/www/include/monitoring/status/TopCounter/xml/statusCounter.php +++ b/www/include/monitoring/status/TopCounter/xml/statusCounter.php @@ -129,10 +129,13 @@ "AND h.host_id = s.host_id " . "AND (h.name NOT LIKE '_Module_%' OR h.name LIKE '_Module_Meta%') "; if (!$obj->is_admin) { - $query_svc_status .= "AND s.service_id IN ( " . - "SELECT DISTINCT service_id " . + $query_svc_status .= "AND EXISTS (" . + "SELECT service_id " . "FROM centreon_acl " . - "WHERE centreon_acl.group_id IN (" . $obj->grouplistStr . ")) "; + "WHERE centreon_acl.host_id = h.host_id " . + "AND centreon_acl.service_id = s.service_id " . + "AND centreon_acl.group_id IN (" . $obj->grouplistStr . ")" . + ") "; } $DBRESULT = $obj->DBC->query($query_svc_status); $svc_stat = array_map("myDecode", $DBRESULT->fetchRow()); diff --git a/www/install/createTablesCentstorage.sql b/www/install/createTablesCentstorage.sql index 0d93174d040..2355275afb7 100644 --- a/www/install/createTablesCentstorage.sql +++ b/www/install/createTablesCentstorage.sql @@ -15,7 +15,8 @@ CREATE TABLE `centreon_acl` ( `host_id` int(11) DEFAULT NULL, `service_id` int(11) DEFAULT NULL, `group_id` int(11) DEFAULT NULL, - KEY `index1` (`group_id`,`host_id`,`service_id`) + KEY `index1` (`group_id`,`host_id`,`service_id`), + KEY `index2` (`host_id`,`service_id`,`group_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/www/install/insertBaseConf.sql b/www/install/insertBaseConf.sql index c0421ab8cc9..ba3cc190a27 100644 --- a/www/install/insertBaseConf.sql +++ b/www/install/insertBaseConf.sql @@ -2,7 +2,7 @@ -- Insert version -- -INSERT INTO `informations` (`key` ,`value`) VALUES ('version', '2.8.17'); +INSERT INTO `informations` (`key` ,`value`) VALUES ('version', '2.8.18'); -- -- Contenu de la table `contact` diff --git a/www/install/php/Update-2.8.17_to_2.8.18.php b/www/install/php/Update-2.8.17_to_2.8.18.php new file mode 100644 index 00000000000..6fcf10e9a16 --- /dev/null +++ b/www/install/php/Update-2.8.17_to_2.8.18.php @@ -0,0 +1,49 @@ +. + * + * Linking this program statically or dynamically with other modules is making a + * combined work based on this program. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this program give Centreon + * permission to link this program with independent modules to produce an executable, + * regardless of the license terms of these independent modules, and to copy and + * distribute the resulting executable under terms of Centreon choice, provided that + * Centreon also meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module which is not + * derived from this program. If you modify this program, you may extend this + * exception to your version of the program, but you are not obliged to do so. If you + * do not wish to do so, delete this exception statement from your version. + * + * For more information : contact@centreon.com + * + * + */ + +/* Update comments unique key */ +if (isset($pearDBO)) { + $query = "SELECT count(*) AS number " . + "FROM INFORMATION_SCHEMA.STATISTICS " . + "WHERE table_schema = '" . $conf_centreon['dbcstg'] . "' " . + "AND table_name = 'centreon_acl' " . + "AND index_name='index1'"; + $res = $pearDBO->query($query); + $data = $res->fetchRow(); + if ($data['number'] == 0) { + $pearDBO->query('ALTER TABLE centreon_acl ADD INDEX `index2` (`host_id`,`service_id`,`group_id`)'); + } +} diff --git a/www/install/sql/centreon/Update-DB-2.8.17_to_2.8.18.sql b/www/install/sql/centreon/Update-DB-2.8.17_to_2.8.18.sql new file mode 100644 index 00000000000..15477918626 --- /dev/null +++ b/www/install/sql/centreon/Update-DB-2.8.17_to_2.8.18.sql @@ -0,0 +1,2 @@ +-- Change version of Centreon +UPDATE `informations` SET `value` = '2.8.18' WHERE CONVERT( `informations`.`key` USING utf8 ) = 'version' AND CONVERT ( `informations`.`value` USING utf8 ) = '2.8.17' LIMIT 1;