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;
* If needed you can pass transaction isolation level as a second parameter:
*
* ~~~
* $connection->transaction(function(Transaction $transaction) {
* // $transaction->db->...
* $connection->transaction(function(Connection $db) {
* //return $db->...
* }, Transaction::READ_UNCOMMITTED);
* ~~~
*
......@@ -459,7 +459,7 @@ class Connection extends Component
/**
* 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.
* See [[Transaction::begin()]] for details.
* @throws \Exception
......@@ -470,7 +470,7 @@ class Connection extends Component
$transaction = $this->beginTransaction($isolationLevel);
try {
$result = call_user_func($callback, $transaction);
$result = call_user_func($callback, $this);
if ($transaction->isActive) {
$transaction->commit();
}
......
......@@ -155,8 +155,8 @@ class ConnectionTest extends DatabaseTestCase
{
$connection = $this->getConnection(true);
$result = $connection->transaction(function (Transaction $transaction) {
$transaction->db->createCommand()->insert('profile', ['description' => 'test transaction shortcut'])->execute();
$result = $connection->transaction(function (Connection $db) {
$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