Handle nested transactions (#90)

* starting a new transaction will send nothing in the DB (only one global transaction : merge nested transactions)
* same for COMMIT or ROLLBACK if more than 1 transaction is opened
* transactions are kept inside \DBObject::DBInsertNoReload, but they can be disabled using config flag db_core_transactions_enabled=false (true by default, hidden by default)
This commit is contained in:
Pierre Goiffon
2019-08-20 10:47:29 +02:00
committed by GitHub
parent 5dd92ab506
commit 51bbe1f79d
5 changed files with 216 additions and 18 deletions

View File

@@ -2700,9 +2700,13 @@ abstract class DBObject implements iDisplay
}
}
$bIsTransactionEnabled = MetaModel::GetConfig()->Get('db_core_transactions_enabled');
try
{
CMDBSource::Query('START TRANSACTION');
if ($bIsTransactionEnabled)
{
CMDBSource::Query('START TRANSACTION');
}
// First query built upon on the root class, because the ID must be created first
$this->m_iKey = $this->DBInsertSingleTable($sRootClass);
@@ -2723,11 +2727,17 @@ abstract class DBObject implements iDisplay
$this->DBInsertSingleTable($sParentClass);
}
CMDBSource::Query('COMMIT');
if ($bIsTransactionEnabled)
{
CMDBSource::Query('COMMIT');
}
}
catch (Exception $e)
{
CMDBSource::Query('ROLLBACK');
if ($bIsTransactionEnabled)
{
CMDBSource::Query('ROLLBACK');
}
throw $e;
}