Hello,

I have a view that is running php code when the argument is not present.

Action to take if argument is not present ->Provide default argument -> Default argument type -> PHP Code

Until version 6.x-2.0-rc4 my view was working perfectly, but when i upgraded in 6.x-2.0-rc5, the query does not running any more, when the argument is missing. Inside settings of my view i am getting the message "No query was run" when i am pressing the preview button.

Looks that something is going wrong, with default argument type. I changed the default argument type to fixed entry and i inserted a value 2008 (Node created year) at the default argument, but with no result again...

Any advice would be much appreciated!

Comments

sotiris’s picture

Category: support » bug
sotiris’s picture

It would be nice if someone could confirm, the issue with the default argument...

merlinofchaos’s picture

Be patient. I haven't had a chance to get to this one yet.

sotiris’s picture

Ok, no prob, i can understand that you have a lot of issues to solve, i'll wait for your confirmation.

merlinofchaos’s picture

I'm also presenting at BADCamp tomorrow, and am focused on trying to make sure those presentations don't suck

merlinofchaos’s picture

Status: Active » Postponed (maintainer needs more info)

Well, I can't get this to happen on my test system. Is your argument one of the date arguments? If so you may need to remove and re-add your argument. If not...I'm not sure what to suggest.

sotiris’s picture

Yes, my argument is "Node:Created Year". I removed and re-added it, but without any result. When the argument is missing i am getting: No query was run.

In my PHP code i have:

return date(Y);

IngusNeilands’s picture

Same problem with 6.x-2.1 and 6.x-2.x-dev ( 2008-Oct-30 ).

Configure Argument Date: Date
Default argument type PHP Code => return date(Y);

Mybe there are some problems with PHP code validator ?

merlinofchaos’s picture

You know, I just realized that your code has a bug in it. It should be:

  return date('Y');
dlloyd’s picture

Version: 6.x-2.0-rc5 » 6.x-2.1

Running 6.x-2.1 on Drupal 6.6, I'm having the same problem with defaults set for arguments for Node: Month Created and Node: Year Created. It happens whether I provide the default via PHP code or fixed entry - "No query was run". If I provide arguments via the live previewer or call a page display with an argument specified, it works fine.

ar-jan’s picture

I get the same as in #10, using default argument: php code:

<?php
  return date('Y');
?>

Like in the original post, using fixed entry: '2008' results in the same error "No query was run".

ocirs’s picture

I'm running in to the same problem. This problem is easily replicable by downloading and installing the most recent copy of Drupal 6.9, installing the views module and creating a view with "node: created year" as an argument and '2009'(or any other year) as the default fixed argument.

Live preview shows 'No query was run' with basic validation and when I insert 'return 1;' with php validation the argument runs but is missing the argument.

ex.

WHERE EXTRACT(YEAR FROM((FROM_UNIXTIME(node.created) + INTERVAL -18000 SECOND))) = ''

when it should be

WHERE EXTRACT(YEAR FROM((FROM_UNIXTIME(node.created) + INTERVAL -18000 SECOND))) = '2009'

When '2009' is provided as an argument in live preview the query is the latter with the argument.

merlinofchaos’s picture

#12 I tried exactly what you said, and it works exactly as expected. The fixed argument I set gets used in the view both in live preview and normally when used as a block or on a page.

ocirs’s picture

I've found the piece of code from RC4 to RC5 that cause the problem here

http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/views/handl...

By copying that piece of code back in to views_handler_argument.inc, the problem was resolved and everything works as expected.

Does that help?

I'm the latest stable release 6.x-2.2, 2009-Feb-07

jcamfield’s picture

I am having this same problem, with both fixed entries and PHP code; adding that diff back in had no effect for me.

merlinofchaos’s picture

Have you tried completely removing the argument and re-adding it?

zbricoleur’s picture

I'm having the same problem as described above in #10, with 6.x-2.3.

Date field for the argument is Node: Post date

Provide default argument: checked
PHP code: checked
Code provided:

$lastWeek = time() - (7 * 24 * 60 * 60);
$start = date("Y-m-d", $lastWeek);
$end = date("Y-m-d");
$thisarg = "$start--$end";
return $thisarg;

This argument is the second argument for the view. If I supply the date argument in the querystring manually, exactly as it is generated by the code above, it works properly. If I don't--if I supply only the first argument--I get the No query run message on Preview, or Page Not Found on the view itself.

I tried completely removing the argument and re-adding it. Still have the problem.

Also tried the suggestion in #14 and still have the problem.

enricom’s picture

I was having the same problem mentioned above.
I was trying to use

return date("W");

and

return date("Y");

as default values for my two arguments, but I kept getting 'No query run'.
Providing a static value didn't work either.

Using 'current date' as the default value almost worked (at least it queried), but it returns date("Y-m-d") irrespective of the argument type.

Here is the modification I made to handle the different 'Node: Created' date types.
views_handler_argument_date.inc @ line 37

function get_default_argument($raw = FALSE) {
  if (!$raw && $this->options['default_argument_type'] == 'date') {
    if($this->field=='created_year')
      return date("Y", time());
    elseif($this->field=='created_week')
      return date("W", time());
    elseif($this->field=='created_day')
      return date("d", time());
    elseif($this->field=='created_year_month')
      return date("Ym", time());
    else
      return date($this->arg_format, time());
}

It's not a solution to the general problem which seems to be that default values can't be specified using php, but if all you want is the built-in 'Node: Created' arguments, this solves that.

merlinofchaos’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)
andrewsuth’s picture

I'm using the latest Views 2.5 and am still get this same problem as outlined in this thread. I've checked and tested my PHP code in other places I know it works.

I noticed the patch mentioned above has been applied to views_handler_argument_date.inc in Views 2.5 but it continues to ignore my code in Default argument type: PHP Code

Is anyone else having this same issue still?

By the way, I'm outputting my View as a Block, so this code is always executed, as explained in the help docs:

Please bear in mind that the selection of default argument happens only if an argument is not provided. If using a display that has no argument source, such as a block, this will be the case 100% of the time.

EDIT: Solved: I found that when changing any of the PHP code, I then had to flush all caches before it would work properly. I also discovered that the Preview didn't represent what was actually being displayed on the user end.