Debug Dynamic Get option #50

Closed
opened 2017-03-03 08:18:20 +00:00 by mwweb · 21 comments
mwweb commented 2017-03-03 08:18:20 +00:00 (Migrated from github.com)

I came across where a debug to echo the query(s) to screen on the site view would be really helpful in trying to track down an issue with a query, in particular filters in a query. (I'm still fighting this one).

My thought, and I wouldn't think this would be too difficult, is to add a radio option on the dynamic gets, it would just be a simple Yes(1) or No(0).

If yes, then on compile, the following (or something similar) would be added in the site view model, between $db->setQuery($query);
// [Interpretation 1781] Load the results as a stdClass object.
$data = $db->loadObject();

This line of code is // Dump the query
echo $db->replacePrefix((string) $query);

This would simple echo the query at the top of the site view, so it could more easily be debugged. If the radio is set to no, then that echo isn't included in the compile.

Thoughts?

I came across where a debug to echo the query(s) to screen on the site view would be really helpful in trying to track down an issue with a query, in particular filters in a query. (I'm still fighting this one). My thought, and I wouldn't think this would be too difficult, is to add a radio option on the dynamic gets, it would just be a simple Yes(1) or No(0). If yes, then on compile, the following (or something similar) would be added in the site view model, between $db->setQuery($query); // [Interpretation 1781] Load the results as a stdClass object. $data = $db->loadObject(); This line of code is // Dump the query echo $db->replacePrefix((string) $query); This would simple echo the query at the top of the site view, so it could more easily be debugged. If the radio is set to no, then that echo isn't included in the compile. Thoughts?

I see your frustration, and I want to make it easier for all, yet try to avoid millions of switches...

Adding your suggested code will be simple, but I am thinking we should look further into a more complete debugging option of implementation. That gives info all over the component about many things that are usually not seen. Then to add one button on the compiler page that turns debugging on for that compile only... so it is easier to turn it on and off.

So I am thinking of one button on the compiler, that control all these debugging concepts. At this time it will only activate your request but as the project continues and more features like this is added we can use that one switch to turn it all on and off.

What do you think?

I see your frustration, and I want to make it easier for all, yet try to avoid millions of switches... Adding your suggested code will be simple, but I am thinking we should look further into a more complete debugging option of implementation. That gives info all over the component about many things that are usually not seen. Then to add one button on the compiler page that turns debugging on for that compile only... so it is easier to turn it on and off. So I am thinking of one button on the compiler, that control all these debugging concepts. At this time it will only activate your request but as the project continues and more features like this is added we can use that one switch to turn it all on and off. What do you think?
mwweb commented 2017-03-03 15:46:30 +00:00 (Migrated from github.com)

I think a global debug would be great. As another area is identified it can be expanded upon. This was just the first area that I encountered that it would be very helpful. This came about after spending hours of looking through code, looking through gets, then with that code quickly saw that it was the getint grabbing the category id rather than the item id.

I think a global debug would be great. As another area is identified it can be expanded upon. This was just the first area that I encountered that it would be very helpful. This came about after spending hours of looking through code, looking through gets, then with that code quickly saw that it was the getint grabbing the category id rather than the item id.
Peeripapo commented 2017-03-03 16:03:32 +00:00 (Migrated from github.com)

Can't you just enable Debug mode on Joomla configuration? That will give you all the all the SQL instructions used for opening the page.

Just compile, install, run the component locally and you'll get what you need.

Can't you just enable Debug mode on Joomla configuration? That will give you all the all the SQL instructions used for opening the page. Just compile, install, run the component locally and you'll get what you need.

I was thinking about that (actually wrote it, lol but then removed it in my last post), I have not used it that much.

So let me see, we will add this echo to all components and only if the current Joomla has debugging enabled will it show the echo.. is that right?

I was thinking about that (actually wrote it, lol but then removed it in my last post), I have not used it that much. So let me see, we will add this echo to all components and only if the current Joomla has debugging enabled will it show the echo.. is that right?
Peeripapo commented 2017-03-03 16:28:19 +00:00 (Migrated from github.com)

I was saying not to code anything actually. Joomla already dumps SQL code when it has debug enabled.

I was saying not to code anything actually. Joomla already dumps SQL code when it has debug enabled.

Hmmm I understand, sorry little slow today... Like I said I thought it, but have not used it enough... @mwweb please take a look at this option and let me know if this resolves the issue for you.

Hmmm I understand, sorry little slow today... Like I said I thought it, but have not used it enough... @mwweb please take a look at this option and let me know if this resolves the issue for you.
mwweb commented 2017-03-03 16:41:01 +00:00 (Migrated from github.com)

The thing with the Joomla! debug is that it outputs every single query, even if it doesn't pertain to the component. In my case, there are 26 queries logged, so each time I do a build, it sifting through 26 queries to get to the one(s) I'm looking for.

However, with the echo, it outputs to screen only the queries that pertain to the view, making it much quicker in my opinion.

The thing with the Joomla! debug is that it outputs every single query, even if it doesn't pertain to the component. In my case, there are 26 queries logged, so each time I do a build, it sifting through 26 queries to get to the one(s) I'm looking for. However, with the echo, it outputs to screen only the queries that pertain to the view, making it much quicker in my opinion.
Peeripapo commented 2017-03-03 19:13:55 +00:00 (Migrated from github.com)

There is a simple way to implement this.

Let's use the Debug lines compiler option.

#If debug is enabled add this code to the beginning of the display() function of controller of the created component (site and admin)

    JHtml::stylesheet('cms/debug.css', array(), true);
    $db = JFactory::getDBO();
    $db->setDebug(true);

    $dispatcher = JEventDispatcher::getInstance();
    $dispatcher->register('onAfterRender', function (){
        $db = JFactory::getDBO();
        $body = JResponse::getBody();
        $logs = $db->getLog();
        $logHTML = '<div id="system-debug" class="profiler j-toggle-main"><h1>JCB SQL Debug</h1>';
         foreach($logs as $log) {
            if (stripos($log, "###component_name###")){
                $logHTML .= '<div class="dbg-header"><a><h3>' . $log . '</h3></a></div>';
            }
         }
        $logHTML .= '</div>';
        $body = $body . $logHTML ;
        JResponse::setBody($body);
    });

#endif

Please review the code for the component name (without the 'com_') in the search part as I'm not familiar on which is the correct code to use.
Only tested it in admin but I'm guessing in site it will also work.

There is a simple way to implement this. Let's use the Debug lines compiler option. #If debug is enabled add this code to the beginning of the display() function of controller of the created component (site and admin) JHtml::stylesheet('cms/debug.css', array(), true); $db = JFactory::getDBO(); $db->setDebug(true); $dispatcher = JEventDispatcher::getInstance(); $dispatcher->register('onAfterRender', function (){ $db = JFactory::getDBO(); $body = JResponse::getBody(); $logs = $db->getLog(); $logHTML = '<div id="system-debug" class="profiler j-toggle-main"><h1>JCB SQL Debug</h1>'; foreach($logs as $log) { if (stripos($log, "###component_name###")){ $logHTML .= '<div class="dbg-header"><a><h3>' . $log . '</h3></a></div>'; } } $logHTML .= '</div>'; $body = $body . $logHTML ; JResponse::setBody($body); }); #endif Please review the code for the component name (without the 'com_') in the search part as I'm not familiar on which is the correct code to use. Only tested it in admin but I'm guessing in site it will also work.
Peeripapo commented 2017-03-03 19:25:31 +00:00 (Migrated from github.com)

@mwweb You can use it right now if you need it while @Llewellynvdm adds it to JCB. Just replace ###component_name### with your component's name

@mwweb You can use it right now if you need it while @Llewellynvdm adds it to JCB. Just replace ###component_name### with your component's name

@mwweb will this work for you? have you tested the code @Peeripapo gave... I will add it if it works.

This way the details will show if debugging is enabled in the Joomla global config.

@mwweb will this work for you? have you tested the code @Peeripapo gave... I will add it if it works. This way the details will show if debugging is enabled in the Joomla global config.
mwweb commented 2017-03-06 20:57:52 +00:00 (Migrated from github.com)

It looks as though it is creating an area at the bottom of the page, labeled JCB SQL Queries, but nothing is being generated.

It looks as though it is creating an area at the bottom of the page, labeled JCB SQL Queries, but nothing is being generated.
Peeripapo commented 2017-03-06 21:40:40 +00:00 (Migrated from github.com)

@mwweb did you change ###component_name### part to your components name ?

After implementing on JCB this can be automatic but for testing you need to hardcode it.

@Llewellynvdm I'd suggest adding an extra radio button in the compile view so we can distinguish visual debugging from code debugging. This will come handy on future debug actions.

@mwweb did you change ###component_name### part to your components name ? After implementing on JCB this can be automatic but for testing you need to hardcode it. @Llewellynvdm I'd suggest adding an extra radio button in the compile view so we can distinguish visual debugging from code debugging. This will come handy on future debug actions.
mwweb commented 2017-03-07 20:37:52 +00:00 (Migrated from github.com)

On categories it works fine, but not on other queries. As an example, a view that is displaying all records from company table, shows the below, rather than the query:

JCB SQL Debug

SELECT element,views,context,types,params FROM gax8s_ark_editor_inline_views WHERE element = 'com_mostwantedrealestate' LIMIT 1
SELECT a.name, a.rules FROM gax8s_assets AS a WHERE (a.name IN ('com_admin','com_ajax','com_akeeba','com_arkeditor','com_banners','com_cache','com_categories','com_checkin','com_componentbuilder','com_config','com_contact','com_content','com_contenthistory','com_cpanel','com_finder','com_installer','com_joomlaupdate','com_languages','com_login','com_mailto','com_media','com_menus','com_messages','com_modules','com_mostwantedrealestate','com_newsfeeds','com_plugins','com_postinstall','com_redirect','com_search','com_sermondistributor','com_tags','com_templates','com_users','com_wrapper') OR a.name = 'root.1')
On categories it works fine, but not on other queries. As an example, a view that is displaying all records from company table, shows the below, rather than the query: JCB SQL Debug ``` SELECT element,views,context,types,params FROM gax8s_ark_editor_inline_views WHERE element = 'com_mostwantedrealestate' LIMIT 1 SELECT a.name, a.rules FROM gax8s_assets AS a WHERE (a.name IN ('com_admin','com_ajax','com_akeeba','com_arkeditor','com_banners','com_cache','com_categories','com_checkin','com_componentbuilder','com_config','com_contact','com_content','com_contenthistory','com_cpanel','com_finder','com_installer','com_joomlaupdate','com_languages','com_login','com_mailto','com_media','com_menus','com_messages','com_modules','com_mostwantedrealestate','com_newsfeeds','com_plugins','com_postinstall','com_redirect','com_search','com_sermondistributor','com_tags','com_templates','com_users','com_wrapper') OR a.name = 'root.1') ```
Peeripapo commented 2017-03-14 14:39:34 +00:00 (Migrated from github.com)

What are you replacing ###component_name### with ?

What are you replacing ###component_name### with ?
mwweb commented 2017-03-14 16:36:03 +00:00 (Migrated from github.com)

In my case, my component is com_mostwantedrealestate, and that is what I'm replacing ###component_name### with.

In my case, my component is com_mostwantedrealestate, and that is what I'm replacing ###component_name### with.

Okay I have not implemented anything as yet, I just have not had the time.

But if you can come with a ready script (that is tried and tested) that will work for each site and custom admin view that makes use of the DynamicGet DB query builder.

Then I will make the effort to add it.

At this time it seems best that the script should auto show if debugging is turned on in the Joomla global settings.

Thanks for your help in this regard 👍

Okay I have not implemented anything as yet, I just have not had the time. But if you can come with a ready script (that is tried and tested) that will work for each site and custom admin view that makes use of the DynamicGet DB query builder. Then I will make the effort to add it. At this time it seems best that the script should auto show if debugging is turned on in the Joomla global settings. Thanks for your help in this regard :+1:
Peeripapo commented 2017-03-14 20:20:25 +00:00 (Migrated from github.com)

@mwweb Try it without the "com_" prefix, just : "mostwantedrealestate". That should do it.

@Llewellynvdm it is working OK, it's the prefix that shouldn't be used in the replacement part. Using it along with joomla global debug seems fine to me for now. I'll fix the code to reflect that condition.

@mwweb Try it without the "com_" prefix, just : "mostwantedrealestate". That should do it. @Llewellynvdm it is working OK, it's the prefix that shouldn't be used in the replacement part. Using it along with joomla global debug seems fine to me for now. I'll fix the code to reflect that condition.
mwweb commented 2017-03-15 20:47:42 +00:00 (Migrated from github.com)

OK, it appears to be working correctly. It actually, kind of, showed me where to start digging on my of my views that is having issues.

OK, it appears to be working correctly. It actually, kind of, showed me where to start digging on my of my views that is having issues.

Where are we with this? do you have a local repo or some code snippet I can look at?

Where are we with this? do you have a local repo or some code snippet I can look at?

@Peeripapo it seems little heavy to have the above code run each time a view is loaded... can you streamline it some more?

@Peeripapo it seems little heavy to have the above code run each time a view is loaded... can you streamline it some more?

Please show me a view.html.php with this code in action.

Please show me a _view.html.php_ with this code in action.
Sign in to join this conversation.
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#50
No description provided.