From 2e795fa0ab04bce52614eeebebdece8b8415bfb0 Mon Sep 17 00:00:00 2001 From: sc979 <34628915+sc979@users.noreply.github.com> Date: Mon, 25 Jun 2018 10:32:33 +0200 Subject: [PATCH] fix(db): remove duplicate entries in centreon_acl table (#6366) * fix(DB): upgrade DB to correct a bug * fix(DB): centAcl close DB connection before the update is achieved * fix(acl): Add primary key and handle duplicate entries in centreon_acl * fix(sql): delete duplicate entries in centreon_acl table * feat(install): add base version to 2.8.24 * doc(upgrade): add empty release notes for 2.8.24 --- cron/centAcl.php | 7 +- .../centreon-2.8/centreon-2.8.24.rst | 3 + .../centreon-2.8/centreon-2.8.24.rst | 3 + www/install/createTablesCentstorage.sql | 8 +- www/install/insertBaseConf.sql | 2 +- www/install/php/Update-2.8.23_to_2.8.24.php | 96 +++++++++++++++++++ .../centreon/Update-DB-2.8.23_to_2.8.24.sql | 2 + 7 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 doc/en/release_notes/centreon-2.8/centreon-2.8.24.rst create mode 100644 doc/fr/release_notes/centreon-2.8/centreon-2.8.24.rst create mode 100644 www/install/php/Update-2.8.23_to_2.8.24.php create mode 100644 www/install/sql/centreon/Update-DB-2.8.23_to_2.8.24.sql diff --git a/cron/centAcl.php b/cron/centAcl.php index a1b910dbd0d..e992b686772 100644 --- a/cron/centAcl.php +++ b/cron/centAcl.php @@ -593,7 +593,8 @@ function programExit($msg) $str .= "('" . $id_tmp[0] . "' , '" . $id_tmp[1] . "' , " . $acl_group_id . ") "; $i++; if ($i >= 1000) { - $pearDBO->query($strBegin . $str); + $strEnd = " ON DUPLICATE KEY UPDATE `group_id` = $acl_group_id"; + $pearDBO->query($strBegin . $str . $strEnd); $str = ""; $i = 0; } @@ -604,7 +605,8 @@ function programExit($msg) * Insert datas */ if ($str != "") { - $pearDBO->query($strBegin . $str); + $strEnd = " ON DUPLICATE KEY UPDATE `group_id` = $acl_group_id"; + $pearDBO->query($strBegin . $str . $strEnd); $str = ""; } } @@ -645,6 +647,7 @@ function programExit($msg) */ $pearDB->disconnect(); $pearDBO->disconnect(); + } catch (Exception $e) { programExit($e->getMessage()); } diff --git a/doc/en/release_notes/centreon-2.8/centreon-2.8.24.rst b/doc/en/release_notes/centreon-2.8/centreon-2.8.24.rst new file mode 100644 index 00000000000..351eb4dfcd5 --- /dev/null +++ b/doc/en/release_notes/centreon-2.8/centreon-2.8.24.rst @@ -0,0 +1,3 @@ +################### +Centreon Web 2.8.24 +################### diff --git a/doc/fr/release_notes/centreon-2.8/centreon-2.8.24.rst b/doc/fr/release_notes/centreon-2.8/centreon-2.8.24.rst new file mode 100644 index 00000000000..351eb4dfcd5 --- /dev/null +++ b/doc/fr/release_notes/centreon-2.8/centreon-2.8.24.rst @@ -0,0 +1,3 @@ +################### +Centreon Web 2.8.24 +################### diff --git a/www/install/createTablesCentstorage.sql b/www/install/createTablesCentstorage.sql index 2355275afb7..23d163490a1 100644 --- a/www/install/createTablesCentstorage.sql +++ b/www/install/createTablesCentstorage.sql @@ -12,11 +12,11 @@ /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `centreon_acl` ( - `host_id` int(11) DEFAULT NULL, + `group_id` int(11) NOT NULL, + `host_id` int(11) NOT NULL, `service_id` int(11) DEFAULT NULL, - `group_id` int(11) DEFAULT NULL, - KEY `index1` (`group_id`,`host_id`,`service_id`), - KEY `index2` (`host_id`,`service_id`,`group_id`) + UNIQUE KEY (`group_id`,`host_id`,`service_id`), + KEY `index1` (`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 486d9315eed..9d09be6a019 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.23'); +INSERT INTO `informations` (`key` ,`value`) VALUES ('version', '2.8.24'); -- -- Contenu de la table `contact` diff --git a/www/install/php/Update-2.8.23_to_2.8.24.php b/www/install/php/Update-2.8.23_to_2.8.24.php new file mode 100644 index 00000000000..5fc4d7ac75f --- /dev/null +++ b/www/install/php/Update-2.8.23_to_2.8.24.php @@ -0,0 +1,96 @@ +. + * + * 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 + * + * + */ + +/* + * Create tempory table to delete duplicate entries + */ +$query = 'CREATE TABLE `centreon_acl_new` ( ' . + '`group_id` int(11) NOT NULL, ' . + '`host_id` int(11) NOT NULL, ' . + '`service_id` int(11) DEFAULT NULL, ' . + 'UNIQUE KEY (`group_id`,`host_id`,`service_id`), ' . + 'KEY `index1` (`host_id`,`service_id`,`group_id`) ' . + ') ENGINE=InnoDB DEFAULT CHARSET=utf8 '; +$pearDBO->query($query); + +/** + * Checking if centAcl.php is running and waiting 2min for it to stop before locking cron_operation table + */ +$query = "SELECT running FROM cron_operation WHERE `name` = 'centAcl.php'"; +$i = 0; +while ($i < 120) { + $i++; + $result = $pearDB->query($query); + while ($row = $result->fetchRow()) { + if ($row['running'] == "1") { + sleep(1); + } else { + break(2); + } + } +} + +/** + * Lock centAcl cron during upgrade + */ +$query = "UPDATE cron_operation SET running = '1' WHERE `name` = 'centAcl.php'"; +$pearDB->query($query); + +/** + * Copy data from old table to new table with duplicate entries deletion + */ +$query = 'INSERT INTO centreon_acl_new (group_id, host_id, service_id) ' . + 'SELECT group_id, host_id, service_id FROM centreon_acl ' . + 'GROUP BY group_id, host_id, service_id'; +$pearDBO->query($query); + +/** + * Drop old table with duplicate entries + */ +$query = 'DROP TABLE centreon_acl'; +$pearDBO->query($query); + +/** + * Rename temporary table to stable table + */ +$query = 'ALTER TABLE centreon_acl_new RENAME TO centreon_acl'; +$pearDBO->query($query); + +/** + * Unlock centAcl cron during upgrade + */ +$query = "UPDATE cron_operation SET running = '0' WHERE `name` = 'centAcl.php'"; +$pearDB->query($query); diff --git a/www/install/sql/centreon/Update-DB-2.8.23_to_2.8.24.sql b/www/install/sql/centreon/Update-DB-2.8.23_to_2.8.24.sql new file mode 100644 index 00000000000..8c2999d0ee1 --- /dev/null +++ b/www/install/sql/centreon/Update-DB-2.8.23_to_2.8.24.sql @@ -0,0 +1,2 @@ +-- Change version of Centreon +UPDATE `informations` SET `value` = '2.8.24' WHERE CONVERT( `informations`.`key` USING utf8 ) = 'version' AND CONVERT ( `informations`.`value` USING utf8 ) = '2.8.23' LIMIT 1; \ No newline at end of file