Jump to content
adrian

Tracy Debugger

Recommended Posts

I got the same issue as szabesz on Win, though I haven't checked it with the newest version.

  • Like 1

Share this post


Link to post
Share on other sites
However, it does open the compiled file in cache instead of the original ones.

Do you have any ideas why?

Hey guys,

I am not sure what is going on. To make this work I have made a small tweak to the Tracy core (hopefully only temporary as I have asked them about a way to publicly modify the filepath) - you can see it here: https://github.com/adrianbj/TracyDebugger/blob/master/tracy/src/Tracy/Dumper.php#L111

Would you mind taking a look at that and debugging why it might not be working - just find out what $file contains before and after that str_replace

I can imagine on Windows I probably need to replace all the "/" with DIRECTORY_SEPARATOR but it sounds like @szabesz is on a Mac so what I have should work?

Thanks to both of you for helping out with this.

  • Like 1

Share this post


Link to post
Share on other sites

$file contains an empty string, but even before this line:

list($file, $line, $code) = $loc ? self::findLocation() : NULL;

I cannot seem to find any occurrence of $file before this line, so I suppose that is why it is empty in the first place.

  • Like 1

Share this post


Link to post
Share on other sites

list() populates the $file variable from the result of findLocation(), or NULL if $loc returns false. 

I am not sure what's going on, but if your edit links are to the compiled file, then it would suggest that $file is being populated. Could you maybe check the value of $loc and self::findLocation() before that list() call please?

  • Like 1

Share this post


Link to post
Share on other sites

$loc is 0

self::findLocation() :

Array
(
 [0] => .../site/assets/cache/FileCompiler/site/modules/TracyDebugger/ProcesswireInfoPanel.inc
 [1] => 162
 [2] => Dumper::toHtml(\ProcessWire\wire('page'), array(Dumper::COLLAPSE => false))
)

EDIT: and similar values, since toHtml() gets called a lot of times...

Edited by szabesz
  • Like 1

Share this post


Link to post
Share on other sites

Maybe it has something to do with php version?

Share this post


Link to post
Share on other sites

Is $loc always 0 ? If so, then that's the problem.

I get it 0 sometimes - when the first result of findLocation() is a module file. But when it's a template file, $loc returns 7

At least from this:

[0] => .../site/assets/cache/FileCompiler/site/modules/TracyDebugger/ProcesswireInfoPanel.inc

I can see that the path in $file is matching something that the next line can remove the "/site/assets/cache/FileCompiler" component to make it the path to the original file.

Can you please clarify that $loc is always 0? What if you force it to 7 on line 100?

Thanks again for your help with this!

  • Like 1

Share this post


Link to post
Share on other sites

@matjazp: I tested with php 5.6, 5.5 and 5.4 and did not make a difference.

$loc is always 0. I put $loc = 7; on line 100 and I still get the compiled file. But this time:
Before the Tracy hack str_replace $file is:
.../site/assets/cache/FileCompiler/site/modules/TracyDebugger/ProcesswireInfoPanel.inc

after modifying the string we get:
.../site/modules/TracyDebugger/ProcesswireInfoPanel.inc

The above is 7 times, and we have "VariablesPanel.inc" 2 times at the end.

So "/site/assets/cache/FileCompiler" is removed as expected, but how is this path related to the my template file? Do not bother explaining it though, I was just wondering a bit :)

  • Like 1

Share this post


Link to post
Share on other sites

Thanks!

I am wondering what links are actually showing the compiled file? Can you show a screenshot of the link you are trying to click on?

Here are some examples showing it working as expected:

Link from a dump()

post-985-0-86435700-1457470273_thumb.png

Link from a barDump()

post-985-0-63403500-1457470274_thumb.png

I am starting to think you are talking about other links, but I am not sure what!

  • Like 1

Share this post


Link to post
Share on other sites

Ooops, yeah, I am clicking on the link in the error panel:

