Found a bug in the views filter on content lock in views_handler_filter_is_locked.inc

Not working:

class views_handler_filter_is_locked extends views_handler_filter_boolean_operator {
  function query() {
    $this->ensure_my_table();
    if (empty($this->value)) {
      $this->query->add_where($this->options['group'], "$this->table_alias.timestamp IS NULL");
    }
    else {
      $this->query->add_where($this->options['group'], "$this->table_alias.timestamp IS NOT NULL");
    }
  }
}

Working

class views_handler_filter_is_locked extends views_handler_filter_boolean_operator {
  function query() {
    $this->ensure_my_table();
    if (empty($this->value)) {
      $this->query->add_where($this->options['group'], $this->table_alias.".timestamp", "NULL", "=");
    }
    else {
      $this->query->add_where($this->options['group'], $this->table_alias.".timestamp", "NULL", "<>");
    }
  }
}

Relevant doc page: http://api.drupal.org/api/views/plugins!views_plugin_query_default.inc/f...

Comments

pandaski’s picture

Version: 7.x-1.4 » 7.x-2.x-dev
Issue summary: View changes

pandaski’s picture

Status: Needs review » Fixed
Issue tags: +7.x-2.1

Thanks for contribution. Will be in next release very soon.

drumm’s picture

Status: Needs review » Fixed
Issue tags: +7.x-2.1

Status: Fixed » Closed (fixed)

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

gomez_in_the_south’s picture

StatusFileSize
new896 bytes

I found that the exposed Views filter for "Is locked" works when the value selected is "Any" or "True", but no rows are returned with a value of "False".

I'm using 7.x-2.2, though this seems to apply equally to the 7.x-3.x branch.

Steps to reproduce:
1. Create a View with an exposed filter on "Content Lock: Is Locked".
2. Set the filter to "Content Locked: False".

Expected behavior: Content that isn't locked would show in the list.
Actual behavior: No results are returned.

This appears to be related to how the "IS NULL / IS NOT NULL" matching happens. The attached patch works for me, though I am not sure if it can be considered DB agnostic, or would only work on MySQL databases.
I couldn't find documentation/examples on how to abstract "NULL" checks for the add_where portion of views query filters.

deepdru’s picture

Version: 7.x-2.x-dev » 8.x-1.x-dev
Issue tags: -7.x-2.1 +8.x-1.x-dev

Exposed views filter for "is locked" works when the value selected is "Any" or "True". But no results returned with value "False" on 8.x-1.0.

Issue still exists on 8.x-1.0.

deepdru’s picture

StatusFileSize
new745 bytes

Here is the patch to fix the views content filter issue.

deepdru’s picture

nitheesh’s picture

#9 works fine. Once you patch, make sure you have cleared the cache or a drush cr to make this work.

Can be applied to 8.x-2.0