Debugging

Version 0 14.03.2024

Different ways to debug application

PHP

p()

Function to render variable on screen.

If $variable is array -> render content.

If $variable is object -> render classname and object info.

Render content of a $variable:

p('Variable', $variable);

loki()

Function to render variable on loki -file.

If $variable is array -> render content.

If $variable is object -> render classname and object info.

Loki can be viewed form: Header / Preferences / Loki

loki('Variable', $variable);

Log

Class to add information on requests -database. Information can be viewed form: Header / Preferences / Requests

See: Log

Add message to Log:

Log::addMessage('Add text to request additional info');

Add time to log:

$Time = Log::addTime('My time');
$Time->addMessage('Additional message');

Time with execute secs:

$Time = Log::addTime('My time');
// SOME CODE
$Time->stop('Additional END message');

Log::startTime('My time', 'Additional message');
// SOME CODE
Log::stopTime('My time', 'Additional END message');

Add counter to log. Counts number of callsand total time.

$Counter = Log::addCounter('My time','Additional message');
// SOME CODE
$Counter->stop('Additional END message');

Log::startCounter('My counter', 'Additional message');
// SOME CODE
Log::stopCounter('My counter', 'Additional END message');

Add log for pages query:

$Pages = $this->get('pages','orders')->addWhere('status','New');
$Pages->setLogSql(Array(
    'title' => 'MyLog',
    'description' => 'New orders'
));
// Saves query to log when executed

Add log for Database query:

$Database = $this->get('database');
$Database->setLogSql(Array(
    'title' => 'MyTitle',
    'description' => 'MyDescription,
    'min' => 0.1 // Save if request time > 0.1
));
$data = $Database->fetchAll("SELECT ...SOME_TEXT_HERE...", Array('name' => 'value'));

API SQL -clause

Save sql clause to Log:

api/table/order/records?LOG_SQL=true

Define name and message for the log:

api/table/order/records?LOG_SQL[title]=MyName&LOG_SQL[description]=MyDescription

NOTE: You can add SHOW_SQL=1 parameter to your api call. This will render info about created SQL -clause (renders on screen, will break the response json!)

Notification

Add text to user notifications.

See: Notification

$this->get('notification', array(
   'title' => 'Sky is blue',
   'type' => 'error',
   'description' => 'And Im green',
   'color' => 'green'
));

Api->addMessage()

When creating custom API -responces, you can add messages to response.messages[]. If editmode is ON, these messages are shown in user notifications.

$Api->addMessage(Array(
    'type' => 'error', // error, deprecated, notification, message
    'title' => 'Somethig wrong',
    'description' => 'If you are a wizard, you will see this.'
));

fwrite()

Write data to file in salaiset -folder:

$file = $this->get('account')->getStorage()->getDir().'/mylog.txt';
$fp = fopen($file, "a");
fwrite($fp, "Mytext - add linebreak!");
fclose(fp);

You should not need to do this.

You should not need to do this. Contact developer gods to do stuff, so you dont need to do this!

PHP console

You can execute custom PHP scripts in: Header / Preferences / PHP console.

Run method to update data in newly added field:

$Pages = $this->get('pages','order')
    ->addWhere('orders_total','Empty')
    ->setLimit(100);

p('Orders', $Pages);
foreach ( $Pages as $i => $Page ){
    p('$Page '+$i, $Page);
    $Page->updateOrdersTotal();
    $Page->saveChangesToServer();
}

MySQL query

You can execute custom SQL queries in: Header / Preferences / SQL Query.

List all tables in database:

SHOW TABLE STATUS

Javascript

Use browser console to log data in javascript.

console.log('Title', variable, otherVariable);