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
8a6418a9
Commit
8a6418a9
authored
Feb 18, 2014
by
Alexander Mohorev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring Session component
parent
c56bf509
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
42 deletions
+31
-42
Session.php
extensions/mongodb/Session.php
+31
-42
No files found.
extensions/mongodb/Session.php
View file @
8a6418a9
...
...
@@ -91,27 +91,21 @@ class Session extends \yii\web\Session
parent
::
regenerateID
(
false
);
$newID
=
session_id
();
$query
=
new
Query
;
$row
=
$query
->
from
(
$this
->
sessionCollection
)
->
where
([
'id'
=>
$oldID
])
->
one
(
$this
->
db
);
if
(
$row
!==
false
)
{
$collection
=
$this
->
db
->
getCollection
(
$this
->
sessionCollection
);
$row
=
$collection
->
findOne
([
'id'
=>
$oldID
]);
if
(
$row
!==
null
)
{
if
(
$deleteOldSession
)
{
$this
->
db
->
getCollection
(
$this
->
sessionCollection
)
->
update
([
'_id'
=>
$row
[
'_id'
]],
[
'id'
=>
$newID
]);
$collection
->
update
([
'id'
=>
$oldID
],
[
'id'
=>
$newID
]);
}
else
{
unset
(
$row
[
'_id'
]);
$row
[
'id'
]
=
$newID
;
$this
->
db
->
getCollection
(
$this
->
sessionCollection
)
->
insert
(
$row
);
$collection
->
insert
(
$row
);
}
}
else
{
// shouldn't reach here normally
$this
->
db
->
getCollection
(
$this
->
sessionCollection
)
->
insert
([
$collection
->
insert
([
'id'
=>
$newID
,
'expire'
=>
time
()
+
$this
->
getTimeout
(),
'data'
=>
''
,
'expire'
=>
time
()
+
$this
->
getTimeout
()
]);
}
}
...
...
@@ -124,15 +118,15 @@ class Session extends \yii\web\Session
*/
public
function
readSession
(
$id
)
{
$
query
=
new
Query
;
$
row
=
$query
->
select
([
'data'
])
->
from
(
$this
->
sessionCollection
)
->
where
([
$
collection
=
$this
->
db
->
getCollection
(
$this
->
sessionCollection
)
;
$
doc
=
$collection
->
findOne
(
[
'id'
=>
$id
,
'expire'
=>
[
'$gt'
=>
time
()],
'id'
=>
$id
])
->
one
(
$this
->
db
);
return
$row
===
false
?
''
:
$row
[
'data'
]
;
],
[
'data'
=>
1
,
'_id'
=>
0
]
);
return
isset
(
$doc
[
'data'
])
?
$doc
[
'data'
]
:
''
;
}
/**
...
...
@@ -147,23 +141,15 @@ class Session extends \yii\web\Session
// exception must be caught in session write handler
// http://us.php.net/manual/en/function.session-set-save-handler.php
try
{
$expire
=
time
()
+
$this
->
getTimeout
();
$query
=
new
Query
;
$exists
=
$query
->
select
([
'id'
])
->
from
(
$this
->
sessionCollection
)
->
where
([
'id'
=>
$id
])
->
one
(
$this
->
db
);
if
(
$exists
===
false
)
{
$this
->
db
->
getCollection
(
$this
->
sessionCollection
)
->
insert
([
$this
->
db
->
getCollection
(
$this
->
sessionCollection
)
->
update
(
[
'id'
=>
$id
],
[
'id'
=>
$id
,
'data'
=>
$data
,
'expire'
=>
$expire
,
]);
}
else
{
$this
->
db
->
getCollection
(
$this
->
sessionCollection
)
->
update
([
'id'
=>
$id
],
[
'data'
=>
$data
,
'expire'
=>
$expire
]);
}
'expire'
=>
time
()
+
$this
->
getTimeout
(),
],
[
'upsert'
=>
true
]
);
}
catch
(
\Exception
$e
)
{
if
(
YII_DEBUG
)
{
echo
$e
->
getMessage
();
...
...
@@ -182,8 +168,10 @@ class Session extends \yii\web\Session
*/
public
function
destroySession
(
$id
)
{
$this
->
db
->
getCollection
(
$this
->
sessionCollection
)
->
remove
([
'id'
=>
$id
]);
$this
->
db
->
getCollection
(
$this
->
sessionCollection
)
->
remove
(
[
'id'
=>
$id
],
[
'justOne'
=>
true
]
);
return
true
;
}
...
...
@@ -195,10 +183,10 @@ class Session extends \yii\web\Session
*/
public
function
gcSession
(
$maxLifetime
)
{
$this
->
db
->
getCollection
(
$this
->
sessionCollection
)
->
remove
([
'expire'
=>
[
'$lt'
=>
time
()
]
]
);
$this
->
db
->
getCollection
(
$this
->
sessionCollection
)
->
remove
(
[
'expire'
=>
[
'$lt'
=>
time
()]],
[
'justOne'
=>
false
]
);
return
true
;
}
}
\ No newline at end of file
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