Skip to content

Commit

Permalink
[HttpFoundation] [PDO] Don't fetch time when reading the session
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan authored and fabpot committed Sep 21, 2021
1 parent e16cc55 commit fb9508f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,6 @@ protected function doRead(string $sessionId): string

if ($sessionRows) {
$expiry = (int) $sessionRows[0][1];
if ($expiry <= self::MAX_LIFETIME) {
$expiry += $sessionRows[0][2];
}

if ($expiry < time()) {
$this->sessionExpired = true;
Expand Down Expand Up @@ -726,14 +723,13 @@ private function getSelectSql(): string
if (self::LOCK_TRANSACTIONAL === $this->lockMode) {
$this->beginTransaction();

// selecting the time column should be removed in 6.0
switch ($this->driver) {
case 'mysql':
case 'oci':
case 'pgsql':
return "SELECT $this->dataCol, $this->lifetimeCol, $this->timeCol FROM $this->table WHERE $this->idCol = :id FOR UPDATE";
return "SELECT $this->dataCol, $this->lifetimeCol FROM $this->table WHERE $this->idCol = :id FOR UPDATE";
case 'sqlsrv':
return "SELECT $this->dataCol, $this->lifetimeCol, $this->timeCol FROM $this->table WITH (UPDLOCK, ROWLOCK) WHERE $this->idCol = :id";
return "SELECT $this->dataCol, $this->lifetimeCol FROM $this->table WITH (UPDLOCK, ROWLOCK) WHERE $this->idCol = :id";
case 'sqlite':
// we already locked when starting transaction
break;
Expand All @@ -742,7 +738,7 @@ private function getSelectSql(): string
}
}

return "SELECT $this->dataCol, $this->lifetimeCol, $this->timeCol FROM $this->table WHERE $this->idCol = :id";
return "SELECT $this->dataCol, $this->lifetimeCol FROM $this->table WHERE $this->idCol = :id";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function testReadConvertsStreamToString()
$stream = $this->createStream($content);

$pdo->prepareResult->expects($this->once())->method('fetchAll')
->willReturn([[$stream, 42, time()]]);
->willReturn([[$stream, time() + 42]]);

$storage = new PdoSessionHandler($pdo);
$result = $storage->read('foo');
Expand Down Expand Up @@ -165,7 +165,7 @@ public function testReadLockedConvertsStreamToString()

$selectStmt->expects($this->atLeast(2))->method('fetchAll')
->willReturnCallback(function () use (&$exception, $stream) {
return $exception ? [[$stream, 42, time()]] : [];
return $exception ? [[$stream, time() + 42]] : [];
});

$insertStmt->expects($this->once())->method('execute')
Expand Down

0 comments on commit fb9508f

Please sign in to comment.