Skip to content
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

[HttpFoundation] [PDO] Don't fetch time when reading the session #43120

Merged
merged 1 commit into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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