mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Implementing transaction nesting, this will allow to open multiple transactions that will only be commited if all transactions succesfully calls commit()
This commit is contained in:
parent
f2b707ac0b
commit
1326707c9d
1 changed files with 14 additions and 10 deletions
|
@ -1895,14 +1895,14 @@ class DboSource extends DataSource {
|
|||
/**
|
||||
* Begin a transaction
|
||||
*
|
||||
* @param model $model
|
||||
* @return boolean True on success, false on fail
|
||||
* (i.e. if the database/model does not support transactions,
|
||||
* or a transaction has not started).
|
||||
*/
|
||||
public function begin(&$model) {
|
||||
if (parent::begin($model) && $this->execute($this->_commands['begin'])) {
|
||||
public function begin() {
|
||||
if ($this->_transactionStarted || $this->_connection->beginTransaction()) {
|
||||
$this->_transactionStarted = true;
|
||||
$this->_transactionNesting++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -1911,14 +1911,18 @@ class DboSource extends DataSource {
|
|||
/**
|
||||
* Commit a transaction
|
||||
*
|
||||
* @param model $model
|
||||
* @return boolean True on success, false on fail
|
||||
* (i.e. if the database/model does not support transactions,
|
||||
* or a transaction has not started).
|
||||
*/
|
||||
public function commit(&$model) {
|
||||
if (parent::commit($model) && $this->execute($this->_commands['commit'])) {
|
||||
$this->_transactionStarted = false;
|
||||
public function commit() {
|
||||
if ($this->_transactionStarted) {
|
||||
$this->_transactionNesting--;
|
||||
if ($this->_transactionNesting <= 0) {
|
||||
$this->_transactionStarted = false;
|
||||
$this->_transactionNesting = 0;
|
||||
return $this->_connection->commit();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -1927,14 +1931,14 @@ class DboSource extends DataSource {
|
|||
/**
|
||||
* Rollback a transaction
|
||||
*
|
||||
* @param model $model
|
||||
* @return boolean True on success, false on fail
|
||||
* (i.e. if the database/model does not support transactions,
|
||||
* or a transaction has not started).
|
||||
*/
|
||||
public function rollback(&$model) {
|
||||
if (parent::rollback($model) && $this->execute($this->_commands['rollback'])) {
|
||||
public function rollback() {
|
||||
if ($this->_transactionStarted && $this->_connection->rollBack()) {
|
||||
$this->_transactionStarted = false;
|
||||
$this->_transactionNesting = 0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
Loading…
Add table
Reference in a new issue