diff --git a/src/OxidEsalesDatabase.php b/src/OxidEsalesDatabase.php index c9502dc..6101d92 100644 --- a/src/OxidEsalesDatabase.php +++ b/src/OxidEsalesDatabase.php @@ -8,6 +8,7 @@ namespace D3\OxidSqlLogger; use Doctrine\DBAL\Configuration; +use Doctrine\DBAL\Logging\SQLLogger; /** * Class OxidEsalesDatabase @@ -15,6 +16,18 @@ use Doctrine\DBAL\Configuration; */ class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database { + /** + * @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 */ @@ -23,6 +36,7 @@ class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrin $trace = debug_backtrace((PHP_VERSION_ID < 50306) ? 2 : DEBUG_BACKTRACE_IGNORE_ARGS); $database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC); + /** @var Configuration $dbalConfig */ $dbalConfig = $database->getConnection()->getConfiguration(); $dbalConfig->setSQLLogger( new OxidSQLLogger( @@ -36,22 +50,45 @@ class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrin } /** - * @return mixed + * @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); + /** @var Configuration $dbalConfig */ $dbalConfig = $database->getConnection()->getConfiguration(); return $dbalConfig->getSQLLogger(); } + /** + * @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() { $database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC); + /** @var Configuration $dbalConfig */ $dbalConfig = $database->getConnection()->getConfiguration(); $dbalConfig->setSQLLogger(null); } diff --git a/src/functions.php b/src/functions.php index d6a9a2f..fdc0f83 100644 --- a/src/functions.php +++ b/src/functions.php @@ -17,3 +17,11 @@ function D3StopSQLLog() $database = oxNew(\D3\OxidSqlLogger\OxidEsalesDatabase::class); $database->d3DisableLogger(); } + +function D3AddSQLLogItem($message) +{ + /** @var \D3\OxidSqlLogger\OxidEsalesDatabase $database */ + $database = oxNew(\D3\OxidSqlLogger\OxidEsalesDatabase::class); + $database->d3GetLogger()->startQuery($message); + $database->d3GetLogger()->stopQuery($message); +}