8000 fix the handling of timestamp in the MongoDBSessionHandler by hjanuschka · Pull Request #26403 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

fix the handling of timestamp in the MongoDBSessionHandler #26403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
use MongoDB\BSON\UTCDateTime
  • Loading branch information
hjanuschka committed Mar 5, 2018
commit 202a05dd2422250c95592f1575e7bde7eb0f2b95
Original file line number Diff line number Diff line change
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 All @@ -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}
*/
Expand Down
0