Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 65862c9

Browse filesBrowse files
minor #11667 [HttpFoundation] revert #11510, moved to 2.6 (nicolas-grekas)
This PR was merged into the 2.3 branch. Discussion ---------- [HttpFoundation] revert #11510, moved to 2.6 | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | none This reverts PR #11510 from 2.3. Commits ------- fb120c7 revert #11510, moved to 2.6
2 parents a8b13a2 + fb120c7 commit 65862c9
Copy full SHA for 65862c9

File tree

Expand file treeCollapse file tree

2 files changed

+10
-94
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-94
lines changed

‎src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php
+7-26Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ public function __construct($mongo, array $options)
6262
$this->mongo = $mongo;
6363

6464
$this->options = array_merge(array(
65-
'id_field' => '_id',
66-
'data_field' => 'data',
67-
'time_field' => 'time',
68-
'expiry_field' => false,
65+
'id_field' => '_id',
66+
'data_field' => 'data',
67+
'time_field' => 'time',
6968
), $options);
7069
}
7170

@@ -110,9 +109,6 @@ public function gc($maxlifetime)
110109
*
111110
* See: http://docs.mongodb.org/manual/tutorial/expire-data/
112111
*/
113-
if (false !== $this->options['expiry_field']) {
114-
return true;
115-
}
116112
$time = new \MongoDate(time() - $maxlifetime);
117113

118114
$this->getCollection()->remove(array(
@@ -127,27 +123,12 @@ public function gc($maxlifetime)
127123
*/
128124
public function write($sessionId, $data)
129125
{
130-
$fields = array(
131-
$this->options['data_field'] => new \MongoBinData($data, \MongoBinData::BYTE_ARRAY),
132-
$this->options['time_field'] => new \MongoDate(),
133-
);
134-
135-
/* Note: As discussed in the gc method of this class. You can utilise
136-
* TTL collections in MongoDB 2.2+
137-
* We are setting the "expiry_field" as part of the write operation here
138-
* You will need to create the index on your collection that expires documents
139-
* at that time
140-
* e.g.
141-
* db.MySessionCollection.ensureIndex( { "expireAt": 1 }, { expireAfterSeconds: 0 } )
142-
*/
143-
if (false !== $this->options['expiry_field']) {
144-
$expiry = new \MongoDate(time() + (int) ini_get('session.gc_maxlifetime'));
145-
$fields[$this->options['expiry_field']] = $expiry;
146-
}
147-
148126
$this->getCollection()->update(
149127
array($this->options['id_field'] => $sessionId),
150-
array('$set' => $fields),
128+
array('$set' => array(
129+
$this->options['data_field'] => new \MongoBinData($data, \MongoBinData::BYTE_ARRAY),
130+
$this->options['time_field'] => new \MongoDate(),
131+
)),
151132
array('upsert' => true, 'multiple' => false)
152133
);
153134

‎src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php
+3-68Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function setUp()
4141
'data_field' => 'data',
4242
'time_field' => 'time',
4343
'database' => 'sf2-test',
44-
'collection' => 'session-test',
44+
'collection' => 'session-test'
4545
);
4646

4747
$this->storage = new MongoDbSessionHandler($this->mongo, $this->options);
@@ -100,45 +100,6 @@ public function testWrite()
100100
$that->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
101101
}
102102

103-
public function testWriteWhenUsingExpiresField()
104-
{
105-
$this->options = array(
106-
'id_field' => '_id',
107-
'data_field' => 'data',
108-
'time_field' => 'time',
109-
'database' => 'sf2-test',
110-
'collection' => 'session-test',
111-
'expiry_field' => 'expiresAt'
112-
);
113-
114-
$this->storage = new MongoDbSessionHandler($this->mongo, $this->options);
115-
116-
$collection = $this->createMongoCollectionMock();
117-
118-
$this->mongo->expects($this->once())
119-
->method('selectCollection')
120-
->with($this->options['database'], $this->options['collection'])
121-
->will($this->returnValue($collection));
122-
123-
$that = $this;
124-
$data = array();
125-
126-
$collection->expects($this->once())
127-
->method('update')
128-
->will($this->returnCallback(function ($criteria, $updateData, $options) use ($that, &$data) {
129-
$that->assertEquals(array($that->options['id_field'] => 'foo'), $criteria);
130-
$that->assertEquals(array('upsert' => true, 'multiple' => false), $options);
131-
132-
$data = $updateData['$set'];
133-
}));
134-
135-
$this->assertTrue($this->storage->write('foo', 'bar'));
136-
137-
$this->assertEquals('bar', $data[$this->options['data_field']]->bin);
138-
$that->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
139-
$that->assertInstanceOf('MongoDate', $data[$this->options['expiry_field']]);
140-
}
141-
142103
public function testReplaceSessionData()
143104
{
144105
$collection = $this->createMongoCollectionMock();
@@ -193,36 +154,10 @@ public function testGc()
193154
->method('remove')
194155
->will($this->returnCallback(function ($criteria) use ($that) {
195156
$that->assertInstanceOf('MongoDate', $criteria[$that->options['time_field']]['$lt']);
196-
$that->assertGreaterThanOrEqual(time() - 1, $criteria[$that->options['time_field']]['$lt']->sec);
157+
$that->assertGreaterThanOrEqual(time() - -1, $criteria[$that->options['time_field']]['$lt']->sec);
197158
}));
198159

199-
$this->assertTrue($this->storage->gc(1));
200-
}
201-
202-
public function testGcWhenUsingExpiresField()
203-
{
204-
$this->options = array(
205-
'id_field' => '_id',
206-
'data_field' => 'data',
207-
'time_field' => 'time',
208-
'database' => 'sf2-test',
209-
'collection' => 'session-test',
210-
'expiry_field' => 'expiresAt'
211-
);
212-
213-
$this->storage = new MongoDbSessionHandler($this->mongo, $this->options);
214-
215-
$collection = $this->createMongoCollectionMock();
216-
217-
$this->mongo->expects($this->never())
218-
->method('selectCollection');
219-
220-
$that = $this;
221-
222-
$collection->expects($this->never())
223-
->method('remove');
224-
225-
$this->assertTrue($this->storage->gc(1));
160+
$this->assertTrue($this->storage->gc(-1));
226161
}
227162

228163
private function createMongoCollectionMock()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.