When the Global PHP filter removes rows from the result array in php_post_execute() it does not reset the keys. So you end up with something like this:

[0] => 'Brian',
[5] => 'Lucy',
[6] => 'Joe',

because rows 1-4 were filtered out. This causes problems down the road when in views it tries to set the field_output by the row_index (see sites/all/modules/views/theme/theme.inc, line 186 in Views 7.x-3.3). It expects this:

[0] => 'Brian',
[1] => 'Lucy',
[2] => 'Joe',

Working on a patch now and will have it uploaded in a few minutes.

Comments

chasingmaxwell’s picture

Status: Active » Needs review
StatusFileSize
new468 bytes
lquessenberry’s picture

Issue summary: View changes

Any chance this can be rolled in? I just tried it and I don't think it is working. I displayed the views row count and it is skipping several items along the way.

I installed the patch with no prevail. I have large gaps of rows being filtered, but still being numbered incorrectly. My pagers are showing inconsistent amounts of rows per page because the pagers still think that there is a number of rows available that aren't.

lquessenberry’s picture

I have been testing this quite a bit. I am not sure if it's this that's not working, or if it's something to do with pagination. The items are filtered, but if I choose a paginated view of say 24 items per page, and if 10 of them meet the filter requirement, then my view shows 14 items, and counts to 24, thus not showing the 10 items it filtered. My expected outcome would be to show 24 items, omitting the 10 that are filtered and bringing the next 10 eligible items in.

I am not sure what to do to fix this.

lquessenberry’s picture

Priority: Normal » Critical

I do not know of the patch is working properly or not, but it would seem that it is not. I am changing this to Critical, because anyone that uses a PHP filter in their views will have problems dealing with using pagers in views. It seems the filters I write, are filtering the nodes that meet my filter criteria, but as stated in a comment already, the count seems off. I have enabled a count on my views and each page shows the incorrect amount of items. A page in views that should show 24 items, when 10 items are filtered, only shows 14 items, but paginates as if there were 24 items still present.

Thanks for any help.

lquessenberry’s picture

Here is a snippet of the output given by the views_php_handler_filter.inc file when output to a file. There is NULL for 'views_php_15'

array (
  0 => 
  stdClass::__set_state(array(
     'nid' => '11739',
     'node_title' => '" Aqua Life" 2-Handle Lav Faucet',
     'field_data_field_cat_product_images_node_entity_type' => 'node',
     'field_data_field_sku_node_entity_type' => 'node',
     'views_php_15' => NULL,
  )),
  1 => 
  stdClass::__set_state(array(
     'nid' => '12282',
     'node_title' => '" Conventional" 24" Satin Nickel Towel Bar',
     'field_data_field_cat_product_images_node_entity_type' => 'node',
     'field_data_field_sku_node_entity_type' => 'node',
     'views_php_15' => NULL,
  )),
  2 => 
  stdClass::__set_state(array(
     'nid' => '12287',
     'node_title' => '" Conventional" Satin Nickel Paper Holder',
     'field_data_field_cat_product_images_node_entity_type' => 'node',
     'field_data_field_sku_node_entity_type' => 'node',
     'views_php_15' => NULL,
  )),
  3 => 
  stdClass::__set_state(array(
     'nid' => '12281',
     'node_title' => '" Traditional" 18" Chrome Towel Bar',
     'field_data_field_cat_product_images_node_entity_type' => 'node',
     'field_data_field_sku_node_entity_type' => 'node',
     'views_php_15' => NULL,
  )),
  4 => 
  stdClass::__set_state(array(
     'nid' => '12293',
     'node_title' => '" Traditional" 24" Polished Chrome Towel Bar',
     'field_data_field_cat_product_images_node_entity_type' => 'node',
     'field_data_field_sku_node_entity_type' => 'node',
     'views_php_15' => NULL,
  )),
  5 => 
  stdClass::__set_state(array(
     'nid' => '12283',
     'node_title' => '" Traditional" Chrome Paper Holder',
     'field_data_field_cat_product_images_node_entity_type' => 'node',
     'field_data_field_sku_node_entity_type' => 'node',
     'views_php_15' => NULL,
  )),
  6 => 
  stdClass::__set_state(array(
     'nid' => '12292',
     'node_title' => '" Transitional" 18" Satin Nickel Towel Bar',
     'field_data_field_cat_product_images_node_entity_type' => 'node',
     'field_data_field_sku_node_entity_type' => 'node',
     'views_php_15' => NULL,
  )),
  7 => 
  stdClass::__set_state(array(
     'nid' => '12291',
     'node_title' => '" Transitional" 24" Satin Nickel Towel Bar',
     'field_data_field_cat_product_images_node_entity_type' => 'node',
     'field_data_field_sku_node_entity_type' => 'node',
     'views_php_15' => NULL,
  )),
  8 => 
  stdClass::__set_state(array(
     'nid' => '12286',
     'node_title' => '" Transitional" Satin Nickel Paper Holder',
     'field_data_field_cat_product_images_node_entity_type' => 'node',
     'field_data_field_sku_node_entity_type' => 'node',
     'views_php_15' => NULL,
  )),
  9 => 
  stdClass::__set_state(array(
     'nid' => '11949',
     'node_title' => '12"x16" Stainless Steel Oval Medicine Cabinet With Mirror',
     'field_data_field_cat_product_images_node_entity_type' => 'node',
     'field_data_field_sku_node_entity_type' => 'node',
     'views_php_15' => NULL,
  )),
  10 => 
  stdClass::__set_state(array(
     'nid' => '14125',
     'node_title' => '18" satin nickel towel bar conventional style',
     'field_data_field_cat_product_images_node_entity_type' => 'node',
     'field_data_field_sku_node_entity_type' => 'node',
     'views_php_15' => NULL,
  )),
  11 => 
  stdClass::__set_state(array(
     'nid' => '12290',
     'node_title' => '18" Stainless Steel Grab Bar, 1.5" Diameter',
     'field_data_field_cat_product_images_node_entity_type' => 'node',
     'field_data_field_sku_node_entity_type' => 'node',
     'views_php_15' => NULL,
  )),
  12 => 
  stdClass::__set_state(array(
     'nid' => '11953',
     'node_title' => '18"x27" Stainless Steel Medicine Cabinet With Mirror',
     'field_data_field_cat_product_images_node_entity_type' => 'node',
     'field_data_field_sku_node_entity_type' => 'node',
     'views_php_15' => NULL,
  )),
  13 => 
  stdClass::__set_state(array(
     'nid' => '14056',
     'node_title' => '18x16 LSO vanity base',
     'field_data_field_cat_product_images_node_entity_type' => 'node',
     'field_data_field_sku_node_entity_type' => 'node',
     'views_php_15' => NULL,
  )),
)
lquessenberry’s picture

