Commit 56a7ec76 by Alexander Makarov

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

parent a0051820
...@@ -461,7 +461,7 @@ class Connection extends Component ...@@ -461,7 +461,7 @@ class Connection extends Component
/** /**
* Executes callback provided in a transaction. * 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. * @param string|null $isolationLevel The isolation level to use for this transaction.
* See [[Transaction::begin()]] for details. * See [[Transaction::begin()]] for details.
* @throws \Exception * @throws \Exception
...@@ -472,7 +472,7 @@ class Connection extends Component ...@@ -472,7 +472,7 @@ class Connection extends Component
$transaction = $this->beginTransaction($isolationLevel); $transaction = $this->beginTransaction($isolationLevel);
try { try {
$result = $callback(); $result = $callback($transaction);
$transaction->commit(); $transaction->commit();
} catch (\Exception $e) { } catch (\Exception $e) {
$transaction->rollBack(); $transaction->rollBack();
......
...@@ -155,8 +155,8 @@ class ConnectionTest extends DatabaseTestCase ...@@ -155,8 +155,8 @@ class ConnectionTest extends DatabaseTestCase
{ {
$connection = $this->getConnection(true); $connection = $this->getConnection(true);
$result = $connection->transaction(function () use ($connection) { $result = $connection->transaction(function (Transaction $transaction) {
$connection->createCommand()->insert('profile', ['description' => 'test transaction shortcut'])->execute(); $transaction->db->createCommand()->insert('profile', ['description' => 'test transaction shortcut'])->execute();
return true; return true;
}, Transaction::READ_UNCOMMITTED); }, 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