oxid-sql-logger/src/OxidEsalesDatabase.php

96 lines
3.1 KiB
PHP
Raw Normal View History

2019-08-20 23:34:33 +02:00
<?php
2019-09-19 19:52:54 +02:00
2019-08-20 23:34:33 +02:00
/**
2019-09-19 19:52:54 +02:00
* @author Tobias Matthaiou <developer@tobimat.eu>
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
2019-08-20 23:34:33 +02:00
*/
2019-09-19 19:52:54 +02:00
namespace D3\OxidSqlLogger;
2019-08-20 23:34:33 +02:00
use Doctrine\DBAL\Configuration;
2021-03-02 15:31:09 +01:00
use Doctrine\DBAL\Logging\SQLLogger;
2019-08-20 23:34:33 +02:00
/**
* Class OxidEsalesDatabase
* Is a depenction injection Helper Class
*/
class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database
{
2021-03-02 15:31:09 +01:00
/**
* @param null $message
*
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
* @deprecated use non static d3EnableLogger method or D3StartSQLLog function
*/
public static function enableLogger($message = null)
{
$database = oxNew(OxidEsalesDatabase::class);
$database->d3EnableLogger($message);
}
/**
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
*/
public function d3EnableLogger($message)
2019-08-20 23:34:33 +02:00
{
$trace = debug_backtrace((PHP_VERSION_ID < 50306) ? 2 : DEBUG_BACKTRACE_IGNORE_ARGS);
2019-08-20 23:34:33 +02:00
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
2021-03-02 15:31:09 +01:00
/** @var Configuration $dbalConfig */
2019-08-20 23:34:33 +02:00
$dbalConfig = $database->getConnection()->getConfiguration();
$dbalConfig->setSQLLogger(
new OxidSQLLogger(
isset($trace[1]['file']) ? $trace[1]['file'] : null,
isset($trace[1]['line']) ? $trace[1]['line'] : null,
isset($trace[2]['class']) ? $trace[2]['class'] : null,
isset($trace[2]['function']) ? $trace[2]['function'] : null,
$message
)
);
}
/**
2021-03-02 15:31:09 +01:00
* @return SQLLogger|null
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
* @deprecated use non static d3GetLogger method
*/
public static function getLogger()
{
$database = oxNew(OxidEsalesDatabase::class);
return $database->d3GetLogger();
}
/**
* @return SQLLogger|null
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
*/
public function d3GetLogger()
{
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
2021-03-02 15:31:09 +01:00
/** @var Configuration $dbalConfig */
$dbalConfig = $database->getConnection()->getConfiguration();
return $dbalConfig->getSQLLogger();
2019-08-20 23:34:33 +02:00
}
2021-03-02 15:31:09 +01:00
/**
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
* @deprecated use non static d3DisableLogger method or D3StopSQLLog function
*/
public static function disableLogger()
{
$database = oxNew(OxidEsalesDatabase::class);
$database->d3DisableLogger();
}
/**
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
*/
public function d3DisableLogger()
2019-08-20 23:34:33 +02:00
{
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
2021-03-02 15:31:09 +01:00
/** @var Configuration $dbalConfig */
2019-08-20 23:34:33 +02:00
$dbalConfig = $database->getConnection()->getConfiguration();
$dbalConfig->setSQLLogger(null);
}
}