When running devel under drush dpm(), dvm() etc fail to function. This means that 2 debug systems need to be implemented when trying to debug problems through drush and the browser.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

skwashd’s picture

Status: Active » Needs review
FileSize
3.19 KB

The attached patch checks to see if the script is running under drush and if so messages are routed to devel_set_message() which properly handles user feedback depending on which environment it using.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Looks pretty handy to me. I'll wait a bit for feedback before committing

Dave Reid’s picture

Should we use drupal_is_cli() rather than a custom devel_is_drush()?

skwashd’s picture

Status: Reviewed & tested by the community » Needs review

@DaveReid, If cron.php is called via the PHP cli it will break as drupal_is_cli() will return TRUE, but it won't be running via drush. I use a custom devel_is_drush() style functions in my in house custom modules which which have drush specific behaviour.

Another problem is that drupal_is_cli() is only available for D7+

If there is a more reliable way of detecting drush, then I'm happy to change the function.

Dave Reid’s picture

devel_set_message() will still handle message if drush isn't being used though right? And cron should be running as anonymous so messges are destroyed anyway.

msonnabaum’s picture

Yeah, I'd rather not depend on drupal_is_cli() since this would be nice to have in d6. Although devel_set_message isn't in the 6 branch of devel anyhow, so that would need to be backported.

skwashd’s picture

Status: Needs review » Postponed

@DaveReid Good points. Sounds like I just signed up for adding drupal_is_cli() support in drush for D6 (is 5 still supported?). If there is no objections to that approach when I wake up in the morning I'll try to find time to work on a patch for that.

Marking as postponed.

Dave Reid’s picture

Status: Postponed » Needs review

So the solution is we add a devel_is_cli() in d6 and use that instead just like backporting devel_set_message()? Not sure which approach would be better.

skwashd’s picture

Status: Needs review » Needs work

I'm tired.

Here is my proposed battle plan:
* I fix the D8 version to use drupal_is_cli(), D7 can just cherry pick.
* The D6 version of the patch backports devel_set_message() and drupal_is_cli() as devel_is_cli()

DaveReid is correct that drupal_is_cli() would need to go into D6 core, not drush.

I'll probably be back onto this in ~10hrs, unless there are objections.

msonnabaum’s picture

I see a couple problems with this approach. devel_set_message() is calling drush_log($msg, NULL), which doesn't print out without the debug flag. Without the second arg to drush_log, it still only prints if you pass verbose to drush.

I'd like to propose a considerably simpler approach:

function dpm($input, $name = NULL) {
  if (function_exists('drush_print_r')) {
    drush_print_r($input);
  }
  elseif (user_access('access devel information')) {
    $export = kprint_r($input, TRUE, $name);
    drupal_set_message($export);
  }
}

This avoids the issues discussed previously and it doesn't print html encoded characters on the cli.

skwashd’s picture

Status: Needs work » Needs review
FileSize
5.83 KB

Attached is the D8/7 version as outlined in comment #9.

I'm not opposed to implementing @msonnabaum's suggestion, but I that part of the problem is how devel_set_message() calls drush_log. I think that fixing how devel_set_message() calls drush_log() is out scope for this issue.

pcambra’s picture

Issue tags: +develcontribute

Tagging

areke’s picture

Issue summary: View changes
FileSize
4.93 KB

This patch needed a reroll, so I rerolled it.

MustangGB’s picture

Status: Needs review » Reviewed & tested by the community

If no-one else has any comments then in terms of functionality this works as expected.

MustangGB’s picture

Status: Reviewed & tested by the community » Needs work

Oops, this actually needs re-rolling against the latest release.

moshe weitzman’s picture

-  if (user_access('access devel information')) {
+  if (user_access('access devel information') || drupal_is_cli()) {

This looks wrong to me. Drush requests happen in the context of a user when -u is provided. Folks can pass in a user and then they will pass a user_access() test.

moshe weitzman’s picture

Title: Improve drush support » ddpm() and friends should work as expected during a Drush request
moshe weitzman’s picture

Title: ddpm() and friends should work as expected during a Drush request » dpm() and friends should work as expected during a Drush request
moshe weitzman’s picture

Status: Needs work » Fixed

Not positive, but I think our move to Kint will fix this. dsm() and such now use Kint of that submodule is enabled so you can try for yourself and reopen if needed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.