From 8f7b23d9c307d50891769f1a1fd5472ac991f3e9 Mon Sep 17 00:00:00 2001 From: flack Date: Mon, 4 Dec 2023 21:01:05 +0100 Subject: [PATCH] Fix some deprecations --- composer.json | 2 +- src/storage/connection.php | 22 ++++++++++--------- src/storage/sqllogger.php | 43 -------------------------------------- 3 files changed, 13 insertions(+), 54 deletions(-) delete mode 100644 src/storage/sqllogger.php diff --git a/composer.json b/composer.json index c8559ca..a630adb 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "require": { "php": ">=7.4", - "doctrine/orm": "^2.13", + "doctrine/orm": "^2.14", "doctrine/dbal": "^3.5", "symfony/console": ">=3.0.0", "symfony/cache": ">=4.4.0", diff --git a/src/storage/connection.php b/src/storage/connection.php index 2beb81b..fa0c8fc 100644 --- a/src/storage/connection.php +++ b/src/storage/connection.php @@ -22,6 +22,8 @@ use midgard\portable\mapping\factory; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\ORMSetup; +use Doctrine\DBAL\Logging\Connection as connection_logger; +use Doctrine\DBAL\Logging\Middleware; class connection { @@ -181,26 +183,26 @@ public static function startup() $config->setMetadataDriverImpl($driver); $config->setClassMetadataFactoryName(factory::class); + $midgard = midgard_connection::get_instance(); + $level = self::$loglevels[$midgard->get_loglevel()]; + if ($level === Logger::DEBUG) { + $logger = new Logger('doctrine'); + $logger->pushHandler(new StreamHandler($midgard->config->logfilename, $level)); + $config->setMiddlewares([new Middleware($logger)]); + } + if (!array_key_exists('charset', $db_config)) { $db_config['charset'] = 'utf8'; } - $em = \Doctrine\ORM\EntityManager::create($db_config, $config); + $connection = \Doctrine\DBAL\DriverManager::getConnection($db_config, $config); + $em = new EntityManager($connection, $config); $em->getFilters()->enable('softdelete'); $em->getEventManager()->addEventSubscriber(new subscriber); Type::overrideType(Types::DATETIME_MUTABLE, datetime::class); Type::overrideType(Types::DATE_MUTABLE, datetime::class); - $midgard = midgard_connection::get_instance(); - $level = self::$loglevels[$midgard->get_loglevel()]; - if ($level === Logger::DEBUG) { - $logger = new Logger('doctrine'); - $logger->pushHandler(new StreamHandler($midgard->config->logfilename, $level)); - - $em->getConnection()->getConfiguration()->setSQLLogger(new sqllogger($logger)); - } - self::$instance = new static($em, $driver->get_namespace()); } diff --git a/src/storage/sqllogger.php b/src/storage/sqllogger.php deleted file mode 100644 index 167131e..0000000 --- a/src/storage/sqllogger.php +++ /dev/null @@ -1,43 +0,0 @@ -logger = $logger; - } - - /** - * {@inheritdoc} - */ - public function startQuery($sql, array $params = null, array $types = null) - { - $context = []; - if (!empty($params)) { - $context['params'] = $params; - } - if (!empty($types)) { - $context['types'] = $types; - } - $this->logger->debug($sql, $context); - } - - /** - * {@inheritdoc} - */ - public function stopQuery() - { - } -}