bug #26403 fix the handling of timestamp in the MongoDBSessionHandler (hjanuschka)

This PR was submitted for the master branch but it was squashed and merged into the 4.0 branch instead (closes #26403).

Discussion
----------

fix the handling of timestamp in the MongoDBSessionHandler

| Q             | A
| ------------- | ---
| Branch?       |  master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

in the process of upgrading from 3.4 to 4.0 we stumbled upon a issue with mongo session handler.

```
[05-Mar-2018 11:12:57 Europe/Vienna] PHP Fatal error:  Uncaught Error: Call to undefined method Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler::createDateTime() in /opt/APP/vendor/symfony/http-foundation/Session/Storage/Handler/MongoDbSessionHandler.php:144
Stack trace:
#0 [internal function]: Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler->updateTimestamp('96d983b59f8aef8...', 'user_obj|O:9:"k...')
#1 [internal function]: session_write_close()
#2 {main}
  thrown in /opt/APP/vendor/symfony/http-foundation/Session/Storage/Handler/MongoDbSessionHandler.php on line 144
```

this PR re-add's the method, that somehow got removed in 4.0 branch, whereas the interface forces to have the implemantation.

Commits
-------

97d9ea8269 fix the handling of timestamp in the MongoDBSessionHandler
This commit is contained in:
Christophe Coevoet 2018-03-05 17:01:10 +01:00
commit 1819c8dc51

View File

@ -141,7 +141,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
*/
public function updateTimestamp($sessionId, $data)
{
$expiry = $this->createDateTime(time() + (int) ini_get('session.gc_maxlifetime'));
$expiry = new \MongoDB\BSON\UTCDateTime((time() + (int) ini_get('session.gc_maxlifetime')) * 1000);
if ($this->mongo instanceof \MongoDB\Client) {
$methodName = 'updateOne';
@ -154,7 +154,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
$this->getCollection()->$methodName(
array($this->options['id_field'] => $sessionId),
array('$set' => array(
$this->options['time_field'] => $this->createDateTime(),
$this->options['time_field'] => new \MongoDB\BSON\UTCDateTime(),
$this->options['expiry_field'] => $expiry,
)),
$options