Commit 608e9012 by Alexander Makarov

Adjusted Connection::transaction to provide Connection instance by default…

Adjusted Connection::transaction to provide Connection instance by default instead of transaction instance
parent b147e651
...@@ -85,8 +85,8 @@ use yii\caching\Cache; ...@@ -85,8 +85,8 @@ use yii\caching\Cache;
* If needed you can pass transaction isolation level as a second parameter: * If needed you can pass transaction isolation level as a second parameter:
* *
* ~~~ * ~~~
* $connection->transaction(function(Transaction $transaction) { * $connection->transaction(function(Connection $db) {
* // $transaction->db->... * //return $db->...
* }, Transaction::READ_UNCOMMITTED); * }, Transaction::READ_UNCOMMITTED);
* ~~~ * ~~~
* *
...@@ -459,7 +459,7 @@ class Connection extends Component ...@@ -459,7 +459,7 @@ class Connection extends Component
/** /**
* Executes callback provided in a transaction. * Executes callback provided in a transaction.
* *
* @param callable $callback a valid PHP callback that performs the job. Accepts transaction instance as parameter. * @param callable $callback a valid PHP callback that performs the job. Accepts connection 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
...@@ -470,7 +470,7 @@ class Connection extends Component ...@@ -470,7 +470,7 @@ class Connection extends Component
$transaction = $this->beginTransaction($isolationLevel); $transaction = $this->beginTransaction($isolationLevel);
try { try {
$result = call_user_func($callback, $transaction); $result = call_user_func($callback, $this);
if ($transaction->isActive) { if ($transaction->isActive) {
$transaction->commit(); $transaction->commit();
} }
......
...@@ -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 (Transaction $transaction) { $result = $connection->transaction(function (Connection $db) {
$transaction->db->createCommand()->insert('profile', ['description' => 'test transaction shortcut'])->execute(); $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