Skip to content

Commit

Permalink
bug #49097 [HttpFoundation] inject SessionHandler in PdoSessionHandle…
Browse files Browse the repository at this point in the history
…rSchemaSubscriber (alli83)

This PR was merged into the 6.3 branch.

Discussion
----------

[HttpFoundation] inject SessionHandler in PdoSessionHandlerSchemaSubscriber

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| License       | MIT
| Doc PR        |  I'm working on it

following the PR symfony/symfony#48059.

In symfony/symfony#48059, it works only if you put the handler explicitly to PdoSessionHandler in the configuration (handler_id) but it stops working if the session is defined by the factory and we can't use it as follow:
````
handler_id: '%env(resolve:DATABASE_URL)%'
`````

Linked to DoctrineBundle PR doctrine/DoctrineBundle#1623

Also imho, I think the second argument of configureSchema inPdoSessionHandler should be optional and set to return true if not defined  since the function is public eg. one wants to add the table to the Schema.

Commits
-------

9aded06c0c [HttpFoundation] inject SessionHandler in PdoSessionHandlerSchemaSubscriber
  • Loading branch information
nicolas-grekas committed Jan 29, 2023
2 parents cde7c2f + aff3a3c commit fad43be
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Session/Storage/Handler/PdoSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@ public function __construct(#[\SensitiveParameter] \PDO|string $pdoOrDsn = null,
$this->ttl = $options['ttl'] ?? null;
}

public function configureSchema(Schema $schema, \Closure $isSameDatabase): void
/**
* Adds the Table to the Schema if it doesn't exist.
*/
public function configureSchema(Schema $schema, \Closure $isSameDatabase = null): void
{
if ($schema->hasTable($this->table) || !$isSameDatabase($this->getConnection()->exec(...))) {
if ($schema->hasTable($this->table) || ($isSameDatabase && !$isSameDatabase($this->getConnection()->exec(...)))) {
return;
}

Expand Down

0 comments on commit fad43be

Please sign in to comment.