Commit dcbfe5ac authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Ajout fonction sqlLogInErrorLog() pour afficher dans l'error_log toutes les requêtes SQL exécutées

parent 239d0d96
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
CHANGELOG
=========

6.6.2 (05/12/2025)
------------------

- Ajout fonction sqlLogInErrorLog() pour afficher dans l'error_log toutes les requêtes SQL exécutées 


6.6.1 (30/10/2025)
------------------

+5 −0
Original line number Diff line number Diff line
@@ -76,3 +76,8 @@ function sqlLog($display=true)
{
    return \UnicaenCode\Util::sqlLog($display);
}

function sqlLogInErrorLog()
{
    return \UnicaenCode\Util::sqlLogInErrorLog();
}
 No newline at end of file
+38 −1
Original line number Diff line number Diff line
@@ -103,6 +103,16 @@ class Util



    public static function sqlLogInErrorLog()
    {
        if (self::getEntityManager()) {
            $sqlLogger          = new ErrorSQLLogger();
            self::getEntityManager()->getConfiguration()->setSQLLogger($sqlLogger);
        }
    }



    /**
     * @param string|QueryBuilder $sql
     */
@@ -814,7 +824,7 @@ class Util



    private static function includeSqlFormatter()
    public static function includeSqlFormatter()
    {
        try {
            $config = self::getContainer()->get(ConfigService::class);
@@ -868,6 +878,33 @@ class EchoSQLLogger implements \Doctrine\DBAL\Logging\SQLLogger



    /**
     * {@inheritdoc}
     */
    public function stopQuery()
    {
    }
}


class ErrorSQLLogger implements \Doctrine\DBAL\Logging\SQLLogger
{

    /**
     * {@inheritdoc}
     */
    public function startQuery($sql, ?array $params = null, ?array $types = null)
    {
        if (Util::includeSqlFormatter()) {
            $sql = \SqlFormatter::format($sql, false);
        }
        error_log(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
        error_log($sql);
        error_log(var_export($params,true));
    }



    /**
     * {@inheritdoc}
     */