From 5e2814b43f4996ebffcad942d59c296c9117201d Mon Sep 17 00:00:00 2001 From: schapron Date: Fri, 3 Jan 2020 12:51:12 +0100 Subject: [PATCH 01/18] enh: exception management --- www/install/php/Update-20.04.0-beta.1.php | 132 +++++++++++++--------- 1 file changed, 81 insertions(+), 51 deletions(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index 0e4036dea92..7d05b97422d 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -20,20 +20,17 @@ include_once __DIR__ . "/../../class/centreonLog.class.php"; $centreonLog = new CentreonLog(); -try { - $pearDB->query( - "UPDATE `contact` SET `contact_autologin_key` = NULL WHERE `contact_autologin_key` =''" - ); -} catch (\PDOException $e) { - $centreonLog->insertLog( - 2, - "UPGRADE : 19.10.2 Unable to set default contact_autologin_key" - ); -} - +//error specific content +$versionOfTheUpgrade = "UPGRADE - 20.04.0-beta.1 : "; -// Move broker xml files to json format +/** + * @internal : Queries needing exception management and rollback if failing + */ try { + $pearDB->beginTransaction(); + /** + * Move broker xml files to json format + */ $result = $pearDB->query( "SELECT config_id, config_filename FROM cfg_centreonbroker" @@ -48,21 +45,22 @@ $configFilenames = []; while ($row = $result->fetch()) { $fileName = str_replace('.xml', '.json', $row['config_filename']); + + // saving data for next engine module modifications $configFilenames[$row['config_filename']] = $fileName; + $statement->bindValue(':value', $fileName, \PDO::PARAM_STR); $statement->bindValue(':id', $row['config_id'], \PDO::PARAM_INT); - $statement->execute(); + if (false === $statement->execute()) { + throw new \PDOException( + $versionOfTheUpgrade . "Unable to move broker configuration from xml format to json format" + ); + }; } -} catch (\PDOException $e) { - $centreonLog->insertLog( - 2, - "UPGRADE : 20.04.0-beta.1 Unable to move broker configuration from xml format to json format" - ); - throw new \PDOException($e); -} -// Move engine module xml files to json format -try { + /** + * Move engine module xml files to json format + */ $result = $pearDB->query( "SELECT bk_mod_id, broker_module FROM cfg_nagios_broker_module" @@ -80,47 +78,79 @@ } $statement->bindValue(':value', $fileName, \PDO::PARAM_STR); $statement->bindValue(':id', $row['bk_mod_id'], \PDO::PARAM_INT); - $statement->execute(); + if (false === $statement->execute()) { + throw new \PDOException( + $versionOfTheUpgrade . "Unable to move engine's broker modules configuration from xml to json format" + ); + }; } -} catch (\PDOException $e) { - $centreonLog->insertLog( - 2, - "UPGRADE : 20.04.0-beta.1 Unable to move engine's broker modules configuration from xml to json format" - ); - throw new \PDOException($e); -} + /** + * Change broker sql output form + */ + // set common error message on failure + $errorMessage = $versionOfTheUpgrade . + "Unable to move engine's broker modules configuration from xml to json format"; -// Change broker sql output form - -try { // reorganise existing input form - $pearDB->query( - "UPDATE cb_type_field_relation AS A INNER JOIN cb_type_field_relation AS B ON A.cb_type_id = B.cb_type_id + $query = "UPDATE cb_type_field_relation AS A INNER JOIN cb_type_field_relation AS B ON A.cb_type_id = B.cb_type_id SET A.`order_display` = 8 - WHERE B.`cb_field_id` = (SELECT f.cb_field_id FROM cb_field f WHERE f.fieldname = 'buffering_timeout')" - ); + WHERE B.`cb_field_id` = (SELECT f.cb_field_id FROM cb_field f WHERE f.fieldname = 'buffering_timeout')"; + if ($pearDB->query($query) === false) { + throw new \PDOException( + $errorMessage . " - While trying to update 'cb_type_field_relation' table data"); + } // add new connections_count input - $pearDB->query( - "INSERT INTO `cb_field` (`fieldname`, `displayname`, `description`, `fieldtype`, `external`) - VALUES ('connections_count', 'Number of connection to the database', 'Usually cpus/2', 'int', NULL)" - ); + $query = "INSERT INTO `cb_field` (`fieldname`, `displayname`, `description`, `fieldtype`, `external`) + VALUES ('connections_count', 'Number of connection to the database', 'Usually cpus/2', 'int', NULL)"; + if ($pearDB->query($query) === false) { + throw new \PDOException( + $errorMessage . " - While trying to insert in 'cb_field' table new values" + ); + } // add relation - $pearDB->query( - "INSERT INTO `cb_type_field_relation` (`cb_type_id`, `cb_field_id`, `is_required`, `order_display`, `jshook_name`, `jshook_arguments`) + $query = "INSERT INTO `cb_type_field_relation` ( + `cb_type_id`, + `cb_field_id`, + `is_required`, + `order_display`, + `jshook_name`, + `jshook_arguments` + ) VALUES ( (SELECT `cb_type_id` FROM `cb_type` WHERE `type_shortname` = 'sql'), (SELECT `cb_field_id` FROM `cb_field` WHERE `fieldname` = 'connections_count'), - 0, 7, 'countConnections', '{\"target\": \"connections_count\"}' - )" - ); + 0, + 7, + 'countConnections', + '{\"target\": \"connections_count\"}' + )"; + if ($pearDB->query($query) === false) { + throw new \PDOException( + $errorMessage . " - While trying to insert in 'cb_type_field_relation' table new values" + ); + } + $pearDB->commit(); } catch (\PDOException $e) { - $centreonLog->insertLog( - 2, - "UPGRADE : 20.04.0-beta.1 Unable to change sql broker form" - ); - throw new \PDOException($e); + $pearDB->rollBack(); + $centreonLog->insertLog(2, $e->getMessage() . '. Code : ' . $e->getCode()); + throw $e; +} finally { + /** + * @internal : Queries which doesn't need rollback and won't throw an exception + */ + + /** + * replace autologin keys using NULL instead of empty string + */ + $query = "UPDATE `contact` SET `contact_autologin_key` = NULL WHERE `contact_autologin_key` =''"; + if (false === $pearDB($query)) { + $centreonLog->insertLog( + 2, + $versionOfTheUpgrade . "Unable to set default contact_autologin_key. No error was thrown." + ); + } } From f2690fe2a25edbdcd92755aa74a9b2349ca7fbc9 Mon Sep 17 00:00:00 2001 From: schapron Date: Fri, 3 Jan 2020 13:29:24 +0100 Subject: [PATCH 02/18] enh: remove exception code thrown --- www/install/php/Update-20.04.0-beta.1.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index 7d05b97422d..b16c6701d96 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -96,7 +96,7 @@ $query = "UPDATE cb_type_field_relation AS A INNER JOIN cb_type_field_relation AS B ON A.cb_type_id = B.cb_type_id SET A.`order_display` = 8 WHERE B.`cb_field_id` = (SELECT f.cb_field_id FROM cb_field f WHERE f.fieldname = 'buffering_timeout')"; - if ($pearDB->query($query) === false) { + if (false === $pearDB->query($query)) { throw new \PDOException( $errorMessage . " - While trying to update 'cb_type_field_relation' table data"); } @@ -104,7 +104,7 @@ // add new connections_count input $query = "INSERT INTO `cb_field` (`fieldname`, `displayname`, `description`, `fieldtype`, `external`) VALUES ('connections_count', 'Number of connection to the database', 'Usually cpus/2', 'int', NULL)"; - if ($pearDB->query($query) === false) { + if (false === $pearDB->query($query)) { throw new \PDOException( $errorMessage . " - While trying to insert in 'cb_field' table new values" ); @@ -127,7 +127,7 @@ 'countConnections', '{\"target\": \"connections_count\"}' )"; - if ($pearDB->query($query) === false) { + if (false === $pearDB->query($query)) { throw new \PDOException( $errorMessage . " - While trying to insert in 'cb_type_field_relation' table new values" ); @@ -136,7 +136,7 @@ $pearDB->commit(); } catch (\PDOException $e) { $pearDB->rollBack(); - $centreonLog->insertLog(2, $e->getMessage() . '. Code : ' . $e->getCode()); + $centreonLog->insertLog(2, $e->getMessage()); throw $e; } finally { /** From 18b3df6f6de9928fd6f6f7b46085a8d05ab9a46f Mon Sep 17 00:00:00 2001 From: schapron Date: Fri, 3 Jan 2020 16:31:15 +0100 Subject: [PATCH 03/18] enh: replace thrown object with error message --- www/install/php/Update-20.04.0-beta.1.php | 44 ++++++++--------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index b16c6701d96..9d3ef25d2a8 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -21,7 +21,8 @@ $centreonLog = new CentreonLog(); //error specific content -$versionOfTheUpgrade = "UPGRADE - 20.04.0-beta.1 : "; +$versionOfTheUpgrade = 'UPGRADE - 20.04.0-beta.1 : '; +$errorMessage = ''; /** * @internal : Queries needing exception management and rollback if failing @@ -51,11 +52,8 @@ $statement->bindValue(':value', $fileName, \PDO::PARAM_STR); $statement->bindValue(':id', $row['config_id'], \PDO::PARAM_INT); - if (false === $statement->execute()) { - throw new \PDOException( - $versionOfTheUpgrade . "Unable to move broker configuration from xml format to json format" - ); - }; + // saving error message to be thrown in case of failure + $errorMessage = $versionOfTheUpgrade . "Unable to move broker configuration from xml format to json format"; } /** @@ -63,7 +61,7 @@ */ $result = $pearDB->query( "SELECT bk_mod_id, broker_module - FROM cfg_nagios_broker_module" + FROM cfg_nagios_broker_module5" ); $statement = $pearDB->prepare( @@ -78,11 +76,8 @@ } $statement->bindValue(':value', $fileName, \PDO::PARAM_STR); $statement->bindValue(':id', $row['bk_mod_id'], \PDO::PARAM_INT); - if (false === $statement->execute()) { - throw new \PDOException( - $versionOfTheUpgrade . "Unable to move engine's broker modules configuration from xml to json format" - ); - }; + $errorMessage = $versionOfTheUpgrade . + "Unable to move engine's broker modules configuration from xml to json format"; } /** @@ -96,19 +91,12 @@ $query = "UPDATE cb_type_field_relation AS A INNER JOIN cb_type_field_relation AS B ON A.cb_type_id = B.cb_type_id SET A.`order_display` = 8 WHERE B.`cb_field_id` = (SELECT f.cb_field_id FROM cb_field f WHERE f.fieldname = 'buffering_timeout')"; - if (false === $pearDB->query($query)) { - throw new \PDOException( - $errorMessage . " - While trying to update 'cb_type_field_relation' table data"); - } + $errorMessage = $versionOfTheUpgrade . " - While trying to update 'cb_type_field_relation' table data"; // add new connections_count input $query = "INSERT INTO `cb_field` (`fieldname`, `displayname`, `description`, `fieldtype`, `external`) VALUES ('connections_count', 'Number of connection to the database', 'Usually cpus/2', 'int', NULL)"; - if (false === $pearDB->query($query)) { - throw new \PDOException( - $errorMessage . " - While trying to insert in 'cb_field' table new values" - ); - } + $errorMessage = $versionOfTheUpgrade . " - While trying to insert in 'cb_field' table new values"; // add relation $query = "INSERT INTO `cb_type_field_relation` ( @@ -127,17 +115,15 @@ 'countConnections', '{\"target\": \"connections_count\"}' )"; - if (false === $pearDB->query($query)) { - throw new \PDOException( - $errorMessage . " - While trying to insert in 'cb_type_field_relation' table new values" - ); - } + $errorMessage = $versionOfTheUpgrade . " - While trying to insert in 'cb_type_field_relation' table new values"; $pearDB->commit(); + $centreonLog->insertLog(4, $versionOfTheUpgrade . "Successful update"); } catch (\PDOException $e) { $pearDB->rollBack(); - $centreonLog->insertLog(2, $e->getMessage()); - throw $e; + $msg = $errorMessage . " - Error : " . $e->getMessage(); + $centreonLog->insertLog(4, $msg); + throw new \Exception ($msg); } finally { /** * @internal : Queries which doesn't need rollback and won't throw an exception @@ -147,7 +133,7 @@ * replace autologin keys using NULL instead of empty string */ $query = "UPDATE `contact` SET `contact_autologin_key` = NULL WHERE `contact_autologin_key` =''"; - if (false === $pearDB($query)) { + if (false === $pearDB->query($query)) { $centreonLog->insertLog( 2, $versionOfTheUpgrade . "Unable to set default contact_autologin_key. No error was thrown." From b555dc267a96648d86c003d46395e0341a20ba0d Mon Sep 17 00:00:00 2001 From: schapron Date: Fri, 3 Jan 2020 16:31:37 +0100 Subject: [PATCH 04/18] enh: add a specific log file for the update --- www/class/centreonLog.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/www/class/centreonLog.class.php b/www/class/centreonLog.class.php index fd208185007..31076c9d80c 100644 --- a/www/class/centreonLog.class.php +++ b/www/class/centreonLog.class.php @@ -72,6 +72,7 @@ public function __construct($uid, $pearDB) $this->errorType[1] = $this->path . "/login.log"; $this->errorType[2] = $this->path . "/sql-error.log"; $this->errorType[3] = $this->path . "/ldap.log"; + $this->errorType[4] = $this->path . "/upgrade.log"; } /* @@ -146,6 +147,7 @@ public function __construct($customLogs = array()) $this->errorType[1] = $this->path . "/login.log"; $this->errorType[2] = $this->path . "/sql-error.log"; $this->errorType[3] = $this->path . "/ldap.log"; + $this->errorType[4] = $this->path . "/upgrade.log"; foreach ($customLogs as $key => $value) { if (!preg_match('@' . $this->path . '@', $value)) { From be0954bd358a286eda318c59830100fbfcb97b1a Mon Sep 17 00:00:00 2001 From: sc979 <34628915+sc979@users.noreply.github.com> Date: Fri, 3 Jan 2020 16:43:34 +0100 Subject: [PATCH 05/18] replace PDOException with parent Co-Authored-By: Laurent Calvet --- www/install/php/Update-20.04.0-beta.1.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index 9d3ef25d2a8..7b20b0e600b 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -119,7 +119,7 @@ $pearDB->commit(); $centreonLog->insertLog(4, $versionOfTheUpgrade . "Successful update"); -} catch (\PDOException $e) { +} catch (\Exception $e) { $pearDB->rollBack(); $msg = $errorMessage . " - Error : " . $e->getMessage(); $centreonLog->insertLog(4, $msg); From 32018770e8cd9b87ab6deb5711d08151b6828e3d Mon Sep 17 00:00:00 2001 From: schapron Date: Fri, 3 Jan 2020 16:50:20 +0100 Subject: [PATCH 06/18] remove erro message duplication --- www/install/php/Update-20.04.0-beta.1.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index 7b20b0e600b..cf086f2a47b 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -53,7 +53,7 @@ $statement->bindValue(':value', $fileName, \PDO::PARAM_STR); $statement->bindValue(':id', $row['config_id'], \PDO::PARAM_INT); // saving error message to be thrown in case of failure - $errorMessage = $versionOfTheUpgrade . "Unable to move broker configuration from xml format to json format"; + $errorMessage = "Unable to move broker configuration from xml format to json format"; } /** @@ -76,27 +76,25 @@ } $statement->bindValue(':value', $fileName, \PDO::PARAM_STR); $statement->bindValue(':id', $row['bk_mod_id'], \PDO::PARAM_INT); - $errorMessage = $versionOfTheUpgrade . - "Unable to move engine's broker modules configuration from xml to json format"; + $errorMessage = "Unable to move engine's broker modules configuration from xml to json format"; } /** * Change broker sql output form */ // set common error message on failure - $errorMessage = $versionOfTheUpgrade . - "Unable to move engine's broker modules configuration from xml to json format"; + $partialErrorMessage = "Unable to move engine's broker modules configuration from xml to json format"; // reorganise existing input form $query = "UPDATE cb_type_field_relation AS A INNER JOIN cb_type_field_relation AS B ON A.cb_type_id = B.cb_type_id SET A.`order_display` = 8 WHERE B.`cb_field_id` = (SELECT f.cb_field_id FROM cb_field f WHERE f.fieldname = 'buffering_timeout')"; - $errorMessage = $versionOfTheUpgrade . " - While trying to update 'cb_type_field_relation' table data"; + $errorMessage = $partialErrorMessage . " - While trying to update 'cb_type_field_relation' table data"; // add new connections_count input $query = "INSERT INTO `cb_field` (`fieldname`, `displayname`, `description`, `fieldtype`, `external`) VALUES ('connections_count', 'Number of connection to the database', 'Usually cpus/2', 'int', NULL)"; - $errorMessage = $versionOfTheUpgrade . " - While trying to insert in 'cb_field' table new values"; + $errorMessage = $partialErrorMessage . " - While trying to insert in 'cb_field' table new values"; // add relation $query = "INSERT INTO `cb_type_field_relation` ( @@ -115,13 +113,13 @@ 'countConnections', '{\"target\": \"connections_count\"}' )"; - $errorMessage = $versionOfTheUpgrade . " - While trying to insert in 'cb_type_field_relation' table new values"; + $errorMessage = $partialErrorMessage . " - While trying to insert in 'cb_type_field_relation' table new values"; $pearDB->commit(); $centreonLog->insertLog(4, $versionOfTheUpgrade . "Successful update"); } catch (\Exception $e) { $pearDB->rollBack(); - $msg = $errorMessage . " - Error : " . $e->getMessage(); + $msg = $versionOfTheUpgrade . $errorMessage . " - Error : " . $e->getMessage(); $centreonLog->insertLog(4, $msg); throw new \Exception ($msg); } finally { From 0608c76eaf3106ec1fa7834554377bb2b1e72501 Mon Sep 17 00:00:00 2001 From: schapron Date: Fri, 3 Jan 2020 16:53:42 +0100 Subject: [PATCH 07/18] restore queries --- www/install/php/Update-20.04.0-beta.1.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index cf086f2a47b..c544547eaea 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -61,7 +61,7 @@ */ $result = $pearDB->query( "SELECT bk_mod_id, broker_module - FROM cfg_nagios_broker_module5" + FROM cfg_nagios_broker_module" ); $statement = $pearDB->prepare( @@ -76,6 +76,7 @@ } $statement->bindValue(':value', $fileName, \PDO::PARAM_STR); $statement->bindValue(':id', $row['bk_mod_id'], \PDO::PARAM_INT); + $statement->execute(); $errorMessage = "Unable to move engine's broker modules configuration from xml to json format"; } @@ -86,18 +87,23 @@ $partialErrorMessage = "Unable to move engine's broker modules configuration from xml to json format"; // reorganise existing input form - $query = "UPDATE cb_type_field_relation AS A INNER JOIN cb_type_field_relation AS B ON A.cb_type_id = B.cb_type_id + $pearDB->query( + "UPDATE cb_type_field_relation AS A INNER JOIN cb_type_field_relation AS B ON A.cb_type_id = B.cb_type_id SET A.`order_display` = 8 - WHERE B.`cb_field_id` = (SELECT f.cb_field_id FROM cb_field f WHERE f.fieldname = 'buffering_timeout')"; + WHERE B.`cb_field_id` = (SELECT f.cb_field_id FROM cb_field f WHERE f.fieldname = 'buffering_timeout')" + ); $errorMessage = $partialErrorMessage . " - While trying to update 'cb_type_field_relation' table data"; // add new connections_count input - $query = "INSERT INTO `cb_field` (`fieldname`, `displayname`, `description`, `fieldtype`, `external`) - VALUES ('connections_count', 'Number of connection to the database', 'Usually cpus/2', 'int', NULL)"; + $pearDB->query( + "INSERT INTO `cb_field` (`fieldname`, `displayname`, `description`, `fieldtype`, `external`) + VALUES ('connections_count', 'Number of connection to the database', 'Usually cpus/2', 'int', NULL)" + ); $errorMessage = $partialErrorMessage . " - While trying to insert in 'cb_field' table new values"; // add relation - $query = "INSERT INTO `cb_type_field_relation` ( + $pearDB->query( + "INSERT INTO `cb_type_field_relation` ( `cb_type_id`, `cb_field_id`, `is_required`, @@ -112,7 +118,8 @@ 7, 'countConnections', '{\"target\": \"connections_count\"}' - )"; + )" + ); $errorMessage = $partialErrorMessage . " - While trying to insert in 'cb_type_field_relation' table new values"; $pearDB->commit(); From f261493a7fbcd2bed9cc112ac32ac36150aafe4c Mon Sep 17 00:00:00 2001 From: schapron Date: Fri, 3 Jan 2020 16:55:01 +0100 Subject: [PATCH 08/18] restore queries --- www/install/php/Update-20.04.0-beta.1.php | 1 + 1 file changed, 1 insertion(+) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index c544547eaea..6323bc89519 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -52,6 +52,7 @@ $statement->bindValue(':value', $fileName, \PDO::PARAM_STR); $statement->bindValue(':id', $row['config_id'], \PDO::PARAM_INT); + $statement->execute(); // saving error message to be thrown in case of failure $errorMessage = "Unable to move broker configuration from xml format to json format"; } From b5f9a4a2e32f6904407a39b9e6d94d9609bace42 Mon Sep 17 00:00:00 2001 From: schapron Date: Fri, 3 Jan 2020 17:17:18 +0100 Subject: [PATCH 09/18] typo correction --- www/install/php/Update-20.04.0-beta.1.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index 6323bc89519..59320714ebb 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -132,7 +132,7 @@ throw new \Exception ($msg); } finally { /** - * @internal : Queries which doesn't need rollback and won't throw an exception + * @internal : Queries which don't need rollback and won't throw an exception */ /** From ec1d3acae660d7bf4df1bbb445a7e92cfb6b6677 Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Mon, 6 Jan 2020 10:51:45 +0100 Subject: [PATCH 10/18] Update www/install/php/Update-20.04.0-beta.1.php --- www/install/php/Update-20.04.0-beta.1.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index 59320714ebb..fd487d0ab91 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -29,7 +29,7 @@ */ try { $pearDB->beginTransaction(); - /** + /* * Move broker xml files to json format */ $result = $pearDB->query( From f01c837ae9e0303ec60d48b097d03114699f5e1d Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Mon, 6 Jan 2020 10:51:52 +0100 Subject: [PATCH 11/18] Update www/install/php/Update-20.04.0-beta.1.php --- www/install/php/Update-20.04.0-beta.1.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index fd487d0ab91..4f9254f52f6 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -57,7 +57,7 @@ $errorMessage = "Unable to move broker configuration from xml format to json format"; } - /** + /* * Move engine module xml files to json format */ $result = $pearDB->query( From c4c57fb0d158d42c6b6de05b805af6ea7e34de92 Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Mon, 6 Jan 2020 10:51:59 +0100 Subject: [PATCH 12/18] Update www/install/php/Update-20.04.0-beta.1.php --- www/install/php/Update-20.04.0-beta.1.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index 4f9254f52f6..70f36c34de5 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -81,7 +81,7 @@ $errorMessage = "Unable to move engine's broker modules configuration from xml to json format"; } - /** + /* * Change broker sql output form */ // set common error message on failure From 7112c352a9c2fcee487c380d27e4a36e3e9c27df Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Mon, 6 Jan 2020 10:52:07 +0100 Subject: [PATCH 13/18] Update www/install/php/Update-20.04.0-beta.1.php --- www/install/php/Update-20.04.0-beta.1.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index 70f36c34de5..6d2de580061 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -131,7 +131,7 @@ $centreonLog->insertLog(4, $msg); throw new \Exception ($msg); } finally { - /** + /* * @internal : Queries which don't need rollback and won't throw an exception */ From 73d69fe75c5a1cb18b70cfaf80e57f29bc1b7d5b Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Mon, 6 Jan 2020 10:52:18 +0100 Subject: [PATCH 14/18] Update www/install/php/Update-20.04.0-beta.1.php --- www/install/php/Update-20.04.0-beta.1.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index 6d2de580061..e0eabd0512d 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -135,7 +135,7 @@ * @internal : Queries which don't need rollback and won't throw an exception */ - /** + /* * replace autologin keys using NULL instead of empty string */ $query = "UPDATE `contact` SET `contact_autologin_key` = NULL WHERE `contact_autologin_key` =''"; From 7be71951660c73c20e9f1466ff93aa2a77ac6c5d Mon Sep 17 00:00:00 2001 From: schapron Date: Mon, 6 Jan 2020 11:43:17 +0100 Subject: [PATCH 15/18] fix(msg): move the errorMessage displayed before the thrown exception --- www/install/php/Update-20.04.0-beta.1.php | 61 +++++++++++++++-------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index e0eabd0512d..37211cc85c2 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -32,6 +32,7 @@ /* * Move broker xml files to json format */ + $errorMessage = "Unable to upgrade broker configuration from xml format to json format"; $result = $pearDB->query( "SELECT config_id, config_filename FROM cfg_centreonbroker" @@ -52,14 +53,16 @@ $statement->bindValue(':value', $fileName, \PDO::PARAM_STR); $statement->bindValue(':id', $row['config_id'], \PDO::PARAM_INT); + $statement->execute(); // saving error message to be thrown in case of failure - $errorMessage = "Unable to move broker configuration from xml format to json format"; + } /* * Move engine module xml files to json format */ + $errorMessage = "Unable to upgrade engine's broker modules configuration from xml to json format"; $result = $pearDB->query( "SELECT bk_mod_id, broker_module FROM cfg_nagios_broker_module" @@ -77,32 +80,33 @@ } $statement->bindValue(':value', $fileName, \PDO::PARAM_STR); $statement->bindValue(':id', $row['bk_mod_id'], \PDO::PARAM_INT); + $statement->execute(); - $errorMessage = "Unable to move engine's broker modules configuration from xml to json format"; } /* * Change broker sql output form */ // set common error message on failure - $partialErrorMessage = "Unable to move engine's broker modules configuration from xml to json format"; + $partialErrorMessage = $errorMessage; // reorganise existing input form + $errorMessage = $partialErrorMessage . " - While trying to update 'cb_type_field_relation' table data"; $pearDB->query( "UPDATE cb_type_field_relation AS A INNER JOIN cb_type_field_relation AS B ON A.cb_type_id = B.cb_type_id SET A.`order_display` = 8 WHERE B.`cb_field_id` = (SELECT f.cb_field_id FROM cb_field f WHERE f.fieldname = 'buffering_timeout')" ); - $errorMessage = $partialErrorMessage . " - While trying to update 'cb_type_field_relation' table data"; // add new connections_count input + $errorMessage = $partialErrorMessage . " - While trying to insert in 'cb_field' table new values"; $pearDB->query( "INSERT INTO `cb_field` (`fieldname`, `displayname`, `description`, `fieldtype`, `external`) VALUES ('connections_count', 'Number of connection to the database', 'Usually cpus/2', 'int', NULL)" ); - $errorMessage = $partialErrorMessage . " - While trying to insert in 'cb_field' table new values"; // add relation + $errorMessage = $partialErrorMessage . " - While trying to insert in 'cb_type_field_relation' table new values"; $pearDB->query( "INSERT INTO `cb_type_field_relation` ( `cb_type_id`, @@ -121,28 +125,43 @@ '{\"target\": \"connections_count\"}' )" ); - $errorMessage = $partialErrorMessage . " - While trying to insert in 'cb_type_field_relation' table new values"; $pearDB->commit(); - $centreonLog->insertLog(4, $versionOfTheUpgrade . "Successful update"); + $errorMessage = ""; } catch (\Exception $e) { $pearDB->rollBack(); - $msg = $versionOfTheUpgrade . $errorMessage . " - Error : " . $e->getMessage(); - $centreonLog->insertLog(4, $msg); - throw new \Exception ($msg); -} finally { - /* - * @internal : Queries which don't need rollback and won't throw an exception - */ + $centreonLog->insertLog( + 4, + $versionOfTheUpgrade . $errorMessage . + " - Code : " . (int)$e->getCode() . + " - Error : " . $e->getMessage() . + " - Trace : " . $e->getTraceAsString() + ); + throw new \Exception($versionOfTheUpgrade . $errorMessage, (int)$e->getCode(), $e); +} +/* +* @internal : Queries which don't need rollback and won't throw an exception +*/ +try { /* * replace autologin keys using NULL instead of empty string */ - $query = "UPDATE `contact` SET `contact_autologin_key` = NULL WHERE `contact_autologin_key` =''"; - if (false === $pearDB->query($query)) { - $centreonLog->insertLog( - 2, - $versionOfTheUpgrade . "Unable to set default contact_autologin_key. No error was thrown." - ); - } + $pearDB->query("UPDATE `contact` SET `contact_autologin_key` = NULL WHERE `contact_autologin_key` =''"); +} catch (\Exception $e) { + $errorMessage = "Unable to set default contact_autologin_key."; + $centreonLog->insertLog( + 4, + $versionOfTheUpgrade . $errorMessage . + " - Code : " . (int)$e->getCode() . + " - Error : " . $e->getMessage() . + " - Trace : " . $e->getTraceAsString() + ); +} + +if (empty($errorMessage)) { + $centreonLog->insertLog( + 4, + $versionOfTheUpgrade . " - Successful Update" + ); } From 188cfce71230bfe7a63a92b7ae84f25695187cf8 Mon Sep 17 00:00:00 2001 From: schapron Date: Mon, 6 Jan 2020 14:36:53 +0100 Subject: [PATCH 16/18] enh: displayed warning on step4 --- lang/es_ES.UTF-8/LC_MESSAGES/messages.po | 7 ++++++- lang/pt_BR.UTF-8/LC_MESSAGES/messages.po | 7 ++++++- lang/pt_PT.UTF-8/LC_MESSAGES/messages.po | 7 ++++++- www/install/step_upgrade/step4.php | 11 ++++++++--- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lang/es_ES.UTF-8/LC_MESSAGES/messages.po b/lang/es_ES.UTF-8/LC_MESSAGES/messages.po index 2199a52c9db..c3f79fc1d28 100644 --- a/lang/es_ES.UTF-8/LC_MESSAGES/messages.po +++ b/lang/es_ES.UTF-8/LC_MESSAGES/messages.po @@ -3231,7 +3231,7 @@ msgid "You seem to be having trouble with your upgrade." msgstr "Parece que hay un problema con tu actualización." #: centreon-web/www/install/step_upgrade/step4.php:70 -msgid "You may refer to the line that causes problem in order to find out more about the issue." +msgid "You may refer to the line in the specified file in order to correct the issue." msgstr "Puede consultar la línea que es problemática para obtener más información sobre el incidente." #: centreon-web/www/install/step_upgrade/step4.php:71 @@ -3239,6 +3239,11 @@ msgstr "Puede consultar la línea que es problemática para obtener más informa msgid "The SQL files are located in %s" msgstr "Los archivos SQL se encuentran en %s" +#: centreon-web/www/install/step_upgrade/step4.php:87 +#, php-format +msgid "Please check the \"upgrade.log\" and the \"sql-error.log\" located in \"%s\" for more details" +msgstr "" + #: centreon-web/www/install/step_upgrade/step4.php:72 msgid "But do not edit the SQL files unless you know what you are doing.Refresh this page when the problem is fixed." msgstr "" diff --git a/lang/pt_BR.UTF-8/LC_MESSAGES/messages.po b/lang/pt_BR.UTF-8/LC_MESSAGES/messages.po index 095174f4b45..f7dc43cabcd 100644 --- a/lang/pt_BR.UTF-8/LC_MESSAGES/messages.po +++ b/lang/pt_BR.UTF-8/LC_MESSAGES/messages.po @@ -11996,7 +11996,7 @@ msgid "You seem to be having trouble with your upgrade." msgstr "Parece que você esta tendo problemas com sua atualização." #: centreon-web/www/install/step_upgrade/step4.php:70 -msgid "You may refer to the line that causes problem in order to find out more about the issue." +msgid "You may refer to the line in the specified file in order to correct the issue." msgstr "Você deve verificar a linha que esta causando o problema para poder-mos encontrar uma resolução para este caso." #: centreon-web/www/install/step_upgrade/step4.php:71 @@ -12004,6 +12004,11 @@ msgstr "Você deve verificar a linha que esta causando o problema para poder-mo msgid "The SQL files are located in %s" msgstr "Os arquivos SQL estão localizados em %s" +#: centreon-web/www/install/step_upgrade/step4.php:87 +#, php-format +msgid "Please check the \"upgrade.log\" and the \"sql-error.log\" located in \"%s\" for more details" +msgstr "" + #: centreon-web/www/install/step_upgrade/step4.php:72 msgid "But do not edit the SQL files unless you know what you are doing.Refresh this page when the problem is fixed." msgstr "" diff --git a/lang/pt_PT.UTF-8/LC_MESSAGES/messages.po b/lang/pt_PT.UTF-8/LC_MESSAGES/messages.po index 5932b995714..78f3b4b3368 100644 --- a/lang/pt_PT.UTF-8/LC_MESSAGES/messages.po +++ b/lang/pt_PT.UTF-8/LC_MESSAGES/messages.po @@ -11997,7 +11997,7 @@ msgid "You seem to be having trouble with your upgrade." msgstr "Parece que você esta tendo problemas com sua atualização." #: centreon-web/www/install/step_upgrade/step4.php:70 -msgid "You may refer to the line that causes problem in order to find out more about the issue." +msgid "You may refer to the line in the specified file in order to correct the issue." msgstr "Você deve verificar a linha que esta causando o problema para poder-mos encontrar uma resolução para este caso." #: centreon-web/www/install/step_upgrade/step4.php:71 @@ -12005,6 +12005,11 @@ msgstr "Você deve verificar a linha que esta causando o problema para poder-mo msgid "The SQL files are located in %s" msgstr "Os ficheiros SQL estão localizados em %s" +#: centreon-web/www/install/step_upgrade/step4.php:87 +#, php-format +msgid "Please check the \"upgrade.log\" and the \"sql-error.log\" located in \"%s\" for more details" +msgstr "" + #: centreon-web/www/install/step_upgrade/step4.php:72 msgid "But do not edit the SQL files unless you know what you are doing.Refresh this page when the problem is fixed." msgstr "" diff --git a/www/install/step_upgrade/step4.php b/www/install/step_upgrade/step4.php index 1719faea9c2..a4de38aa45b 100644 --- a/www/install/step_upgrade/step4.php +++ b/www/install/step_upgrade/step4.php @@ -83,13 +83,18 @@ "; $troubleshootTxt1 = _('You seem to be having trouble with your upgrade.'); - $troubleshootTxt2 = _('You may refer to the line that causes problem in order to find out more about the issue.'); - $troubleshootTxt3 = sprintf(_('The SQL files are located in %s'), _CENTREON_PATH_ . 'www/install/sql/'); + $troubleshootTxt1bis = sprintf( + _("Please check the \"upgrade.log\" and the \"sql-error.log\" located in \"%s\" for more details"), + _CENTREON_LOG_ + ); + $troubleshootTxt2 = _('You may refer to the line in the specified file in order to correct the issue.'); + $troubleshootTxt3 = sprintf(_('The SQL files are located in "%s"'), _CENTREON_PATH_ . 'www/install/sql/'); $troubleshootTxt4 = _('But do not edit the SQL files unless you know what you are doing.' . 'Refresh this page when the problem is fixed.'); $contents .= sprintf( - '
', + '
', $troubleshootTxt1, + $troubleshootTxt1bis, $troubleshootTxt2, $troubleshootTxt3, $troubleshootTxt4 From b61d7637c96d5b3848e04d9498404f280844298e Mon Sep 17 00:00:00 2001 From: schapron Date: Tue, 7 Jan 2020 09:18:16 +0100 Subject: [PATCH 17/18] enh: improve comments --- www/install/php/Update-20.04.0-beta.1.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index 37211cc85c2..cbe20bd04d7 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -25,14 +25,14 @@ $errorMessage = ''; /** - * @internal : Queries needing exception management and rollback if failing + * Queries needing exception management and rollback if failing */ try { $pearDB->beginTransaction(); /* * Move broker xml files to json format */ - $errorMessage = "Unable to upgrade broker configuration from xml format to json format"; + $errorMessage = "Unable to replace broker configuration from xml format to json format"; $result = $pearDB->query( "SELECT config_id, config_filename FROM cfg_centreonbroker" @@ -55,14 +55,12 @@ $statement->bindValue(':id', $row['config_id'], \PDO::PARAM_INT); $statement->execute(); - // saving error message to be thrown in case of failure - } /* * Move engine module xml files to json format */ - $errorMessage = "Unable to upgrade engine's broker modules configuration from xml to json format"; + $errorMessage = "Unable to replace engine's broker modules configuration from xml to json format"; $result = $pearDB->query( "SELECT bk_mod_id, broker_module FROM cfg_nagios_broker_module" @@ -140,9 +138,9 @@ throw new \Exception($versionOfTheUpgrade . $errorMessage, (int)$e->getCode(), $e); } -/* -* @internal : Queries which don't need rollback and won't throw an exception -*/ +/** + * Queries which don't need rollback and won't throw an exception + */ try { /* * replace autologin keys using NULL instead of empty string From 2835faf7a7fdab009eaa5524df2cc7d46fa1bb60 Mon Sep 17 00:00:00 2001 From: sc979 <34628915+sc979@users.noreply.github.com> Date: Tue, 7 Jan 2020 09:24:45 +0100 Subject: [PATCH 18/18] Update www/install/php/Update-20.04.0-beta.1.php --- www/install/php/Update-20.04.0-beta.1.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/install/php/Update-20.04.0-beta.1.php b/www/install/php/Update-20.04.0-beta.1.php index cbe20bd04d7..978ecc3e6c6 100644 --- a/www/install/php/Update-20.04.0-beta.1.php +++ b/www/install/php/Update-20.04.0-beta.1.php @@ -145,7 +145,7 @@ /* * replace autologin keys using NULL instead of empty string */ - $pearDB->query("UPDATE `contact` SET `contact_autologin_key` = NULL WHERE `contact_autologin_key` =''"); + $pearDB->query("UPDATE `contact` SET `contact_autologin_key` = NULL WHERE `contact_autologin_key` = ''"); } catch (\Exception $e) { $errorMessage = "Unable to set default contact_autologin_key."; $centreonLog->insertLog(