I have found the code that uses database transaction (\Magento\SalesRule\Model\ResourceModel\Rule::saveStoreLabels
):
public function saveStoreLabels($ruleId, $labels)
{
...
$connection = $this->getConnection();
...
$connection->beginTransaction();
try {
...
} catch (\Exception $e) {
$connection->rollback();
throw $e;
}
$connection->commit();
return $this;
}
I want to get nested transactions where inner transaction should be processed silently (without exception) and outer transaction should be committed if no error occured (even inner transaction is rolled back):
public function someOtherMethod(...)
{
...
$connection = $this->getConnection();
...
$connection->beginTransaction();
try {
...
/* nested transaction should be committed or rolled back without exception */
$connection->beginTransaction();
try {
...
$connection->commit();
} catch (\Exception $e) {
$connection->rollback();
}
} catch (\Exception $e) {
$connection->rollback();
throw $e;
}
/* outer transaction should be committed if exception was not thrown */
$connection->commit();
return $this;
}
Is it possible?