diff options
Diffstat (limited to 'lib/private/DB/Connection.php')
-rw-r--r-- | lib/private/DB/Connection.php | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index 6f89ba64e80..0cd310550b6 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -49,12 +49,12 @@ use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Result; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Statement; -use OC\DB\QueryBuilder\QueryBuilder; -use OC\SystemConfig; use OCP\DB\QueryBuilder\IQueryBuilder; -use OCP\ILogger; use OCP\IRequestId; use OCP\PreConditionNotMetException; +use OC\DB\QueryBuilder\QueryBuilder; +use OC\SystemConfig; +use Psr\Log\LoggerInterface; class Connection extends \Doctrine\DBAL\Connection { /** @var string */ @@ -66,8 +66,7 @@ class Connection extends \Doctrine\DBAL\Connection { /** @var SystemConfig */ private $systemConfig; - /** @var ILogger */ - private $logger; + private LoggerInterface $logger; protected $lockedTable = null; @@ -78,6 +77,34 @@ class Connection extends \Doctrine\DBAL\Connection { protected $queriesExecuted = 0; /** + * Initializes a new instance of the Connection class. + * + * @throws \Exception + */ + public function __construct( + array $params, + Driver $driver, + ?Configuration $config = null, + ?EventManager $eventManager = null + ) { + if (!isset($params['adapter'])) { + throw new \Exception('adapter not set'); + } + if (!isset($params['tablePrefix'])) { + throw new \Exception('tablePrefix not set'); + } + /** + * @psalm-suppress InternalMethod + */ + parent::__construct($params, $driver, $config, $eventManager); + $this->adapter = new $params['adapter']($this); + $this->tablePrefix = $params['tablePrefix']; + + $this->systemConfig = \OC::$server->getSystemConfig(); + $this->logger = \OC::$server->get(LoggerInterface::class); + } + + /** * @throws Exception */ public function connect() { @@ -126,7 +153,7 @@ class Connection extends \Doctrine\DBAL\Connection { */ public function createQueryBuilder() { $backtrace = $this->getCallerBacktrace(); - \OC::$server->getLogger()->debug('Doctrine QueryBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); + $this->logger->debug('Doctrine QueryBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); $this->queriesBuilt++; return parent::createQueryBuilder(); } @@ -139,7 +166,7 @@ class Connection extends \Doctrine\DBAL\Connection { */ public function getExpressionBuilder() { $backtrace = $this->getCallerBacktrace(); - \OC::$server->getLogger()->debug('Doctrine ExpressionBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); + $this->logger->debug('Doctrine ExpressionBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); $this->queriesBuilt++; return parent::getExpressionBuilder(); } @@ -169,34 +196,6 @@ class Connection extends \Doctrine\DBAL\Connection { } /** - * Initializes a new instance of the Connection class. - * - * @param array $params The connection parameters. - * @param \Doctrine\DBAL\Driver $driver - * @param \Doctrine\DBAL\Configuration $config - * @param \Doctrine\Common\EventManager $eventManager - * @throws \Exception - */ - public function __construct(array $params, Driver $driver, Configuration $config = null, - EventManager $eventManager = null) { - if (!isset($params['adapter'])) { - throw new \Exception('adapter not set'); - } - if (!isset($params['tablePrefix'])) { - throw new \Exception('tablePrefix not set'); - } - /** - * @psalm-suppress InternalMethod - */ - parent::__construct($params, $driver, $config, $eventManager); - $this->adapter = new $params['adapter']($this); - $this->tablePrefix = $params['tablePrefix']; - - $this->systemConfig = \OC::$server->getSystemConfig(); - $this->logger = \OC::$server->getLogger(); - } - - /** * Prepares an SQL statement. * * @param string $statement The SQL statement to prepare. |