2

Is some solution in prestashop for tracking hooks call? Especially actions hooks I need to check where hooks is call and what hooks doing. It is hard to find functions for hooks. They can be everywhere.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Marcin Jaworski
  • 330
  • 2
  • 9
  • Do you want to know which hooks are called? – joseantgv Aug 31 '17 at 10:05
  • In my store sometimes DB contains double rows. Insert are in hook function. So sometimes they must run twice. I can't find when and where. And second case i find HOOK::EXEC, but i can't find where is function for it. They must be in some module. – Marcin Jaworski Aug 31 '17 at 19:10

1 Answers1

6

All hook executions are done by funcion exec from Hook class. You can add a debug trace at the beginning of this function:

public static function exec($hook_name, $hook_args = array(), $id_module = null, $array_return = false, $check_exceptions = true,
                            $use_push = false, $id_shop = null)
{
    $logger = new FileLogger(0);
    $logger->setFilename(_PS_ROOT_DIR_.'/log/debug.log');
    $e = new Exception;
    $logger->logDebug('Hook '.$hook_name.' called from:');
    $logger->logDebug($e->getTraceAsString());
    ....

This will create a debug log at /log/debug.log and will display the information about who call this hook.

Even better if you override this function to do so ;)


You can also debug all the INSERT in your DB.

Add this code

protected function q($sql, $use_cache = true)
{
    $logger = new FileLogger(0);
    $logger->setFilename(_PS_ROOT_DIR_.'/log/sql.log');
    $e = new Exception;
    $logger->logDebug('SQL '.$sql.' executed from:');
    $logger->logDebug($e->getTraceAsString());
    ...

in q function from Db class (/classes/db/Db.php).

idnovate
  • 992
  • 1
  • 5
  • 10