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
ba2c35b8
Commit
ba2c35b8
authored
Feb 23, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #2482.
parent
9f37e133
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
18 deletions
+34
-18
ActiveRecord.php
framework/db/ActiveRecord.php
+34
-18
No files found.
framework/db/ActiveRecord.php
View file @
ba2c35b8
...
@@ -377,7 +377,7 @@ class ActiveRecord extends BaseActiveRecord
...
@@ -377,7 +377,7 @@ class ActiveRecord extends BaseActiveRecord
return
false
;
return
false
;
}
}
$db
=
static
::
getDb
();
$db
=
static
::
getDb
();
if
(
$this
->
isTransactional
(
self
::
OP_INSERT
)
&&
$db
->
getTransaction
()
===
null
)
{
if
(
$this
->
isTransactional
(
self
::
OP_INSERT
))
{
$transaction
=
$db
->
beginTransaction
();
$transaction
=
$db
->
beginTransaction
();
try
{
try
{
$result
=
$this
->
insertInternal
(
$attributes
);
$result
=
$this
->
insertInternal
(
$attributes
);
...
@@ -397,9 +397,12 @@ class ActiveRecord extends BaseActiveRecord
...
@@ -397,9 +397,12 @@ class ActiveRecord extends BaseActiveRecord
}
}
/**
/**
* @see ActiveRecord::insert()
* Inserts an ActiveRecord into DB without considering transaction.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return boolean whether the record is inserted successfully.
*/
*/
pr
ivate
function
insertInternal
(
$attributes
=
null
)
pr
otected
function
insertInternal
(
$attributes
=
null
)
{
{
if
(
!
$this
->
beforeSave
(
true
))
{
if
(
!
$this
->
beforeSave
(
true
))
{
return
false
;
return
false
;
...
@@ -489,7 +492,7 @@ class ActiveRecord extends BaseActiveRecord
...
@@ -489,7 +492,7 @@ class ActiveRecord extends BaseActiveRecord
return
false
;
return
false
;
}
}
$db
=
static
::
getDb
();
$db
=
static
::
getDb
();
if
(
$this
->
isTransactional
(
self
::
OP_UPDATE
)
&&
$db
->
getTransaction
()
===
null
)
{
if
(
$this
->
isTransactional
(
self
::
OP_UPDATE
))
{
$transaction
=
$db
->
beginTransaction
();
$transaction
=
$db
->
beginTransaction
();
try
{
try
{
$result
=
$this
->
updateInternal
(
$attributes
);
$result
=
$this
->
updateInternal
(
$attributes
);
...
@@ -530,8 +533,34 @@ class ActiveRecord extends BaseActiveRecord
...
@@ -530,8 +533,34 @@ class ActiveRecord extends BaseActiveRecord
public
function
delete
()
public
function
delete
()
{
{
$db
=
static
::
getDb
();
$db
=
static
::
getDb
();
$transaction
=
$this
->
isTransactional
(
self
::
OP_DELETE
)
&&
$db
->
getTransaction
()
===
null
?
$db
->
beginTransaction
()
:
null
;
if
(
$this
->
isTransactional
(
self
::
OP_DELETE
))
{
$transaction
=
$db
->
beginTransaction
();
try
{
try
{
$result
=
$this
->
deleteInternal
();
if
(
$result
===
false
)
{
$transaction
->
rollBack
();
}
else
{
$transaction
->
commit
();
}
}
catch
(
\Exception
$e
)
{
$transaction
->
rollBack
();
throw
$e
;
}
}
else
{
$result
=
$this
->
deleteInternal
();
}
return
$result
;
}
/**
* Deletes an ActiveRecord without considering transaction.
* @return integer|boolean the number of rows deleted, or false if the deletion is unsuccessful for some reason.
* Note that it is possible the number of rows deleted is 0, even though the deletion execution is successful.
* @throws StaleObjectException
*/
protected
function
deleteInternal
()
{
$result
=
false
;
$result
=
false
;
if
(
$this
->
beforeDelete
())
{
if
(
$this
->
beforeDelete
())
{
// we do not check the return value of deleteAll() because it's possible
// we do not check the return value of deleteAll() because it's possible
...
@@ -548,19 +577,6 @@ class ActiveRecord extends BaseActiveRecord
...
@@ -548,19 +577,6 @@ class ActiveRecord extends BaseActiveRecord
$this
->
setOldAttributes
(
null
);
$this
->
setOldAttributes
(
null
);
$this
->
afterDelete
();
$this
->
afterDelete
();
}
}
if
(
$transaction
!==
null
)
{
if
(
$result
===
false
)
{
$transaction
->
rollBack
();
}
else
{
$transaction
->
commit
();
}
}
}
catch
(
\Exception
$e
)
{
if
(
$transaction
!==
null
)
{
$transaction
->
rollBack
();
}
throw
$e
;
}
return
$result
;
return
$result
;
}
}
...
...
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