Skip to content

Commit

Permalink
make encoding required
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Feb 16, 2024
1 parent dafe312 commit 3e93e21
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
8 changes: 2 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ Changelog
When instantiating the client, you need to provide at least the cache instance for metadata, as CachedClient does not know which implementation to pick.
* Support for new Symfony versions.
* Support for doctrine/dbal 4.
* For MySQL/MariaDB, default to `utf8mb4` encoding instead of `utf8` if autodiscovery does not provide the encoding.
If you get errors about the collation, either upgrade your database to utf8mb4 or explicitly configure the encoding
with `Client::setCaseSensitiveEncoding('utf8_bin')`. The error on misconfiguration looks like this:

1253 COLLATION 'utf8_bin' is not valid for CHARACTER SET 'utf8mb4'

* For MySQL/MariaDB, it is now required to configure `collate` or `charset` in the Doctrine connection, or alternatively
set the encoding explicitly with `Client::setCaseSensitiveEncoding('utf8_bin')`.
* If you are on PHP 8.0 and install Jackalope with `symfony/cache`, you need to restrict `psr/simple-cache` to `^1.0 || ^2.0` in your application because Symfony 5 does not declare a conflict with it, but fails at runtime.
* Drop support for PHP 7.
* Fixed: While it is allowed to call `Repository::login` with `null` credentials, there used to be an error. It now correctly works.
Expand Down
3 changes: 3 additions & 0 deletions src/Jackalope/Transport/DoctrineDBAL/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ private function getMySQLCaseSensitiveEncoding(): string
if (isset($params['defaultTableOptions']['collate'])) {
return $this->caseSensitiveEncoding = $params['defaultTableOptions']['collate'];
}
if (!array_key_exists('charset', $params)) {
throw new \InvalidArgumentException('For MySQL, the Doctrine dbal connection must have either "collate" or "charset" configured. Alternatively, you can set the encoding with '.__CLASS__.'::setCaseSensitiveEncoding().');
}
$charset = $params['charset'] ?? 'utf8';

return $this->caseSensitiveEncoding = 'binary' === $charset ? $charset : $charset.'_bin';
Expand Down
10 changes: 8 additions & 2 deletions tests/Jackalope/Test/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@ protected function getConnection(): Connection
return $this->conn;
}

$this->conn = DriverManager::getConnection([
$params = [
'driver' => @$GLOBALS['phpcr.doctrine.dbal.driver'],
'path' => @$GLOBALS['phpcr.doctrine.dbal.path'],
'host' => @$GLOBALS['phpcr.doctrine.dbal.host'],
'port' => @$GLOBALS['phpcr.doctrine.dbal.port'],
'user' => @$GLOBALS['phpcr.doctrine.dbal.username'],
'password' => @$GLOBALS['phpcr.doctrine.dbal.password'],
'dbname' => @$GLOBALS['phpcr.doctrine.dbal.dbname'],
]);
];
if (array_key_exists('phpcr.doctrine.dbal.collate', $GLOBALS)) {
$params['collate'] = $GLOBALS['phpcr.doctrine.dbal.collate'];
}

$this->conn = DriverManager::getConnection($params);

return $this->conn;
}
Expand Down
8 changes: 6 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@
* For further details, please see Doctrine configuration page.
* http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connection-details.
*/
$dbConn = DriverManager::getConnection([
$params = [
'driver' => @$GLOBALS['phpcr.doctrine.dbal.driver'],
'path' => @$GLOBALS['phpcr.doctrine.dbal.path'],
'host' => @$GLOBALS['phpcr.doctrine.dbal.host'],
'port' => @$GLOBALS['phpcr.doctrine.dbal.port'],
'user' => @$GLOBALS['phpcr.doctrine.dbal.username'],
'password' => @$GLOBALS['phpcr.doctrine.dbal.password'],
'dbname' => @$GLOBALS['phpcr.doctrine.dbal.dbname'],
]);
];
if (array_key_exists('phpcr.doctrine.dbal.collate', $GLOBALS)) {
$params['collate'] = $GLOBALS['phpcr.doctrine.dbal.collate'];
}
$dbConn = DriverManager::getConnection($params);

/* Recreate database schema */
if (!getenv('JACKALOPE_NO_TEST_DB_INIT')) {
Expand Down
3 changes: 2 additions & 1 deletion tests/generate_phpunit_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'phpcr.doctrine.dbal.username' => 'root',
'phpcr.doctrine.dbal.password' => 'root',
'phpcr.doctrine.dbal.dbname' => 'phpcr_tests',
'phpcr.doctrine.dbal.collate' => 'utf8_bin',
],
'pgsql' => [
'phpcr.doctrine.dbal.driver' => 'pdo_pgsql',
Expand All @@ -28,7 +29,7 @@
],
];

if (!in_array(@$argv[1], array_keys($config))) {
if (!array_key_exists(@$argv[1], $config)) {
exit('Error:'."\n\t".'Database "'.@$argv[1].'" not supported.'."\n".
'Usage:'."\n\t".'php tests/'.basename(__FILE__).' ['.implode('|', array_keys($config)).']'."\n");
}
Expand Down

0 comments on commit 3e93e21

Please sign in to comment.