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
780fdd61
Commit
780fdd61
authored
Dec 31, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #6710
parent
7b52fd5e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
63 deletions
+60
-63
ActiveRecord.php
framework/db/ActiveRecord.php
+60
-63
No files found.
framework/db/ActiveRecord.php
View file @
780fdd61
...
...
@@ -420,25 +420,24 @@ class ActiveRecord extends BaseActiveRecord
Yii
::
info
(
'Model not inserted due to validation error.'
,
__METHOD__
);
return
false
;
}
$db
=
static
::
getDb
();
if
(
$this
->
isTransactional
(
self
::
OP_INSERT
))
{
$transaction
=
$db
->
beginTransaction
();
try
{
$result
=
$this
->
insertInternal
(
$attributes
);
if
(
$result
===
false
)
{
$transaction
->
rollBack
();
}
else
{
$transaction
->
commit
();
}
}
catch
(
\Exception
$e
)
{
if
(
!
$this
->
isTransactional
(
self
::
OP_INSERT
))
{
return
$this
->
insertInternal
(
$attributes
);
}
$transaction
=
static
::
getDb
()
->
beginTransaction
();
try
{
$result
=
$this
->
insertInternal
(
$attributes
);
if
(
$result
===
false
)
{
$transaction
->
rollBack
();
throw
$e
;
}
else
{
$transaction
->
commit
();
}
}
else
{
$result
=
$this
->
insertInternal
(
$attributes
);
return
$result
;
}
catch
(
\Exception
$e
)
{
$transaction
->
rollBack
();
throw
$e
;
}
return
$result
;
}
/**
...
...
@@ -538,25 +537,24 @@ class ActiveRecord extends BaseActiveRecord
Yii
::
info
(
'Model not updated due to validation error.'
,
__METHOD__
);
return
false
;
}
$db
=
static
::
getDb
();
if
(
$this
->
isTransactional
(
self
::
OP_UPDATE
))
{
$transaction
=
$db
->
beginTransaction
();
try
{
$result
=
$this
->
updateInternal
(
$attributeNames
);
if
(
$result
===
false
)
{
$transaction
->
rollBack
();
}
else
{
$transaction
->
commit
();
}
}
catch
(
\Exception
$e
)
{
if
(
!
$this
->
isTransactional
(
self
::
OP_UPDATE
))
{
return
$this
->
updateInternal
(
$attributeNames
);
}
$transaction
=
static
::
getDb
()
->
beginTransaction
();
try
{
$result
=
$this
->
updateInternal
(
$attributeNames
);
if
(
$result
===
false
)
{
$transaction
->
rollBack
();
throw
$e
;
}
else
{
$transaction
->
commit
();
}
}
else
{
$result
=
$this
->
updateInternal
(
$attributeNames
);
return
$result
;
}
catch
(
\Exception
$e
)
{
$transaction
->
rollBack
();
throw
$e
;
}
return
$result
;
}
/**
...
...
@@ -580,25 +578,23 @@ class ActiveRecord extends BaseActiveRecord
*/
public
function
delete
()
{
$db
=
static
::
getDb
();
if
(
$this
->
isTransactional
(
self
::
OP_DELETE
))
{
$transaction
=
$db
->
beginTransaction
();
try
{
$result
=
$this
->
deleteInternal
();
if
(
$result
===
false
)
{
$transaction
->
rollBack
();
}
else
{
$transaction
->
commit
();
}
}
catch
(
\Exception
$e
)
{
if
(
!
$this
->
isTransactional
(
self
::
OP_DELETE
))
{
return
$this
->
deleteInternal
();
}
$transaction
=
static
::
getDb
()
->
beginTransaction
();
try
{
$result
=
$this
->
deleteInternal
();
if
(
$result
===
false
)
{
$transaction
->
rollBack
();
throw
$e
;
}
else
{
$transaction
->
commit
();
}
}
else
{
$result
=
$this
->
deleteInternal
();
return
$result
;
}
catch
(
\Exception
$e
)
{
$transaction
->
rollBack
();
throw
$e
;
}
return
$result
;
}
/**
...
...
@@ -609,22 +605,23 @@ class ActiveRecord extends BaseActiveRecord
*/
protected
function
deleteInternal
()
{
$result
=
false
;
if
(
$this
->
beforeDelete
())
{
// we do not check the return value of deleteAll() because it's possible
// the record is already deleted in the database and thus the method will return 0
$condition
=
$this
->
getOldPrimaryKey
(
true
);
$lock
=
$this
->
optimisticLock
();
if
(
$lock
!==
null
)
{
$condition
[
$lock
]
=
$this
->
$lock
;
}
$result
=
$this
->
deleteAll
(
$condition
);
if
(
$lock
!==
null
&&
!
$result
)
{
throw
new
StaleObjectException
(
'The object being deleted is outdated.'
);
}
$this
->
setOldAttributes
(
null
);
$this
->
afterDelete
();
if
(
!
$this
->
beforeDelete
())
{
return
false
;
}
// we do not check the return value of deleteAll() because it's possible
// the record is already deleted in the database and thus the method will return 0
$condition
=
$this
->
getOldPrimaryKey
(
true
);
$lock
=
$this
->
optimisticLock
();
if
(
$lock
!==
null
)
{
$condition
[
$lock
]
=
$this
->
$lock
;
}
$result
=
$this
->
deleteAll
(
$condition
);
if
(
$lock
!==
null
&&
!
$result
)
{
throw
new
StaleObjectException
(
'The object being deleted is outdated.'
);
}
$this
->
setOldAttributes
(
null
);
$this
->
afterDelete
();
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