From 63df000f929bb88dc233795eadb919d93aaa56ab Mon Sep 17 00:00:00 2001 From: jben94 Date: Mon, 22 May 2017 11:32:22 +0200 Subject: [PATCH 1/5] Fixed database entry duplication --- www/class/centreonCustomView.class.php | 27 +++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/www/class/centreonCustomView.class.php b/www/class/centreonCustomView.class.php index 2178500520a..3f6b9bdb210 100644 --- a/www/class/centreonCustomView.class.php +++ b/www/class/centreonCustomView.class.php @@ -596,7 +596,8 @@ public function syncCustomView($customViewId, $userId = null) public function loadCustomView($params) { $isLocked = 1; - $query = 'SELECT custom_view_id, locked ' . + $update = false; + $query = 'SELECT custom_view_id, locked, user_id ' . 'FROM custom_view_user_relation ' . 'WHERE custom_view_id = :viewLoad ' . 'AND ' . @@ -618,14 +619,26 @@ public function loadCustomView($params) if ($row['locked'] == "0") { $isLocked = $row['locked']; } + if (!is_null($row['user_id']) && $row['user_id'] > 0){ + $update = true; + } } - $query = 'INSERT INTO custom_view_user_relation (custom_view_id,user_id,is_owner,locked,is_share) ' . - 'VALUES (:viewLoad, :userId, 0, :isLocked, 1)'; - $stmt = $this->db->prepare($query); - $stmt->bindParam(':viewLoad', $params['viewLoad'], PDO::PARAM_INT); - $stmt->bindParam(':userId', $this->userId, PDO::PARAM_INT); - $stmt->bindParam(':isLocked', $isLocked, PDO::PARAM_INT); + if ($update){ + $query = 'UPDATE custom_view_user_relation SET is_consumed=\'1\' WHERE ' . + ' custom_view_id = :viewLoad AND user_id = :userId'; + $stmt = $this->db->prepare($query); + $stmt->bindParam(':viewLoad', $params['viewLoad'], PDO::PARAM_INT); + $stmt->bindParam(':userId', $this->userId, PDO::PARAM_INT); + } + else { + $query = 'INSERT INTO custom_view_user_relation (custom_view_id,user_id,is_owner,locked,is_share) ' . + 'VALUES (:viewLoad, :userId, 0, :isLocked, 1)'; + $stmt = $this->db->prepare($query); + $stmt->bindParam(':viewLoad', $params['viewLoad'], PDO::PARAM_INT); + $stmt->bindParam(':userId', $this->userId, PDO::PARAM_INT); + $stmt->bindParam(':isLocked', $isLocked, PDO::PARAM_INT); + } $dbResult = $stmt->execute(); if (!$dbResult) { throw new \Exception("An error occured"); From 39fea22d55cfb6db2e663c10402c1cec07023ba1 Mon Sep 17 00:00:00 2001 From: Kev Date: Wed, 12 Jul 2017 11:51:48 +0200 Subject: [PATCH 2/5] Fix coding style --- www/class/centreonCustomView.class.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/www/class/centreonCustomView.class.php b/www/class/centreonCustomView.class.php index 3f6b9bdb210..7fe8e9eec36 100644 --- a/www/class/centreonCustomView.class.php +++ b/www/class/centreonCustomView.class.php @@ -624,14 +624,13 @@ public function loadCustomView($params) } } - if ($update){ - $query = 'UPDATE custom_view_user_relation SET is_consumed=\'1\' WHERE ' . + if ($update) { + $query = 'UPDATE custom_view_user_relation SET is_consumed=1 WHERE ' . ' custom_view_id = :viewLoad AND user_id = :userId'; $stmt = $this->db->prepare($query); $stmt->bindParam(':viewLoad', $params['viewLoad'], PDO::PARAM_INT); $stmt->bindParam(':userId', $this->userId, PDO::PARAM_INT); - } - else { + } else { $query = 'INSERT INTO custom_view_user_relation (custom_view_id,user_id,is_owner,locked,is_share) ' . 'VALUES (:viewLoad, :userId, 0, :isLocked, 1)'; $stmt = $this->db->prepare($query); From cb8c5a7ae056e337856c61ecb97cec26ec2e08b7 Mon Sep 17 00:00:00 2001 From: jben94 Date: Wed, 12 Jul 2017 15:01:29 +0200 Subject: [PATCH 3/5] Fix "unique" field in table "custom_view_user_relation" --- www/install/createTables.sql | 3 ++- .../sql/centreon/Update-DB-2.8.8_to_2.9.0.sql | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/www/install/createTables.sql b/www/install/createTables.sql index 17f57b8d944..300b6e4dee1 100644 --- a/www/install/createTables.sql +++ b/www/install/createTables.sql @@ -962,7 +962,8 @@ CREATE TABLE `custom_view_user_relation` ( `is_owner` tinyint(6) DEFAULT '0', `is_share` tinyint(6) DEFAULT '0', `is_consumed` int(1) NOT NULL DEFAULT 1, - UNIQUE KEY `view_user_unique_index` (`custom_view_id`,`user_id`,`usergroup_id`), + UNIQUE KEY `view_user_unique_index` (`custom_view_id`,`user_id`), + UNIQUE KEY `view_usergroup_unique_index` (`custom_view_id`,`usergroup_id`), KEY `fk_custom_views_user_id` (`user_id`), KEY `fk_custom_views_usergroup_id` (`usergroup_id`), CONSTRAINT `fk_custom_views_user_id` FOREIGN KEY (`user_id`) REFERENCES `contact` (`contact_id`) ON DELETE CASCADE, diff --git a/www/install/sql/centreon/Update-DB-2.8.8_to_2.9.0.sql b/www/install/sql/centreon/Update-DB-2.8.8_to_2.9.0.sql index 932b1028a4f..ece98391ebf 100644 --- a/www/install/sql/centreon/Update-DB-2.8.8_to_2.9.0.sql +++ b/www/install/sql/centreon/Update-DB-2.8.8_to_2.9.0.sql @@ -2,3 +2,27 @@ UPDATE `informations` SET `value` = '2.9.0' WHERE CONVERT( `informations`.`key` USING utf8 ) = 'version' AND CONVERT ( `informations`.`value` USING utf8 ) = '2.8.7' LIMIT 1; ALTER TABLE `cfg_nagios` DROP COLUMN `log_initial_states`; + +ALTER TABLE `custom_view_user_relation` + DROP FOREIGN KEY `fk_custom_views_usergroup_id`, + DROP FOREIGN KEY `fk_custom_views_user_id`, + DROP FOREIGN KEY `fk_custom_view_user_id`, + DROP INDEX `view_user_unique_index`; + +ALTER IGNORE TABLE `custom_view_user_relation` + ADD UNIQUE INDEX `view_user_unique_index` (`custom_view_id`, `user_id`), + ADD UNIQUE INDEX `view_usergroup_unique_index` (`custom_view_id`, `usergroup_id`); + +ALTER TABLE `custom_view_user_relation` + ADD CONSTRAINT `fk_custom_views_usergroup_id` + FOREIGN KEY (`usergroup_id`) + REFERENCES `centreon`.`contactgroup` (`cg_id`) + ON DELETE CASCADE, + ADD CONSTRAINT `fk_custom_views_user_id` + FOREIGN KEY (`user_id`) + REFERENCES `centreon`.`contact` (`contact_id`) + ON DELETE CASCADE, + ADD CONSTRAINT `fk_custom_view_user_id` + FOREIGN KEY (`custom_view_id`) + REFERENCES `centreon`.`custom_views` (`custom_view_id`) + ON DELETE CASCADE; \ No newline at end of file From 6f6b4a678bbfe8ea07f9b7e7fc64dfc02b3385ea Mon Sep 17 00:00:00 2001 From: Kev Date: Wed, 12 Jul 2017 18:01:11 +0200 Subject: [PATCH 4/5] Update Update-DB-2.8.8_to_2.9.0.sql --- www/install/sql/centreon/Update-DB-2.8.8_to_2.9.0.sql | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/www/install/sql/centreon/Update-DB-2.8.8_to_2.9.0.sql b/www/install/sql/centreon/Update-DB-2.8.8_to_2.9.0.sql index ece98391ebf..bfd6a9cd4e9 100644 --- a/www/install/sql/centreon/Update-DB-2.8.8_to_2.9.0.sql +++ b/www/install/sql/centreon/Update-DB-2.8.8_to_2.9.0.sql @@ -3,16 +3,15 @@ UPDATE `informations` SET `value` = '2.9.0' WHERE CONVERT( `informations`.`key` ALTER TABLE `cfg_nagios` DROP COLUMN `log_initial_states`; +-- Delete duplicate entries in custom_view_user_relation ALTER TABLE `custom_view_user_relation` DROP FOREIGN KEY `fk_custom_views_usergroup_id`, DROP FOREIGN KEY `fk_custom_views_user_id`, DROP FOREIGN KEY `fk_custom_view_user_id`, DROP INDEX `view_user_unique_index`; - ALTER IGNORE TABLE `custom_view_user_relation` ADD UNIQUE INDEX `view_user_unique_index` (`custom_view_id`, `user_id`), ADD UNIQUE INDEX `view_usergroup_unique_index` (`custom_view_id`, `usergroup_id`); - ALTER TABLE `custom_view_user_relation` ADD CONSTRAINT `fk_custom_views_usergroup_id` FOREIGN KEY (`usergroup_id`) @@ -25,4 +24,4 @@ ALTER TABLE `custom_view_user_relation` ADD CONSTRAINT `fk_custom_view_user_id` FOREIGN KEY (`custom_view_id`) REFERENCES `centreon`.`custom_views` (`custom_view_id`) - ON DELETE CASCADE; \ No newline at end of file + ON DELETE CASCADE; From eee1e0289a1f228fa745bcd91a048c249ae4180b Mon Sep 17 00:00:00 2001 From: Kev Date: Wed, 12 Jul 2017 18:03:16 +0200 Subject: [PATCH 5/5] Update and rename Update-DB-2.8.8_to_2.9.0.sql to Update-DB-2.8.10_to_2.9.0.sql --- ....9.0.sql => Update-DB-2.8.10_to_2.9.0.sql} | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) rename www/install/sql/centreon/{Update-DB-2.8.8_to_2.9.0.sql => Update-DB-2.8.10_to_2.9.0.sql} (59%) diff --git a/www/install/sql/centreon/Update-DB-2.8.8_to_2.9.0.sql b/www/install/sql/centreon/Update-DB-2.8.10_to_2.9.0.sql similarity index 59% rename from www/install/sql/centreon/Update-DB-2.8.8_to_2.9.0.sql rename to www/install/sql/centreon/Update-DB-2.8.10_to_2.9.0.sql index bfd6a9cd4e9..b4446eaa644 100644 --- a/www/install/sql/centreon/Update-DB-2.8.8_to_2.9.0.sql +++ b/www/install/sql/centreon/Update-DB-2.8.10_to_2.9.0.sql @@ -1,18 +1,30 @@ -- Change version of Centreon -UPDATE `informations` SET `value` = '2.9.0' WHERE CONVERT( `informations`.`key` USING utf8 ) = 'version' AND CONVERT ( `informations`.`value` USING utf8 ) = '2.8.7' LIMIT 1; +UPDATE `informations` SET `value` = '2.9.0' WHERE CONVERT( `informations`.`key` USING utf8 ) = 'version' AND CONVERT ( `informations`.`value` USING utf8 ) = '2.8.10' LIMIT 1; -ALTER TABLE `cfg_nagios` DROP COLUMN `log_initial_states`; +ALTER TABLE `extended_host_information` DROP FOREIGN KEY `extended_host_information_ibfk_3`; +ALTER TABLE `extended_host_information` DROP COLUMN `ehi_vrml_image`; + +DELETE FROM topology_JS WHERE PathName_js LIKE '%aculous%'; + +UPDATE `cb_field` +SET `fieldname` = 'negotiation', `displayname` = 'Enable negotiation', +`description` = 'Enable negotiation option (use only for version of Centren Broker >= 2.5)' +WHERE `fieldname` = 'negociation'; + +UPDATE `cfg_centreonbroker_info` +SET `config_key` = 'negotiation' +WHERE `config_key` = 'negociation'; -- Delete duplicate entries in custom_view_user_relation -ALTER TABLE `custom_view_user_relation` +ALTER TABLE `custom_view_user_relation` DROP FOREIGN KEY `fk_custom_views_usergroup_id`, DROP FOREIGN KEY `fk_custom_views_user_id`, DROP FOREIGN KEY `fk_custom_view_user_id`, DROP INDEX `view_user_unique_index`; -ALTER IGNORE TABLE `custom_view_user_relation` +ALTER IGNORE TABLE `custom_view_user_relation` ADD UNIQUE INDEX `view_user_unique_index` (`custom_view_id`, `user_id`), ADD UNIQUE INDEX `view_usergroup_unique_index` (`custom_view_id`, `usergroup_id`); -ALTER TABLE `custom_view_user_relation` +ALTER TABLE `custom_view_user_relation` ADD CONSTRAINT `fk_custom_views_usergroup_id` FOREIGN KEY (`usergroup_id`) REFERENCES `centreon`.`contactgroup` (`cg_id`)