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 committed Nov 4, 2021
1 parent 40ef8db commit e072480
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 35 deletions.
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 @@ -24,28 +24,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
14 changes: 8 additions & 6 deletions www/install/php/Update-21.04.6.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
//error specific content
$versionOfTheUpgrade = 'UPGRADE - 21.04.6:';

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

/**
* Query with transaction
*/
Expand All @@ -39,6 +37,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 @@ -51,11 +51,13 @@
}

$errorMessage = "Impossible to drop column 'contact_platform_data_sending' from 'contact' table";
$pearDB->query("ALTER TABLE `contact` DROP COLUMN `contact_platform_data_sending`");

$pearDB->commit();
if ($pearDB->isColumnExist('contact', 'contact_platform_data_sending')) {
$pearDB->query("ALTER TABLE `contact` DROP COLUMN `contact_platform_data_sending`");
}
} catch (\Exception $e) {
$pearDB->rollBack();
if ($pearDB->inTransaction()) {
$pearDB->rollBack();
}
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage .
Expand Down

0 comments on commit e072480

Please sign in to comment.