Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
56a7ec76
Commit
56a7ec76
authored
Jul 10, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Passed transaction as callback argument for Connection::transaction() method
parent
a0051820
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
4 deletions
+4
-4
Connection.php
framework/db/Connection.php
+2
-2
ConnectionTest.php
tests/unit/framework/db/ConnectionTest.php
+2
-2
No files found.
framework/db/Connection.php
View file @
56a7ec76
...
@@ -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
();
...
...
tests/unit/framework/db/ConnectionTest.php
View file @
56a7ec76
...
@@ -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
(
$conne
ction
)
{
$result
=
$connection
->
transaction
(
function
(
Transaction
$transa
ction
)
{
$
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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment