How can I debug my Vtiger?

Tracy library is a useful helper for everyday PHP programmers. It helps you to:

  • quickly detect and correct errors
  • log errors
  • dump variables
  • measure execution time and memory consumption

Implementation

  • Download Tracy latest version from https://github.com/nette/tracy/releases
  • Open .zip file and copy tracy to your FTP folder include
  • Edit file libraries/HTTP_Session/Session.php
  • Replace function: function start($name = ‘SessionID’, $id = null) from:
function start($name = 'SessionID', $id = null)
    {
        HTTP_Session::name($name);
        if ($id) {
            HTTP_Session::id($id);
        } elseif (is_null(HTTP_Session::detectID())) {
            HTTP_Session::id($id ? $id : uniqid(dechex(rand())));
        }
        session_start();
        if (!isset($_SESSION['__HTTP_Session_Info'])) {
            $_SESSION['__HTTP_Session_Info'] = HTTP_SESSION_STARTED;
        } else {
            $_SESSION['__HTTP_Session_Info'] = HTTP_SESSION_CONTINUED;
        }
    }

to:

function start($name = 'SessionID', $id = null)   
    {
        HTTP_Session::name($name);
        if ($id) {
            HTTP_Session::id($id);
        } elseif (is_null(HTTP_Session::detectID())) {
            HTTP_Session::id($id ? $id : uniqid(dechex(rand())));
        }
//----------- START ITS4YOU TRACY IMPLEMENTATION -----------
        $sessionid = session_id();
        if(empty($sessionid)) {
            session_start();
        }
//----------- END ITS4YOU TRACY IMPLEMENTATION -----------        
        if (!isset($_SESSION['__HTTP_Session_Info'])) {
            $_SESSION['__HTTP_Session_Info'] = HTTP_SESSION_STARTED;
        } else {
            $_SESSION['__HTTP_Session_Info'] = HTTP_SESSION_CONTINUED;
        }
    }
Session.php BEFORE
Session.php AFTER
  • Edit file index.php from:
//Overrides GetRelatedList : used to get related query
//TODO : Eliminate below hacking solution
include_once 'include/Webservices/Relation.php';
include_once 'vtlib/Vtiger/Module.php';
include_once 'includes/main/WebUI.php';

$webUI = new Vtiger_WebUI();
$webUI->process(new Vtiger_Request($_REQUEST, $_REQUEST));

to:

//Overrides GetRelatedList : used to get related query
//TODO : Eliminate below hacking solution
include_once 'config.php';
include_once 'include/Webservices/Relation.php';
include_once 'vtlib/Vtiger/Module.php';
include_once 'includes/main/WebUI.php';

//----------- START ITS4YOU TRACY IMPLEMENTATION -----------
session_start();
$session_tracy = false;
if(isset($_REQUEST['tracy'])){
    if($_REQUEST['tracy'] == 'start') {
        $_SESSION['its4you_tracy'] = true;
    } else {
        unset($_SESSION['its4you_tracy']);
    }
}
if(isset($_REQUEST['tracylog'])){
    if($_REQUEST['tracylog'] == 'start') {
        $_SESSION['its4you_tracylog'] = true;
    } else {
        unset($_SESSION['its4you_tracylog']);
    }
}
include_once 'include/tracy/src/tracy.php';
use Tracy\Debugger;
$tracy_mode = Debugger::PRODUCTION;
if(isset($_SESSION['its4you_tracy'])){
    $tracy_mode = Debugger::DEVELOPMENT;
}
$tracylog_dir = null;
if(isset($_SESSION['its4you_tracylog'])){
    $rootDirectory = vglobal('root_directory');
$tracylog_dir = $rootDirectory.'logs/';
}
Debugger::$logSeverity = E_NOTICE | E_WARNING;
Debugger::enable($tracy_mode,$tracylog_dir);
//----------- END ITS4YOU TRACY IMPLEMENTATION -----------
$webUI = new Vtiger_WebUI();
$webUI->process(new Vtiger_Request($_REQUEST, $_REQUEST));
index.php BEFORE
index.php AFTER
  • Create folder logs in root directory of Vtiger and set rights to write to this directory
  • There is a possibility that logs folder will be already there so make sure to set rights

Usage 

You can choose between Debugger error reporting or Error reporting to log directory

Debugger error reporting:

  • Enable: add to URL ?tracy=start
  • Disable: add to URL ?tracy=stop

Example: xxxxx/test/71new/index.php?tracy=start

If you successfully enabled Tracy, you should see Debugger bar like you see on the picture. Also you have option to move bar and place it where you need on your screen.

How looks Tracy in your Vtiger system

Debugger bar position

Error reporting to log directory

  • Enable: add to URL ?tracylog=start
  • Disable: add to URL ?tracylog=stop

If tracylog is enabled, all errors will be saved to error.log / exceptions.log file, which is located in logs directory.

NOTE: There can be enabled just one error reporting. Means you can’t have enabled Debugger reporting and in same time Reporting to log directory.

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *


We use cookies to improve our website. By browsing this website, you agree to our use of cookies. More info