Skip to content

Commit

Permalink
Merge pull request #8539 from kenjis/fix-db-dateFormat-merge
Browse files Browse the repository at this point in the history
[4.5] fix: $db->dateFormat merge
  • Loading branch information
kenjis authored Feb 12, 2024
2 parents 09b48d5 + f5a28e2 commit 01e1a46
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
9 changes: 5 additions & 4 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,17 @@ abstract class BaseConnection implements ConnectionInterface
*/
public function __construct(array $params)
{
if (isset($params['dateFormat'])) {
$this->dateFormat = array_merge($this->dateFormat, $params['dateFormat']);
unset($params['dateFormat']);
}

foreach ($params as $key => $value) {
if (property_exists($this, $key)) {
$this->{$key} = $value;
}
}

if (isset($params['dateFormat'])) {
$this->dateFormat = array_merge($this->dateFormat, $params['dateFormat']);
}

$queryClass = str_replace('Connection', 'Query', static::class);

if (class_exists($queryClass)) {
Expand Down
37 changes: 21 additions & 16 deletions tests/system/Database/BaseConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,27 @@
final class BaseConnectionTest extends CIUnitTestCase
{
private array $options = [
'DSN' => '',
'hostname' => 'localhost',
'username' => 'first',
'password' => 'last',
'database' => 'dbname',
'DBDriver' => 'MockDriver',
'DBPrefix' => 'test_',
'pConnect' => true,
'DBDebug' => true,
'charset' => 'utf8mb4',
'DBCollat' => 'utf8mb4_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => true,
'failover' => [],
'DSN' => '',
'hostname' => 'localhost',
'username' => 'first',
'password' => 'last',
'database' => 'dbname',
'DBDriver' => 'MockDriver',
'DBPrefix' => 'test_',
'pConnect' => true,
'DBDebug' => true,
'charset' => 'utf8mb4',
'DBCollat' => 'utf8mb4_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => true,
'failover' => [],
'dateFormat' => [
'date' => 'Y-m-d',
'datetime' => 'Y-m-d H:i:s',
'time' => 'H:i:s',
],
];
private array $failoverOptions = [
'DSN' => '',
Expand Down

0 comments on commit 01e1a46

Please sign in to comment.