Skip to content

Commit

Permalink
bug #26403 fix the handling of timestamp in the MongoDBSessionHandler…
Browse files Browse the repository at this point in the history
… (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
-------

97d9ea8 fix the handling of timestamp in the MongoDBSessionHandler
  • Loading branch information
stof committed Mar 5, 2018
2 parents cb06d0f + 97d9ea8 commit 1819c8d
Showing 1 changed file with 2 additions and 2 deletions.
Expand Up @@ -141,7 +141,7 @@ protected function doWrite($sessionId, $data)
*/
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';
Expand All @@ -154,7 +154,7 @@ public function updateTimestamp($sessionId, $data)
$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
Expand Down

0 comments on commit 1819c8d

Please sign in to comment.