From 22775df27e35503c931e91d0ab1b7228b7f71d54 Mon Sep 17 00:00:00 2001 From: Helmut Januschka Date: Mon, 5 Mar 2018 12:54:46 +0100 Subject: [PATCH 1/4] add missing method createDateTime add missing createDateTime --- .../Storage/Handler/MongoDbSessionHandler.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php index edc0149f995a4..eea84e94f2f33 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php @@ -163,6 +163,26 @@ public function updateTimestamp($sessionId, $data) return true; } + /** + * Create a date object using the class appropriate for the current mongo connection. + * + * Return an instance of a MongoDate or \MongoDB\BSON\UTCDateTime + * + * @param int $seconds An integer representing UTC seconds since Jan 1 1970. Defaults to now. + * + * @return \MongoDate|\MongoDB\BSON\UTCDateTime + */ + private function createDateTime($seconds = null) + { + if (null === $seconds) { + $seconds = time(); + } + if ($this->mongo instanceof \MongoDB\Client) { + return new \MongoDB\BSON\UTCDateTime($seconds * 1000); + } + return new \MongoDate($seconds); + } + /** * {@inheritdoc} */ From 33f80b7659a3b757f791b5fa7ced534c0b9a06f2 Mon Sep 17 00:00:00 2001 From: Helmut Januschka Date: Mon, 5 Mar 2018 12:59:36 +0100 Subject: [PATCH 2/4] code style --- .../Session/Storage/Handler/MongoDbSessionHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php index eea84e94f2f33..7931c6cd447f1 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php @@ -182,7 +182,7 @@ private function createDateTime($seconds = null) } return new \MongoDate($seconds); } - + /** * {@inheritdoc} */ From f8bca4c60245966aa43863c1fdf1f28170620b52 Mon Sep 17 00:00:00 2001 From: Helmut Januschka Date: Mon, 5 Mar 2018 16:13:46 +0100 Subject: [PATCH 3/4] cs fixes --- .../Session/Storage/Handler/MongoDbSessionHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php index 7931c6cd447f1..0058b663e4ad4 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php @@ -180,6 +180,7 @@ private function createDateTime($seconds = null) if ($this->mongo instanceof \MongoDB\Client) { return new \MongoDB\BSON\UTCDateTime($seconds * 1000); } + return new \MongoDate($seconds); } From 202a05dd2422250c95592f1575e7bde7eb0f2b95 Mon Sep 17 00:00:00 2001 From: Helmut Januschka Date: Mon, 5 Mar 2018 16:46:13 +0100 Subject: [PATCH 4/4] use MongoDB\BSON\UTCDateTime --- .../Storage/Handler/MongoDbSessionHandler.php | 25 ++----------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php index 0058b663e4ad4..9cc7055e984a2 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php @@ -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'; @@ -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 @@ -163,27 +163,6 @@ public function updateTimestamp($sessionId, $data) return true; } - /** - * Create a date object using the class appropriate for the current mongo connection. - * - * Return an instance of a MongoDate or \MongoDB\BSON\UTCDateTime - * - * @param int $seconds An integer representing UTC seconds since Jan 1 1970. Defaults to now. - * - * @return \MongoDate|\MongoDB\BSON\UTCDateTime - */ - private function createDateTime($seconds = null) - { - if (null === $seconds) { - $seconds = time(); - } - if ($this->mongo instanceof \MongoDB\Client) { - return new \MongoDB\BSON\UTCDateTime($seconds * 1000); - } - - return new \MongoDate($seconds); - } - /** * {@inheritdoc} */