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
2026d382
Commit
2026d382
authored
Apr 01, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow using existing column to store lock version.
parent
c6a13278
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
ActiveRecord.php
framework/db/ActiveRecord.php
+8
-6
No files found.
framework/db/ActiveRecord.php
View file @
2026d382
...
...
@@ -279,16 +279,16 @@ class ActiveRecord extends Model
/**
* Returns the name of the column that stores the lock version for implementing optimistic locking.
*
* Optimistic locking allows multiple users to access the same record for edits
. In case
*
when a user attempts to save the record upon some staled data (because another user
*
has modified the data), a [[StaleObjectException]] exception will be thrown, and
*
the update or deletion is ignor
ed.
* Optimistic locking allows multiple users to access the same record for edits
and avoids
*
potential conflicts. In case when a user attempts to save the record upon some staled data
*
(because another user has modified the data), a [[StaleObjectException]] exception will be thrown,
*
and the update or deletion is skipp
ed.
*
* Optimized locking is only supported by [[update()]] and [[delete()]].
*
* To use optimized locking:
*
* 1.
create a column to store the lock version
. The column type should be `BIGINT DEFAULT 0`.
* 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
* the lock version of the recording being updated.
...
...
@@ -753,8 +753,10 @@ class ActiveRecord extends Model
$condition
=
$this
->
getOldPrimaryKey
(
true
);
$lock
=
$this
->
optimisticLock
();
if
(
$lock
!==
null
)
{
if
(
!
isset
(
$values
[
$lock
]))
{
$values
[
$lock
]
=
$this
->
$lock
+
1
;
$condition
[
$lock
]
=
new
Expression
(
"[[
$lock
]]+1"
);
}
$condition
[
$lock
]
=
$this
->
$lock
;
}
// We do not check the return value of updateAll() because it's possible
// that the UPDATE statement doesn't change anything and thus returns 0.
...
...
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