post-4029-0-02528600-1457471069_thumb.jp

  • Like 1

Share this post


Link to post
Share on other sites

Oh, I see - I have been running in StrictMode, so haven't been noticing that - there is another location that I need to add that hack to change the path. I'll get that fix committed shortly.

@tpr - is this the case for you also? Do the links from dump() and barDump() calls get converted properly?

  • Like 1

Share this post


Link to post
Share on other sites

I have just tested and dump() and barDump() calls are ok. However, I have another question: Tracy\Debugger::dump(); and the others used to work but now I get:  Class 'ProcessWire\Tracy\Debugger' not found and Class 'ProcessWire\TD' not found   so only the shortcut methods work (ProcessWire 3.0.10 and the template file is in namespace ProcessWire; ).

Share this post


Link to post
Share on other sites

I can't test it right now but I also clicked on the link in the error panel.

  • Like 2

Share this post


Link to post
Share on other sites

I have just tested and dump() and barDump() calls are ok. However, I have another question: Tracy\Debugger::dump(); and the others used to work but now I get:  Class 'ProcessWire\Tracy\Debugger' not found and Class 'ProcessWire\TD' not found   so only the shortcut methods work (ProcessWire 3.0.10 and the template file is in namespace ProcessWire; ).

Great - thanks for confirming that the paths are correct for dump() and barDump()

The class not found error will be because of the template being the ProcessWire namespace. If you are doing that, then you'll need prepend a "\" to your calls, eg:

\Tracy\Debugger::dump('Test \Tracy\Debugger::dump');
\TD::dump('Test \TD::dump');

and then they'll work fine.

  • Like 1

Share this post


Link to post
Share on other sites

Ok, the latest version now correctly modifies the editor path to the file in the errors panel, as well as dump() and barDump().

Thanks again @szabesz for helping so much to figure this out - sorry we got so sidetracked along the way :)

  • Like 3

Share this post


Link to post
Share on other sites

That's okay. Happy to help :) Your Tracy Debugger module is a godsend!

  • Like 1

Share this post


Link to post
Share on other sites

@matjazp: I tested with php 5.6, 5.5 and 5.4 and did not make a difference.

In PHP 5, list() assigns the values starting with the right-most parameter. In PHP 7, list() starts with the left-most parameter. But I see that adrian fixed it...

  • Like 1

Share this post


Link to post
Share on other sites

I'm playing with Editor Protocol Handler set to "editor://open/?file=%file&line=%line" using UltraEdit. The problem I have is that editor won't open correct file if %line is empty string. So 

editor://open/?file=myfile.txt&line=1

is ok, while 

editor://open/?file=myfile.txt&line=

is not ok. This is bug in UltraEdit. Can you help by providing line number 1, if there is no line number?

  • Like 1

Share this post


Link to post
Share on other sites

Finally got the protocol handler thing to work on Win(8), thanks!

  • Like 2

Share this post


Link to post
Share on other sites
In PHP 5, list() assigns the values starting with the right-most parameter. In PHP 7, list() starts with the left-most parameter. But I see that adrian fixed it...

@matjazp - thanks for the info on the changes to list() in PHP 7 - I hadn't seen that yet, although from reading about it, I don't think it actually affects that code. 

This is bug in UltraEdit. Can you help by providing line number 1, if there is no line number?

No problem at all - I assume the only places where this is affecting you are the links to the template file from the PW Info panel (both in the template info section and the icon at the bottom)? Are there any other locations with links without line numbers that I haven't thought of?

Finally got the protocol handler thing to work on Win(8), thanks!

Awesome - care to share any tips for setting it up? Did you work with this file: https://github.com/adrianbj/TracyDebugger/blob/master/tracy/tools/open-in-editor/open-editor.js

Thanks!

Share this post


Link to post
Share on other sites

Here's how I set up the editor protocol handler on Windows 8.

I started out using this but needed to modify a few things.