Here is a snippet of the inc file and where we output. It seems that the patch doesn't even get a chance to work. The views_php_15 variable gets NULLs all the way around.

function php_post_execute() {
    // Evaluate the PHP code.
    if (!empty($this->options['php_filter'])) {
      $function = create_function('$view, $handler, &$static, $row, $data', $this->options['php_filter'] . ';');
      file_put_contents("/var/www/dev.bargain-outlets.com/output.txt", "\n\n\n\n\n".var_export($this->view->result, true)."\n\n\n\n\n\n", FILE_APPEND);
      ob_start();
      foreach ($this->view->result as $i => $row) {
        $normalized_row = new stdClass;
        foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
          $normalized_row->$field = isset($row->{$handler->field_alias}) ? $row->{$handler->field_alias} : NULL;
        }
        if ($function($this->view, $this, $this->php_static_variable, $normalized_row, $row)) {
          unset($this->view->result[$i]);
        }
      }
      $this->view->result = array_values($this->view->result);
      file_put_contents("/var/www/dev.bargain-outlets.com/output.txt", "\n\n\n\n\n".var_export($this->view->result, true)."\n\n\n\n\n\n", FILE_APPEND);
      ob_end_clean();
    }
  }
chasingmaxwell’s picture

lquessenberry, I'm finally getting a chance to take a look at this. I'm thinking that your problem is probably beyond the scope of this patch. It may be related in some way, but your issue sounds much more complicated than just not having proper array keys for an indexed array of results. I honestly can't remember what visible problem this bug was causing when I wrote the patch (you would think I would document that kind of thing!) but I do remember that it was kind of an edge case most people wouldn't run into - hence why it had not been caught yet and why this issue and patch went untouched for so long. Sorry I can't be of more help. Your best bet would be to use a debugger to step through and pinpoint the exact reason you aren't seeing the result you expect (where the additional 10 results should be included, but are not). Otherwise, it's just a guessing game.

johnv’s picture

I have a patch for this. Basically because the 'zebra' effect was broken (odd/even row classes), when a result row was filtered.
I didn't file the patch, since the module was not maintained.
But now the filter is 'fixed', I'll upload it.

@chasingmaxwell , my patch is not as elegant as yours. Does yours repair the Zebra, too?

lquessenberry’s picture

chasingmaxwell and johnv, thanks for your help. Yes chasingmaxwell, it is a little beyond this problem itself, although I think this problem being resolved could help. I found another issue more closely related, and I am hoping we can make it work. I will continue to watch this and test if anyone is interested.

chasingmaxwell’s picture

@johnv, That very well may have been the problem that I was trying to fix when I initially uploaded the patch, but at this point I can't remember. If the zebra striping is calculated from the results array index (and I think it is), then it should be fixed by my patch.