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
4969f51e
Commit
4969f51e
authored
Jun 26, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #3221: Added events for DB transaction commit/rollback
parent
838a79cd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
3 deletions
+20
-3
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Connection.php
framework/db/Connection.php
+12
-0
Transaction.php
framework/db/Transaction.php
+7
-3
No files found.
framework/CHANGELOG.md
View file @
4969f51e
...
...
@@ -81,6 +81,7 @@ Yii Framework 2 Change Log
-
Enh #3154: Added validation error display for
`GridView`
filters (ivan-kolmychek)
-
Enh #3196: Masked input upgraded to use jquery.inputmask plugin with more features. (kartik-v)
-
Enh #3220: Added support for setting transaction isolation levels (cebe)
-
Enh #3221: Added events for DB transaction commit/rollback (drcypher, qiangxue)
-
Enh #3222: Added
`useTablePrefix`
option to the model generator for Gii (horizons2)
-
Enh #3230: Added
`yii\filters\AccessControl::user`
to support access control with different actors (qiangxue)
-
Enh #3232: Added
`export()`
and
`exportAsString()`
methods to
`yii\helpers\BaseVarDumper`
(klimov-paul)
...
...
framework/db/Connection.php
View file @
4969f51e
...
...
@@ -107,6 +107,18 @@ class Connection extends Component
* @event Event an event that is triggered after a DB connection is established
*/
const
EVENT_AFTER_OPEN
=
'afterOpen'
;
/**
* @event Event an event that is triggered right before a top-level transaction is started
*/
const
EVENT_BEGIN_TRANSACTION
=
'beginTransaction'
;
/**
* @event Event an event that is triggered right after a top-level transaction is committed
*/
const
EVENT_COMMIT_TRANSACTION
=
'commitTransaction'
;
/**
* @event Event an event that is triggered right after a top-level transaction is rolled back
*/
const
EVENT_ROLLBACK_TRANSACTION
=
'rollbackTransaction'
;
/**
* @var string the Data Source Name, or DSN, contains the information required to connect to the database.
...
...
framework/db/Transaction.php
View file @
4969f51e
...
...
@@ -113,6 +113,8 @@ class Transaction extends \yii\base\Object
$this
->
db
->
getSchema
()
->
setTransactionIsolationLevel
(
$isolationLevel
);
}
Yii
::
trace
(
'Begin transaction'
.
(
$isolationLevel
?
' with isolation level '
.
$isolationLevel
:
''
),
__METHOD__
);
$this
->
db
->
trigger
(
Connection
::
EVENT_BEGIN_TRANSACTION
);
$this
->
db
->
pdo
->
beginTransaction
();
$this
->
_level
=
1
;
...
...
@@ -143,7 +145,7 @@ class Transaction extends \yii\base\Object
if
(
$this
->
_level
==
0
)
{
Yii
::
trace
(
'Commit transaction'
,
__METHOD__
);
$this
->
db
->
pdo
->
commit
();
$this
->
db
->
trigger
(
Connection
::
EVENT_COMMIT_TRANSACTION
);
return
;
}
...
...
@@ -163,14 +165,16 @@ class Transaction extends \yii\base\Object
public
function
rollBack
()
{
if
(
!
$this
->
getIsActive
())
{
throw
new
Exception
(
'Failed to roll back transaction: transaction was inactive.'
);
// do nothing if transaction is not active: this could be the transaction is committed
// but the event handler to "commitTransaction" throw an exception
return
;
}
$this
->
_level
--
;
if
(
$this
->
_level
==
0
)
{
Yii
::
trace
(
'Roll back transaction'
,
__METHOD__
);
$this
->
db
->
pdo
->
rollBack
();
$this
->
db
->
trigger
(
Connection
::
EVENT_ROLLBACK_TRANSACTION
);
return
;
}
...
...
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