Note that I'm using a portable version of PhpStorm (using my own yaP launcher), so installed versions may need some modifications.

Module settings, "Editor protocol handler" field:

pstorm://open/?url=file://%file&line=%line

There's "editor.reg" file with these contents:

REGEDIT4

[HKEY_CLASSES_ROOT\pstorm]
@="URL:pstorm Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\pstorm\shell\open\command]
@="wscript \"D:\\portables\\PhpStorm\\run-editor.js\" \"%1\""

and also its counter-part, which removes registry key, "editor-unreg.reg":

REGEDIT4

[-HKEY_CLASSES_ROOT\pstorm]

The "editor.reg" needs to be merged to the registry - double click on it, or using regedit.exe and "Import" from the menu.

Note that you need to do this in admin mode, otherwise registry settings won't be added.

"editor-unreg" is only needed to clean the registry, possibly you won't ever need this.

Then you'll need a file named "run-editor.js" in the directory you've set in "editor.reg"

There's some hardcoded paths, project name and window title in the code below - these still need revisit.

"run-editor.js" file contents:

var settings = {
	// Set to 'true' (without quotes) if run on Windows 64bit. Set to 'false' (without quotes) otherwise.
	x64: true,

	// Set to folder name, where PhpStorm was installed to (e.g. 'PhpStorm')
	folder_name: 'PhpStorm 9.0',

	// Set to window title (only text after dash sign), that you see, when switching to running PhpStorm instance
	window_title: 'PhpStorm PS-145.61.14',

	// In case your file is mapped via a network share and paths do not match.
	// eg. /var/www will can replaced with Y:/
	projects_basepath: '/YOUR_PATH_HERE',
	projects_path_alias: 'D:/Projects/YOUR_PROJECT_NAME'
};

// don't change anything below this line, unless you know what you're doing
var	url = WScript.Arguments(0),
	match = /^pstorm:\/\/open\/\?url=file:\/\/(.+)&line=(\d+)$/.exec(url),
	project = '',
	editor = "D:\\portables\\PhpStorm\\PhpStormPortable.exe";

