Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix(db): remove duplicate entries in centreon_acl table (#6366)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sc979 authored and kduret committed Jun 25, 2018
1 parent 9a739dc commit 2e795fa
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 7 deletions.
7 changes: 5 additions & 2 deletions cron/centAcl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 = "";
}
}
Expand Down Expand Up @@ -645,6 +647,7 @@ function programExit($msg)
*/
$pearDB->disconnect();
$pearDBO->disconnect();

} catch (Exception $e) {
programExit($e->getMessage());
}
3 changes: 3 additions & 0 deletions doc/en/release_notes/centreon-2.8/centreon-2.8.24.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
###################
Centreon Web 2.8.24
###################
3 changes: 3 additions & 0 deletions doc/fr/release_notes/centreon-2.8/centreon-2.8.24.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
###################
Centreon Web 2.8.24
###################
8 changes: 4 additions & 4 deletions www/install/createTablesCentstorage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 */;

Expand Down
2 changes: 1 addition & 1 deletion www/install/insertBaseConf.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
96 changes: 96 additions & 0 deletions www/install/php/Update-2.8.23_to_2.8.24.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/*
* Copyright 2005-2018 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation ; either version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see <http://www.gnu.org/licenses>.
*
* 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);
2 changes: 2 additions & 0 deletions www/install/sql/centreon/Update-DB-2.8.23_to_2.8.24.sql
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 2e795fa

Please sign in to comment.