Skip to content

Commit 1819c8d

Browse files
committed
bug symfony#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 symfony#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
2 parents cb06d0f + 97d9ea8 commit 1819c8d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected function doWrite($sessionId, $data)
141141
*/
142142
public function updateTimestamp($sessionId, $data)
143143
{
144-
$expiry = $this->createDateTime(time() + (int) ini_get('session.gc_maxlifetime'));
144+
$expiry = new \MongoDB\BSON\UTCDateTime((time() + (int) ini_get('session.gc_maxlifetime')) * 1000);
145145

146146
if ($this->mongo instanceof \MongoDB\Client) {
147147
$methodName = 'updateOne';
@@ -154,7 +154,7 @@ public function updateTimestamp($sessionId, $data)
154154
$this->getCollection()->$methodName(
155155
array($this->options['id_field'] => $sessionId),
156156
array('$set' => array(
157-
$this->options['time_field'] => $this->createDateTime(),
157+
$this->options['time_field'] => new \MongoDB\BSON\UTCDateTime(),
158158
$this->options['expiry_field'] => $expiry,
159159
)),
160160
$options

0 commit comments

Comments
 (0)