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
83b0b3d4
Commit
83b0b3d4
authored
Nov 29, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #6311: Optimistic lock for ActiveRecord does not work as expected
parent
39fb85ed
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
5 deletions
+5
-5
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
BaseActiveRecord.php
framework/db/BaseActiveRecord.php
+4
-5
No files found.
framework/CHANGELOG.md
View file @
83b0b3d4
...
...
@@ -41,6 +41,7 @@ Yii Framework 2 Change Log
-
Bug #6271: Query caching returns the same data when running the same SQL with different fetch modes (grachov)
-
Bug #6279:
`yii\db\Schema::getLastInsertID()`
was passing wrong default schema name to PDO (samdark)
-
Bug #6305:
`yii\i18n\Formatter::asParagraphs()`
was not unicode-aware (samdark)
-
Bug #6311: Optimistic lock for ActiveRecord does not work as expected (qiangxue)
-
Bug: Gii console command help information does not contain global options (qiangxue)
-
Bug:
`yii\web\UrlRule`
was unable to create URLs for rules containing unicode characters (samdark)
-
Bug:
`yii\web\AssetManager`
should not publish disabled asset bundles (qiangxue)
...
...
framework/db/BaseActiveRecord.php
View file @
83b0b3d4
...
...
@@ -210,9 +210,10 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*
* 1. Create a column to store the version number of each row. The column type should be `BIGINT DEFAULT 0`.
* Override this method to return the name of this column.
* 2. In the Web form that collects the user input, add a hidden field that stores
* 2. Add a `required` validation rule for the version column to ensure the version value is submitted.
* 3. In the Web form that collects the user input, add a hidden field that stores
* the lock version of the recording being updated.
*
3
. In the controller action that does the data updating, try to catch the [[StaleObjectException]]
*
4
. In the controller action that does the data updating, try to catch the [[StaleObjectException]]
* and implement necessary business logic (e.g. merging the changes, prompting stated data)
* to resolve the conflict.
*
...
...
@@ -703,9 +704,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
$condition
=
$this
->
getOldPrimaryKey
(
true
);
$lock
=
$this
->
optimisticLock
();
if
(
$lock
!==
null
)
{
if
(
!
isset
(
$values
[
$lock
]))
{
$values
[
$lock
]
=
$this
->
$lock
+
1
;
}
$values
[
$lock
]
=
$this
->
$lock
+
1
;
$condition
[
$lock
]
=
$this
->
$lock
;
}
// We do not check the return value of updateAll() because it's possible
...
...
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