8
0
Bifurcation 0
oxid-sql-logger/src/OxidEsalesDatabase.php

99 lignes
2.8 KiB
PHP
Brut Vue normale Historique

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;
2022-08-18 14:18:43 +02:00
use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
2019-08-20 23:34:33 +02:00
/**
* Class OxidEsalesDatabase
* Is a depenction injection Helper Class
*/
2022-08-18 14:18:43 +02:00
class OxidEsalesDatabase extends Database
2019-08-20 23:34:33 +02:00
{
2021-03-02 15:31:09 +01:00
/**
* @param null $message
*
2022-08-18 14:18:43 +02:00
* @throws DatabaseConnectionException
2021-03-02 15:31:09 +01:00
* @deprecated use non static d3EnableLogger method or D3StartSQLLog function
*/
public static function enableLogger($message = null)
{
$database = oxNew(OxidEsalesDatabase::class);
$database->d3EnableLogger($message);
}
/**
2022-08-18 14:18:43 +02:00
* @throws 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);
2022-08-18 14:18:43 +02:00
$database = DatabaseProvider::getDb( 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(
2022-08-18 14:18:43 +02:00
$trace[1]['file'] ?? null,
$trace[1]['line'] ?? null,
$trace[2]['class'] ?? null,
$trace[2]['function'] ?? null,
$message
)
);
}
/**
2021-03-02 15:31:09 +01:00
* @return SQLLogger|null
2022-08-18 14:18:43 +02:00
* @throws DatabaseConnectionException
2021-03-02 15:31:09 +01:00
* @deprecated use non static d3GetLogger method
*/
public static function getLogger()
{
$database = oxNew(OxidEsalesDatabase::class);
return $database->d3GetLogger();
}
/**
* @return SQLLogger|null
2022-08-18 14:18:43 +02:00
* @throws DatabaseConnectionException
*/
public function d3GetLogger()
{
2022-08-18 14:18:43 +02:00
$database = DatabaseProvider::getDb( 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
/**
2022-08-18 14:18:43 +02:00
* @throws DatabaseConnectionException
2021-03-02 15:31:09 +01:00
* @deprecated use non static d3DisableLogger method or D3StopSQLLog function
*/
public static function disableLogger()
{
$database = oxNew(OxidEsalesDatabase::class);
$database->d3DisableLogger();
}
/**
2022-08-18 14:18:43 +02:00
* @throws DatabaseConnectionException
*/
public function d3DisableLogger()
2019-08-20 23:34:33 +02:00
{
2022-08-18 14:18:43 +02:00
$database = DatabaseProvider::getDb( 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();
2022-08-18 14:18:43 +02:00
$dbalConfig->setSQLLogger();
2019-08-20 23:34:33 +02:00
}
}