bug #37563 Fix DBAL deprecation (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

Fix DBAL deprecation

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Follows https://github.com/doctrine/dbal/pull/4163

Commits
-------

4273aedfae Fix DBAL deprecation
This commit is contained in:
Nicolas Grekas 2020-07-12 12:25:53 +02:00
commit 3ae61ec22c
3 changed files with 31 additions and 7 deletions

View File

@ -81,7 +81,11 @@ class DoctrineTokenProvider implements TokenProviderInterface
$sql = 'DELETE FROM rememberme_token WHERE series=:series'; $sql = 'DELETE FROM rememberme_token WHERE series=:series';
$paramValues = ['series' => $series]; $paramValues = ['series' => $series];
$paramTypes = ['series' => \PDO::PARAM_STR]; $paramTypes = ['series' => \PDO::PARAM_STR];
$this->conn->executeUpdate($sql, $paramValues, $paramTypes); if (method_exists($this->conn, 'executeStatement')) {
$this->conn->executeStatement($sql, $paramValues, $paramTypes);
} else {
$this->conn->executeUpdate($sql, $paramValues, $paramTypes);
}
} }
/** /**
@ -101,7 +105,11 @@ class DoctrineTokenProvider implements TokenProviderInterface
'lastUsed' => self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE, 'lastUsed' => self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE,
'series' => \PDO::PARAM_STR, 'series' => \PDO::PARAM_STR,
]; ];
$updated = $this->conn->executeUpdate($sql, $paramValues, $paramTypes); if (method_exists($this->conn, 'executeStatement')) {
$updated = $this->conn->executeStatement($sql, $paramValues, $paramTypes);
} else {
$updated = $this->conn->executeUpdate($sql, $paramValues, $paramTypes);
}
if ($updated < 1) { if ($updated < 1) {
throw new TokenNotFoundException('No token found.'); throw new TokenNotFoundException('No token found.');
} }
@ -129,6 +137,10 @@ class DoctrineTokenProvider implements TokenProviderInterface
'value' => \PDO::PARAM_STR, 'value' => \PDO::PARAM_STR,
'lastUsed' => self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE, 'lastUsed' => self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE,
]; ];
$this->conn->executeUpdate($sql, $paramValues, $paramTypes); if (method_exists($this->conn, 'executeStatement')) {
$this->conn->executeStatement($sql, $paramValues, $paramTypes);
} else {
$this->conn->executeUpdate($sql, $paramValues, $paramTypes);
}
} }
} }

View File

@ -72,7 +72,7 @@ class DoctrineTokenProviderTest extends TestCase
'driver' => 'pdo_sqlite', 'driver' => 'pdo_sqlite',
'url' => 'sqlite:///:memory:', 'url' => 'sqlite:///:memory:',
]); ]);
$connection->executeUpdate(<<< 'SQL' $connection->{method_exists($this->conn, 'executeStatement') ? 'executeStatement' : 'executeUpdate'}(<<< 'SQL'
CREATE TABLE rememberme_token ( CREATE TABLE rememberme_token (
series char(88) UNIQUE PRIMARY KEY NOT NULL, series char(88) UNIQUE PRIMARY KEY NOT NULL,
value char(88) NOT NULL, value char(88) NOT NULL,

View File

@ -107,7 +107,11 @@ trait PdoTrait
$table->setPrimaryKey([$this->idCol]); $table->setPrimaryKey([$this->idCol]);
foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) { foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) {
$conn->exec($sql); if (method_exists($conn, 'executeStatement')) {
$conn->executeStatement($sql);
} else {
$conn->exec($sql);
}
} }
return; return;
@ -138,7 +142,11 @@ trait PdoTrait
throw new \DomainException(sprintf('Creating the cache table is currently not implemented for PDO driver "%s".', $this->driver)); throw new \DomainException(sprintf('Creating the cache table is currently not implemented for PDO driver "%s".', $this->driver));
} }
$conn->exec($sql); if (method_exists($conn, 'executeStatement')) {
$conn->executeStatement($sql);
} else {
$conn->exec($sql);
}
} }
/** /**
@ -238,7 +246,11 @@ trait PdoTrait
$sql = "DELETE FROM $this->table WHERE $this->idCol LIKE '$namespace%'"; $sql = "DELETE FROM $this->table WHERE $this->idCol LIKE '$namespace%'";
} }
$conn->exec($sql); if (method_exists($conn, 'executeStatement')) {
$conn->executeStatement($sql);
} else {
$conn->exec($sql);
}
return true; return true;
} }