Skip to content

Instantly share code, notes, and snippets.

@tlode
Created January 15, 2015 16:40
Show Gist options
  • Save tlode/ba9a41785c40931802f4 to your computer and use it in GitHub Desktop.
Save tlode/ba9a41785c40931802f4 to your computer and use it in GitHub Desktop.
/**
* begin transaction
*/
public function begin()
{
if(count($this->transactionStack) == 0)
{
$this->transactionStack[0] = true;
parent::beginTransaction();
}
else
{
$savePoint = 'savepoint_'. count($this->transactionStack);
array_push($this->transactionStack, $savePoint);
$this->setSavePoint($savePoint);
}
}
/**
* commit
*/
public function commit()
{
if(count($this->transactionStack) > 1)
{
$savePoint = array_pop($this->transactionStack);
$this->releaseSavePoint($savePoint);
}
else
{
$this->transactionStack = array();
parent::commit();
}
}
/**
* rollback
*/
public function rollback()
{
/**
* Take care of nesting transaction blocks
*/
if(count($this->transactionStack) > 1)
{
$savePoint = array_pop($this->transactionStack);
$this->rollbackToSavePoint($savePoint);
}
else
{
$this->transactionStack = array();
parent::rollback();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment