Commit 56a7ec76 by Alexander Makarov

Passed transaction as callback argument for Connection::transaction() method

parent a0051820
......@@ -461,7 +461,7 @@ class Connection extends Component
/**
* Executes callback provided in a transaction.
*
* @param \Closure $callback
* @param \Closure $callback a callback that performs the job. Accepts transaction instance as parameter.
* @param string|null $isolationLevel The isolation level to use for this transaction.
* See [[Transaction::begin()]] for details.
* @throws \Exception
......@@ -472,7 +472,7 @@ class Connection extends Component
$transaction = $this->beginTransaction($isolationLevel);
try {
$result = $callback();
$result = $callback($transaction);
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollBack();
......
......@@ -155,8 +155,8 @@ class ConnectionTest extends DatabaseTestCase
{
$connection = $this->getConnection(true);
$result = $connection->transaction(function () use ($connection) {
$connection->createCommand()->insert('profile', ['description' => 'test transaction shortcut'])->execute();
$result = $connection->transaction(function (Transaction $transaction) {
$transaction->db->createCommand()->insert('profile', ['description' => 'test transaction shortcut'])->execute();
return true;
}, Transaction::READ_UNCOMMITTED);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment