bug #24448 [Session] fix MongoDb session handler to gc all expired sessions (Tobion)

This PR was merged into the 2.7 branch.

Discussion
----------

[Session] fix MongoDb session handler to gc all expired sessions

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

MongoDB session handler `gc` wrongly only deleted one random expired session instead of all of them.
Care when merging to master as this will conflict with #24447

Commits
-------

e6895bfac5 [Session] fix MongoDb session handler to gc all expired sessions
This commit is contained in:
Fabien Potencier 2017-10-05 15:34:50 -07:00
commit f961aa024f
2 changed files with 2 additions and 2 deletions

View File

@ -118,7 +118,7 @@ class MongoDbSessionHandler implements \SessionHandlerInterface
*/
public function gc($maxlifetime)
{
$methodName = $this->mongo instanceof \MongoDB\Client ? 'deleteOne' : 'remove';
$methodName = $this->mongo instanceof \MongoDB\Client ? 'deleteMany' : 'remove';
$this->getCollection()->$methodName(array(
$this->options['expiry_field'] => array('$lt' => $this->createDateTime()),

View File

@ -291,7 +291,7 @@ class MongoDbSessionHandlerTest extends TestCase
$that = $this;
$methodName = phpversion('mongodb') ? 'deleteOne' : 'remove';
$methodName = phpversion('mongodb') ? 'deleteMany' : 'remove';
$collection->expects($this->once())
->method($methodName)