The date_views_argument_handler class causes a syntax error in the query due to a missing table alias in the condition string when using a field that is added via a relationship.
See below timestamp field below.
{code}
(DATE_FORMAT(ADDTIME(FROM_UNIXTIME(.timestamp), SEC_TO_TIME(7200)), '%Y-%m-%d %H:%i:%s') >= '2014-12-15 00:00:00' AND DATE_FORMAT(ADDTIME(FROM_UNIXTIME(.timestamp), SEC_TO_TIME(7200)), '%Y-%m-%d %H:%i:%s') <= '2014-12-22 00:00:00')
{code}

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

recrit’s picture

Status: Active » Needs review
FileSize
1.23 KB

Cause: Line 168 of date_views_argument_handler.inc, the table is set to the alias returned by "$this->query->ensure_table" after it was set to the field's table_name 3 lines above.

# Line 166
$this->table = $field['table_name'];
$this->original_table = $field['table_name'];
if ($field['table_name'] != $this->table || !empty($this->relationship)) {
  $this->table = $this->query->ensure_table($field['table_name'], $this->relationship);
}

Fix:
* Updated code to use $this->ensure_my_table() which sets the table_alias based on the query and relationship. This keeps table un-touched which is set to the field's table_name above it, and provides the table_alias correctly for the parent class to process.
* The following condition is no longer needed since the table always is the same as the table_name and ensure_my_table processes the alias for relationships. field['table_name'] != $this->table || !empty($this->relationship)

Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll, +Needs work

The 4 year old patch to date_views_argument_handler.inc does not apply to the latest 7.x-2.x-dev and may be too old to reroll, but I went ahead and tagged the issue accordingly.

error: while searching for:
        $this->real_field = $field['field_name'];
        $this->table = $field['table_name'];
        $this->original_table = $field['table_name'];
        if ($field['table_name'] != $this->table || !empty($this->relationship)) {
          $this->table = $this->query->ensure_table($field['table_name'], $this->relationship);
        }
        // $this->table_alias gets set when the first field is processed if otherwise empty.
        // For subsequent fields, we need to be sure it is emptied again.
        elseif (empty($this->relationship)) {
          $this->table_alias = NULL;
        }
        parent::query($group_by);

        $this->placeholders = array_merge($this->placeholders, $this->date_handler->placeholders);

error: patch failed: date_views/includes/date_views_argument_handler.inc:165
error: date_views/includes/date_views_argument_handler.inc: patch does not apply
pjcdawkins’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll, -
FileSize
1.24 KB

Rerolled