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

Commit

Permalink
fix(upgrade): avoid transaction when autocommit is done (#10256)
Browse files Browse the repository at this point in the history
Refs: MON-10926
  • Loading branch information
kduret authored Oct 7, 2021
1 parent 8accfb2 commit eb7bc99
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 52 deletions.
2 changes: 0 additions & 2 deletions www/install/php/Update-20.10.8.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
//error specific content
$versionOfTheUpgrade = 'UPGRADE - 20.10.8 : ';

$pearDB = new CentreonDB('centreon', 3, false);

/**
* Query with transaction
*/
Expand Down
2 changes: 0 additions & 2 deletions www/install/php/Update-21.04.0-beta.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
//error specific content
$versionOfTheUpgrade = 'UPGRADE - 21.04.0-beta.1: ';

$pearDB = new CentreonDB('centreon', 3, false);

$criteriasConcordanceArray = [
'states' => [
'acknowledged' => 'Acknowledged',
Expand Down
10 changes: 2 additions & 8 deletions www/install/php/Update-21.04.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
//error specific content
$versionOfTheUpgrade = 'UPGRADE - 21.04.1: ';

$pearDB = new CentreonDB('centreon', 3, false);

/**
* Query with transaction
*/
Expand Down Expand Up @@ -73,13 +71,9 @@
$statement->execute();
}

if ($pearDB->inTransaction()) {
$pearDB->commit();
}
$pearDB->commit();
} catch (\Exception $e) {
if ($pearDB->inTransaction()) {
$pearDB->rollBack();
}
$pearDB->rollBack();
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage .
Expand Down
10 changes: 2 additions & 8 deletions www/install/php/Update-21.04.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
//error specific content
$versionOfTheUpgrade = 'UPGRADE - 21.04.2: ';

$pearDB = new CentreonDB('centreon', 3, false);

/**
* Query with transaction
*/
Expand Down Expand Up @@ -57,13 +55,9 @@
$statement->execute();
}

if ($pearDB->inTransaction()) {
$pearDB->commit();
}
$pearDB->commit();
} catch (\Exception $e) {
if ($pearDB->inTransaction()) {
$pearDB->rollBack();
}
$pearDB->rollBack();
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage .
Expand Down
11 changes: 0 additions & 11 deletions www/install/php/Update-21.04.5.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,17 @@
//error specific content
$versionOfTheUpgrade = 'UPGRADE - 21.04.5:';

$pearDB = new CentreonDB('centreon', 3, false);

/**
* Query with transaction
*/
try {
$pearDB->beginTransaction();

$errorMessage = 'Impossible to alter the table contact';
if (!$pearDB->isColumnExist('contact', 'contact_platform_data_sending')) {
$pearDB->query(
"ALTER TABLE `contact` ADD COLUMN `contact_platform_data_sending` ENUM('0', '1', '2')"
);
}

if ($pearDB->inTransaction()) {
$pearDB->commit();
}
} catch (\Exception $e) {
if ($pearDB->inTransaction()) {
$pearDB->rollBack();
}
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage .
Expand Down
10 changes: 5 additions & 5 deletions www/install/php/Update-21.04.6.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
//error specific content
$versionOfTheUpgrade = 'UPGRADE - 21.04.6:';

$pearDB = new CentreonDB('centreon', 3, false);

/**
* Query with transaction
*/
Expand All @@ -40,6 +38,8 @@
$errorMessage = 'Impossible to purge the table ws_token';
$pearDB->query("DELETE FROM `ws_token`");

$pearDB->commit();

$constraintStatement = $pearDB->query(
"SELECT COUNT(*) as count FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='session_ibfk_1'"
);
Expand All @@ -55,10 +55,10 @@
if ($pearDB->isColumnExist('contact', 'contact_platform_data_sending')) {
$pearDB->query("ALTER TABLE `contact` DROP COLUMN `contact_platform_data_sending`");
}

$pearDB->commit();
} catch (\Exception $e) {
$pearDB->rollBack();
if ($pearDB->inTransaction()) {
$pearDB->rollBack();
}
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage .
Expand Down
2 changes: 0 additions & 2 deletions www/install/php/Update-21.04.7.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
//error specific content
$versionOfTheUpgrade = 'UPGRADE - 21.04.7: ';

$pearDB = new CentreonDB('centreon', 3, false);

/**
* Query with transaction
*/
Expand Down
28 changes: 14 additions & 14 deletions www/install/php/Update-21.10.0-beta.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
//error specific content
$versionOfTheUpgrade = 'UPGRADE - 21.10.0-beta.1: ';

$pearDB = new CentreonDB('centreon', 3, false);

/**
* Query with transaction
*/
Expand All @@ -37,17 +35,6 @@
$errorMessage = 'Impossible to purge the table session';
$pearDB->query("DELETE FROM `session`");

$constraintStatement = $pearDB->query(
"SELECT COUNT(*) as count FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='session_ibfk_1'"
);
if (($constraint = $constraintStatement->fetch()) && (int) $constraint['count'] === 0) {
$errorMessage = 'Impossible to add Delete Cascade constraint on the table session';
$pearDB->query(
"ALTER TABLE `session` ADD CONSTRAINT `session_ibfk_1` FOREIGN KEY (`user_id`) " .
"REFERENCES `contact` (`contact_id`) ON DELETE CASCADE"
);
}

// Add TLS hostname in config brocker for input/outputs IPV4
$statement = $pearDB->query("SELECT cb_field_id from cb_field WHERE fieldname = 'tls_hostname'");
if ($statement->fetchColumn() === false) {
Expand All @@ -73,8 +60,21 @@
}

$pearDB->commit();

$constraintStatement = $pearDB->query(
"SELECT COUNT(*) as count FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='session_ibfk_1'"
);
if (($constraint = $constraintStatement->fetch()) && (int) $constraint['count'] === 0) {
$errorMessage = 'Impossible to add Delete Cascade constraint on the table session';
$pearDB->query(
"ALTER TABLE `session` ADD CONSTRAINT `session_ibfk_1` FOREIGN KEY (`user_id`) " .
"REFERENCES `contact` (`contact_id`) ON DELETE CASCADE"
);
}
} catch (\Exception $e) {
$pearDB->rollBack();
if ($pearDB->inTransaction()) {
$pearDB->rollBack();
}
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage .
Expand Down

0 comments on commit eb7bc99

Please sign in to comment.