if (match) {

	var	shell = new ActiveXObject('WScript.Shell'),
		file_system = new ActiveXObject('Scripting.FileSystemObject'),
		file = decodeURIComponent(match[1]).replace(/\+/g, ' '),
		search_path = file.replace(/\//g, '\\');

	if (settings.projects_basepath != '' && settings.projects_path_alias != '') {
		file = file.replace(new RegExp('^' + settings.projects_basepath), settings.projects_path_alias);
	}

	// note: uncomment to see the popup message (for testing)
	//shell.Popup(file, 0, "My Title", 64);

	while (search_path.lastIndexOf('\\') != -1) {
		search_path = search_path.substring(0, search_path.lastIndexOf('\\'));

		if(file_system.FileExists(search_path+'\\.idea\\.name')) {
			project = search_path;
			break;
		}
	}

	if (project != '') {
		editor += ' "%project%"';
	}

	editor += ' --line %line% "%file%"';

	var command = editor.replace(/%line%/g, match[2])
						.replace(/%file%/g, file)
						.replace(/%project%/g, project)
						.replace(/\//g, '\\');

	shell.Exec(command);
	shell.AppActivate(settings.window_title);
}

That's all. Clicking on a Tracy error line load PhpStorm at the file/line specified, and also brings the application to the front (activates it).

If you encounter errors, try to "debug" using popup messages (see "shell.Popup(..." line in the js file).

  • Like 4

Share this post


Link to post
Share on other sites

Awesome writeup - thanks @tpr!

Share this post


Link to post
Share on other sites
On 3/9/2016 at 3:47 PM, adrian said:

No problem at all - I assume the only places where this is affecting you are the links to the template file from the PW Info panel (both in the template info section and the icon at the bottom)? Are there any other locations with links without line numbers that I haven't thought of?

Yes, I was talking about template files.

On 3/9/2016 at 3:47 PM, adrian said:

Awesome - care to share any tips for setting it up? Did you work with this file: https://github.com/adrianbj/TracyDebugger/blob/master/tracy/tools/open-in-editor/open-editor.js

Huh, didn't know the file was there :-), I was using https://pla.nette.org/en/how-open-files-in-ide-from-debugger (link provided by @tpr) and modified just a little. My .js file is very simple, @tpr went few steps forward, here are the files:

editor.reg:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\editor]
@="URL:editor Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\editor\shell\open\command]
@="wscript //E:jscript \"D:\\editor.js\" \"%1\""

and editor.js:

// full path to the editor, you have to use double backslash
var editor = '"C:\\Program Files\\IDM Computer Solutions\\UltraEdit\\uedit64.exe" "%file%" -l%line%';

var url = WScript.Arguments(0);
var match = /^editor:\/\/open\/\?file=(.+)&line=(\d*)$/.exec(url);

if (match) {
    var file = decodeURIComponent(match[1]).replace(/\+/g, ' ').replace(/\//g, "\\");
    var command = editor.replace(/%line%/g, match[2]).replace(/%file%/g, file);
    var shell = new ActiveXObject("WScript.Shell");
    shell.Exec(command.replace(/\\/g, '\\\\'));
}

 

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for your writeup also @matjazp - great to have this stuff documented!

I have committed a fix for the blank line number issue you were having. Please let me know if it works now.

New Feature

I have just added a new feature - it's a bit experimental, and I am not sure just how useful it is so would appreciate feedback.

It provides the ability to insert debugging statements (actually any code you want) at designtaed lines in the compiled template at runtime. I see this as useful if you want to quickly debug something on a live site without having to edit the files on the server.

In this example I am inserting two barDump (bd) statements into the home.php template file at lines 61 and 63 and noting which one is before the variable is iterated and which one is after. 

post-985-0-00563400-1457543595_thumb.png

The code for the home.php file looks like this:

post-985-0-29333000-1457543639_thumb.png

And this is the result in the dumps panel:

post-985-0-60835300-1457543721_thumb.png

Obviously the scenario and the inserted debug statements could be quite different, but hopefully you get the idea.

Note: Any lines of code inserted like this are only executed for superusers, so you could even use this as a way to insert lines of code that affect the output on the page without it affecting other users and guests.

Also, be sure to remove any statements when you are done debugging, because the template file is re-compiled every time the page is loaded when this field is populated.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By d'Hinnisdaël
      Happy new year, everybody 🥬
      I've been sitting on this Dashboard module I made for a client and finally came around to cleaning it up and releasing it to the wider public. This is how it looks.
      ProcessWire Dashboard

      If anyone is interested in trying this out, please go ahead! I'd love to get some feedback on it. If this proves useful and survives some real-world testing, I'll add this to the module directory.
      Download
      You can find the latest release on Github.
      Documentation
      Check out the documentation to get started. This is where you'll find information about included panel types and configuration options.
      Custom Panels
      My goal was to make it really simple to create custom panels. The easiest way to do that is to use the panel type template and have it render a file in your templates folder. This might be enough for 80% of all use cases. For anything more complex (FormBuilder submissions? Comments? Live chat?), you can add new panel types by creating modules that extend the DashboardPanel base class. Check out the documentation on custom panels or take a look at the HelloWorld panel to get started. I'm happy to merge any user-created modules into the main repo if they might be useful to more than a few people.
       Disclaimer
      This is a pre-release version. Please treat it as such — don't install it on production sites. Just making sure 🍇
      Roadmap
      These are the things I'm looking to implement myself at some point. The wishlist is a lot longer, but those are the 80/20 items that I probably won't regret spending time on.
      Improve documentation & add examples ⚙️ Panel types Google Analytics ⚙️ Add new page  🔥 Drafts 🔥 At a glance / Page counter 404s  Layout options Render multiple tabs per panel panel groups with heading and spacing between ✅ panel wrappers as grid item (e.g. stacked notices) ✅ Admin themes support AdminThemeReno and AdminThemeDefault ✅ Shortcuts panel add a table layout with icon, title & summary ✅ Chart panel add default styles for common chart types ✅ load chart data from JS file (currently passed as PHP array) Collection panel support image columns ✅ add buttons: view all & add new ✅
    • By Pip
      Hi everyone!
      I'm trying out the Login/Register module for my site. Noted that the module assigns the newly registered user to login-register role. 
      Once you modify the login-register role's permissions, particularly adding page-edit, the new member role will be set to guest. 
      Thing is I'd like to grant my new users the power to create their own pages. Any advice? 
      Thanks. 
    • By Gadgetto
      SnipWire - Snipcart integration for ProcessWire
      Snipcart is a powerful 3rd party, developer-first HTML/JavaScript shopping cart platform. SnipWire is the missing link between Snipcart and the content management framework ProcessWire.
      With SnipWire, you can quickly turn any ProcessWire site into a Snipcart online shop. The SnipWire plugin helps you to get your store up and running in no time. Detailed knowledge of the Snipcart system is not required.
      SnipWire is free and open source licensed under Mozilla Public License 2.0! A lot of work and effort has gone into development. It would be nice if you could donate an amount to support further development:

      Status update links (inside this thread) for SnipWire development
      2020-07-03 -- SnipWire 0.8.7 (beta) released! Fixes some small bugs and adds an indicator for TEST mode 2020-04-06 -- SnipWire 0.8.6 (beta) released! Adds support for Snipcart subscriptions and also fixes some problems 2020-03-21 -- SnipWire 0.8.5 (beta) released! Improves SnipWires webhooks interface and provides some other fixes and additions 2020-03-03 -- SnipWire 0.8.4 (beta) released! Improves compatibility for Windows based Systems. 2020-03-01 -- SnipWire 0.8.3 (beta) released! The installation and uninstallation process has been heavily revised. 2020-02-08 -- SnipWire 0.8.2 (beta) released! Added a feature to change the cart and catalogue currency by GET, POST or SESSION param 2020-02-03 -- SnipWire 0.8.1 (beta) released! All custom classes moved into their own namespaces. 2020-02-01 -- SnipWire is now available via ProcessWire's module directory! 2020-01-30 -- SnipWire 0.8.0 (beta) first public release! (module just submitted to the PW modules directory) 2020-01-28 -- added Custom Order Fields feature (first SnipWire release version is near!) 2020-01-21 -- Snipcart v3 - when will the new cart system be implemented? 2020-01-19 -- integrated taxes provider finished (+ very flexible shipping taxes handling) 2020-01-14 -- new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 -- orders filter, order details, download + resend invoices, refunds 2019-10-18 -- list filters, REST API improvements, new docs platform, and more ... 2019-08-08 -- dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 -- taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 -- FieldtypeSnipWireTaxSelector 2019-05-25 -- SnipWire will be free and open source Plugin Key Features
      Fast and simple store setup Full integration of the Snipcart dashboard into the ProcessWire backend (no need to leave the ProcessWire admin area) Browse and manage orders, customers, discounts, abandoned carts, and more Multi currency support Custom order and cart fields Process refunds and send customer notifications from within the ProcessWire backend Process Abandoned Carts + sending messages to customers from within the ProcessWire backend Complete Snipcart webhooks integration (all events are hookable via ProcessWire hooks) Integrated taxes provider (which is more flexible then Snipcart own provider) Useful Links
      SnipWire in PW modules directory SnipWire Docs (please note that the documentation is a work in progress) SnipWire @GitHub (feature requests and suggestions for improvement are welcome - I also accept pull requests) Snipcart Website  

       
      ---- INITIAL POST FROM 2019-05-25 ----
       
    • By Sten
      Hello
      Till now I hacked something with the twig template but it works no more with new PW versions so I look forward to create a module. I am working on a site in multiple languages : French, English, Italian, German, Spanish, Portuguese, Hebrew, Russian. The new posts are entered in any language with a field for language. Till now, I got twig files to get the translations with constants defined for each part of the pages.
      So I'd like to create a module to include theses files added according to the url /fr/en/...
      Have you some observations to do before I begin about the direction to take ?
      Thank you
    • By ukyo
      Mystique Module for ProcessWire CMS/CMF
      Github repo : https://github.com/trk/Mystique
      Mystique module allow you to create dynamic fields and store dynamic fields data on database by using a config file.
      Requirements
      ProcessWire 3.0 or newer PHP 7.0 or newer FieldtypeMystique InputfieldMystique Installation
      Install the module from the modules directory:
      Via Composer:
      composer require trk/mystique Via git clone:
      cd your-processwire-project-folder/ cd site/modules/ git clone https://github.com/trk/Mystique.git Module in live reaction with your Mystique config file
      This mean if you remove a field from your config file, field will be removed from edit screen. As you see on youtube video.
      Using Mystique with your module or use different configs path, autoload need to be true for modules
      Default configs path is site/templates/configs/, and your config file name need to start with Mystique. and need to end with .php extension.
      Adding custom path not supporting anymore !
      // Add your custom path inside your module class`init` function, didn't tested outside public function init() { $path = __DIR__ . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR; Mystique::add($path); } Mystique module will search site/modules/**/configs/Mystique.*.php and site/templates/Mystique.*.php paths for Mystique config files.
      All config files need to return a PHP ARRAY like examples.
      Usage almost same with ProcessWire Inputfield Api, only difference is set and showIf usage like on example.
      <?php namespace ProcessWire; /** * Resource : testing-mystique */ return [ 'title' => __('Testing Mystique'), 'fields' => [ 'text_field' => [ 'label' => __('You can use short named types'), 'description' => __('In file showIf working like example'), 'notes' => __('Also you can use $input->set() method'), 'type' => 'text', 'showIf' => [ 'another_text' => "=''" ], 'set' => [ 'showCount' => InputfieldText::showCountChars, 'maxlength' => 255 ], 'attr' => [ 'attr-foo' => 'bar', 'attr-bar' => 'foo' ] ], 'another_text' => [ 'label' => __('Another text field (default type is text)') ] ] ]; Example:
      site/templates/configs/Mystique.seo-fields.php <?php namespace ProcessWire; /** * Resource : seo-fields */ return [ 'title' => __('Seo fields'), 'fields' => [ 'window_title' => [ 'label' => __('Window title'), 'type' => Mystique::TEXT, // or InputfieldText 'useLanguages' => true, 'attr' => [ 'placeholder' => __('Enter a window title') ] ], 'navigation_title' => [ 'label' => __('Navigation title'), 'type' => Mystique::TEXT, // or InputfieldText 'useLanguages' => true, 'showIf' => [ 'window_title' => "!=''" ], 'attr' => [ 'placeholder' => __('Enter a navigation title') ] ], 'description' => [ 'label' => __('Description for search engines'), 'type' => Mystique::TEXTAREA, 'useLanguages' => true ], 'page_tpye' => [ 'label' => __('Type'), 'type' => Mystique::SELECT, 'options' => [ 'basic' => __('Basic page'), 'gallery' => __('Gallery'), 'blog' => __('Blog') ] ], 'show_on_nav' => [ 'label' => __('Display this page on navigation'), 'type' => Mystique::CHECKBOX ] ] ]; Searching data on Mystique field is limited. Because, Mystique saving data to database in json format. When you make search for Mystique field, operator not important. Operator will be changed with %= operator.
      Search example
      $navigationPages = pages()->find('my_mystique_field.show_on_nav=1'); $navigationPages = pages()->find('my_mystique_field.page_tpye=gallery');
×
×
  • Create New...