
| Current Path : /var/www/html/rocksensor1/web/core/modules/mysql/src/Driver/Database/mysql/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/rocksensor1/web/core/modules/mysql/src/Driver/Database/mysql/TransactionManager.php |
<?php
declare(strict_types=1);
namespace Drupal\mysql\Driver\Database\mysql;
use Drupal\Core\Database\Transaction\ClientConnectionTransactionState;
use Drupal\Core\Database\Transaction\TransactionManagerBase;
/**
* MySql implementation of TransactionManagerInterface.
*
* MySQL will automatically commit transactions when tables are altered or
* created (DDL transactions are not supported). However, pdo_mysql tracks
* whether a client connection is still active and we can prevent triggering
* exceptions.
*/
class TransactionManager extends TransactionManagerBase {
/**
* {@inheritdoc}
*/
protected function beginClientTransaction(): bool {
return $this->connection->getClientConnection()->beginTransaction();
}
/**
* {@inheritdoc}
*/
protected function processRootCommit(): void {
if (!$this->connection->getClientConnection()->inTransaction()) {
$this->voidClientTransaction();
return;
}
parent::processRootCommit();
}
/**
* {@inheritdoc}
*/
protected function rollbackClientSavepoint(string $name): bool {
if (!$this->connection->getClientConnection()->inTransaction()) {
$this->voidClientTransaction();
return TRUE;
}
return parent::rollbackClientSavepoint($name);
}
/**
* {@inheritdoc}
*/
protected function releaseClientSavepoint(string $name): bool {
if (!$this->connection->getClientConnection()->inTransaction()) {
$this->voidClientTransaction();
return TRUE;
}
return parent::releaseClientSavepoint($name);
}
/**
* {@inheritdoc}
*/
protected function commitClientTransaction(): bool {
$clientCommit = $this->connection->getClientConnection()->commit();
$this->setConnectionTransactionState($clientCommit ?
ClientConnectionTransactionState::Committed :
ClientConnectionTransactionState::CommitFailed
);
return $clientCommit;
}
/**
* {@inheritdoc}
*/
protected function rollbackClientTransaction(): bool {
if (!$this->connection->getClientConnection()->inTransaction()) {
$this->voidClientTransaction();
return FALSE;
}
$clientRollback = $this->connection->getClientConnection()->rollBack();
$this->setConnectionTransactionState($clientRollback ?
ClientConnectionTransactionState::RolledBack :
ClientConnectionTransactionState::RollbackFailed
);
return $clientRollback;
}
}