Crossposting this issue: #1087898: PDOException: SQLSTATE[HY000] on batch export
If my view contains a column that is defined by Views PHP, this columns is not exported by 'Views Data Export'.
My guess is that some Views callback is missing.

Issue fork views_php-1088776

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hadsie’s picture

Category: feature » bug

I'm getting this same error. You have any luck figuring out a work around? It looks like I'm just going to have to write a custom views field for my solution.

johnv’s picture

Status: Needs review » Active

No, and even worse: my current VDE-exports only export node-titles :-( .
I don't know yet if this is due to a update of VDE of an update of Views.

johnv’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

gabrielu’s picture

Status: Closed (fixed) » Active

How can this be related to table character encoding. All my tables are UTF8 but the PHP is never called there.
So the problem is about integrating Views PHP with Views Data Export. In the preview of VDE I see the result of my PHP FIeld, but not in the file, the file is always blank.

pineray’s picture

I ran into the same trouble.
However, I applied the following modifications and it worked correctly.

Change the function name php_post_execute() in views_php_handler_field.inc to post_execute() and php_pre_execute() to pre_execute().

johnv’s picture

BWPanda’s picture

PineRay's solution worked for me, though I don't really understand it...

I've attached a patch that should be tested to make sure it doesn't break anything.

Amarjit’s picture

The patch actually worked for me but with an error.

Strict warning: Declaration of views_php_handler_field::post_execute() should be compatible with that of views_handler::post_execute() in _registry_check_code() (line 2982 of \includes\bootstrap.inc).

I did some scavenging around on the function 'post_execute'. It seems this function needs the reference for $variables to be passed in. Even though this is not used, it's part of the function prototype.

See here »

Amarjit.

meghanmary’s picture

@Amarjit - This patch worked for me - thanks so much!

drewish’s picture

Status: Needs review » Reviewed & tested by the community

Worked well for us too.

ttkaminski’s picture

A quick grep on the source files shows this:

plugins/views/views_php_handler_field.inc:   * @see self::php_post_execute()
plugins/views/views_php_handler_field.inc:   * @see self::php_post_execute()
plugins/views/views_php_handler_field.inc:  function php_pre_execute() {
plugins/views/views_php_handler_field.inc:  function php_post_execute() {
plugins/views/views_php_plugin_pager.inc:        if (is_callable(array($handler, 'php_pre_execute'))) {
plugins/views/views_php_plugin_pager.inc:          $handler->php_pre_execute();
plugins/views/views_php_plugin_pager.inc:        if (is_callable(array($handler, 'php_post_execute'))) {
plugins/views/views_php_plugin_pager.inc:          $handler->php_post_execute();
plugins/views/views_php_handler_sort.inc:  function php_pre_execute() {
plugins/views/views_php_handler_sort.inc:  function php_post_execute() {
plugins/views/views_php_handler_filter.inc:  function php_pre_execute() {
plugins/views/views_php_handler_filter.inc:  function php_post_execute() {

Should these files be updated as well?

junedkazi’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/docroot/sites/all/modules/views_php/plugins/views/views_php_handler_field.inc
@@ -111,7 +111,7 @@ class views_php_handler_field extends views_handler_field {
-  function php_pre_execute() {

You cannot change the function name. As it is being called from the views_php_plugin_pager.inc file.

+++ b/docroot/sites/all/modules/views_php/plugins/views/views_php_handler_field.inc
@@ -125,14 +125,14 @@ class views_php_handler_field extends views_handler_field {
-  function php_post_execute() {

You cannot change the function name. As it is being called from the views_php_plugin_pager.inc file.

johnv’s picture

@junedkazi , the function names have been changed similarly in other patches, too. With succes.
It seems like Views PHP has a lot of D6-code, which is not working anymore. This might be a D6-D7 api change.

junedkazi’s picture

@johnv I do understand that it is not working and a change is necessary. But by comment was regards to the patch in comment 9 where it is changed for only one file instead of the complete module. Hence the comment you cannot change it at one place as it makes the whole code much more vulnerable if someone applies this patch.

vensires’s picture

I have to offer another idea - based of course on #6. In views_php_handler_field.inc Instead of fixing the function names and the callers, I only added the following functions to the views_php_handler_field class:

function pre_execute() {
  $this->php_pre_execute();
}
function post_execute() {
  $this->php_post_execute();
}
SilviuChingaru’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
543 bytes

The solution from #16 is working fine and I also think is good for compatibility so here is a patch for this.

A better approach is to move content of php_pre_execute() and php_post_exectue() to pre_execute() and post_execute() and php_pre|post_execute() to return the output of pre|post_execute for views API consistency.

SilviuChingaru’s picture

Title: Views PHP columns are not supported by Views Data Export » Views PHP pre and post execute extender implementation
DevDaveUK’s picture

Patch #17 works for me - the views php columns are now populated in the exported CSV, however, I have the following error on the page with my view:

Strict warning: Declaration of views_php_handler_field::post_execute() should be compatible with that of views_handler::post_execute() in _registry_check_code() (line 3139 of /Users/davidlong/Sites/devdesktop/registers/includes/bootstrap.inc).
SilviuChingaru’s picture

@DevDaveUK please post you view (exported). I'm using this patch for 4 months now on production and I don't receive that error.

By the way, did you cleared cache and views cache after applying the #17 patch? You should do that and post your feedback afterwards pls.

DevDaveUK’s picture

<?php
$empty = "a course";
$course = array(
"VGD"=>"Video Game Development", 
"ANI2D"=>"Stop Motion and 2D Animation", 
"DMJR"=>"Digital Music Production for 10-12 year olds", 
"DMSR"=>"Digital Music Production for 13+ year olds", 
"TCJ"=>"Java with Greenfoot", 
"TCP"=>"Teen Python"
);


$course_abr = $row->name;
if (array_key_exists($course_abr, $course)) {
return $course[$course_abr];
} else {
return $empty;
}

$directions = "Test";
If ($row->name_1 == "London" && $row->name != "RAP") {
$directions = "Message text goes here.";
} else if ($row->name_1 == "London" && $row->name == "RAP") {
$directions = "TMessage text goes here";
} else if ($row->name_1 == "Manchester") {
$directions = "Message text goes here.";
} else if ($row->name_1 == "Bristol") {
$directions = "Message text goes here.";
} else if ($row->name_1 == "Brighton") {
$directions = "Message text goes here.";
}
return $directions;
-----

$view = new view();
$view->name = 'emails';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Emails';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Welcome Emails';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['style_plugin'] = 'table';
/* Relationship: Parent */
$handler->display->display_options['relationships']['field_nr_parent_nid']['id'] = 'field_nr_parent_nid';
$handler->display->display_options['relationships']['field_nr_parent_nid']['table'] = 'field_data_field_nr_parent';
$handler->display->display_options['relationships']['field_nr_parent_nid']['field'] = 'field_nr_parent_nid';
$handler->display->display_options['relationships']['field_nr_parent_nid']['ui_name'] = 'Parent';
$handler->display->display_options['relationships']['field_nr_parent_nid']['delta'] = '-1';
/* Relationship: Child */
$handler->display->display_options['relationships']['field_child_nid']['id'] = 'field_child_nid';
$handler->display->display_options['relationships']['field_child_nid']['table'] = 'field_data_field_child';
$handler->display->display_options['relationships']['field_child_nid']['field'] = 'field_child_nid';
$handler->display->display_options['relationships']['field_child_nid']['ui_name'] = 'Child';
$handler->display->display_options['relationships']['field_child_nid']['delta'] = '-1';
/* Relationship: Courses */
$handler->display->display_options['relationships']['term_node_tid']['id'] = 'term_node_tid';
$handler->display->display_options['relationships']['term_node_tid']['table'] = 'node';
$handler->display->display_options['relationships']['term_node_tid']['field'] = 'term_node_tid';
$handler->display->display_options['relationships']['term_node_tid']['ui_name'] = 'Courses';
$handler->display->display_options['relationships']['term_node_tid']['label'] = 'terms_course';
$handler->display->display_options['relationships']['term_node_tid']['vocabularies'] = array(
  'course' => 'course',
  'camp' => 0,
  'course_type' => 0,
  'location' => 0,
  'school' => 0,
  'tags' => 0,
  'tutor' => 0,
);
/* Relationship: Locations */
$handler->display->display_options['relationships']['term_node_tid_1']['id'] = 'term_node_tid_1';
$handler->display->display_options['relationships']['term_node_tid_1']['table'] = 'node';
$handler->display->display_options['relationships']['term_node_tid_1']['field'] = 'term_node_tid';
$handler->display->display_options['relationships']['term_node_tid_1']['ui_name'] = 'Locations';
$handler->display->display_options['relationships']['term_node_tid_1']['label'] = 'term_location';
$handler->display->display_options['relationships']['term_node_tid_1']['vocabularies'] = array(
  'location' => 'location',
  'camp' => 0,
  'course' => 0,
  'course_type' => 0,
  'school' => 0,
  'tags' => 0,
  'tutor' => 0,
);
/* Field: Content: Title */
$handler->display->display_options['fields']['title_1']['id'] = 'title_1';
$handler->display->display_options['fields']['title_1']['table'] = 'node';
$handler->display->display_options['fields']['title_1']['field'] = 'title';
$handler->display->display_options['fields']['title_1']['relationship'] = 'field_nr_parent_nid';
$handler->display->display_options['fields']['title_1']['link_to_node'] = FALSE;
/* Field: Content: Parent Name */
$handler->display->display_options['fields']['field_parent_name']['id'] = 'field_parent_name';
$handler->display->display_options['fields']['field_parent_name']['table'] = 'field_data_field_parent_name';
$handler->display->display_options['fields']['field_parent_name']['field'] = 'field_parent_name';
$handler->display->display_options['fields']['field_parent_name']['relationship'] = 'field_nr_parent_nid';
$handler->display->display_options['fields']['field_parent_name']['type'] = 'text_plain';
/* Field: Content: Child Name */
$handler->display->display_options['fields']['field_child_name']['id'] = 'field_child_name';
$handler->display->display_options['fields']['field_child_name']['table'] = 'field_data_field_child_name';
$handler->display->display_options['fields']['field_child_name']['field'] = 'field_child_name';
$handler->display->display_options['fields']['field_child_name']['relationship'] = 'field_child_nid';
$handler->display->display_options['fields']['field_child_name']['type'] = 'text_plain';
/* Field: Taxonomy term: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'taxonomy_term_data';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'term_node_tid';
$handler->display->display_options['fields']['name']['label'] = 'Course';
/* Field: Global: PHP */
$handler->display->display_options['fields']['php_4']['id'] = 'php_4';
$handler->display->display_options['fields']['php_4']['table'] = 'views';
$handler->display->display_options['fields']['php_4']['field'] = 'php';
$handler->display->display_options['fields']['php_4']['label'] = 'Course Name';
$handler->display->display_options['fields']['php_4']['use_php_setup'] = 0;
$handler->display->display_options['fields']['php_4']['php_value'] = '$empty = "a course";
$course = array(
"VGD"=>"Video Game Design", 
"ANI2D"=>"Stop Motion and 2D Animation", 
"T3D"=>"Teen 3D Animation",
"DMJR"=>"Digital Music Production", 
"DMSR"=>"Digital Music Production", 
"TCJ"=>"Coding Java with Greenfoot", 
"TCP"=>"Teen Coding with Python",
"ROB"=>"Robotics with LEGO Mindstorms",
"THC"=>"Physical Computing with Arduino",
"RAP" =>"Rapid Prototyping: An Introduction to Making"
);


$course_abr = $row->name;
if (array_key_exists($course_abr, $course)) {
return $course[$course_abr];
} else {
return $empty;
}';
$handler->display->display_options['fields']['php_4']['php_output'] = '<?php echo $value; ?>';
$handler->display->display_options['fields']['php_4']['use_php_click_sortable'] = '0';
$handler->display->display_options['fields']['php_4']['php_click_sortable'] = '';
/* Field: Taxonomy term: Name */
$handler->display->display_options['fields']['name_1']['id'] = 'name_1';
$handler->display->display_options['fields']['name_1']['table'] = 'taxonomy_term_data';
$handler->display->display_options['fields']['name_1']['field'] = 'name';
$handler->display->display_options['fields']['name_1']['relationship'] = 'term_node_tid_1';
$handler->display->display_options['fields']['name_1']['label'] = 'Location';
/* Field: Global: PHP */
$handler->display->display_options['fields']['php_5']['id'] = 'php_5';
$handler->display->display_options['fields']['php_5']['table'] = 'views';
$handler->display->display_options['fields']['php_5']['field'] = 'php';
$handler->display->display_options['fields']['php_5']['label'] = 'Location Text';
$handler->display->display_options['fields']['php_5']['use_php_setup'] = 0;
$handler->display->display_options['fields']['php_5']['php_value'] = '$locationName = "default address goes here";
If ($row->name_1 == "London" && $row->name != "RAP") {
//Imperial
$locationName = "address goes here";
} else if ($row->name_1 == "London" && $row->name == "RAP") {
//Makerversity
$locationName = "address goes here";
} else if ($row->name_1 == "Manchester") {
$locationName = "address goes here";
} else if ($row->name_1 == "Bristol") {
$locationName = "address goes here";
} else if ($row->name_1 == "Brighton") {
$locationName = "address goes here";
}
return $locationName;';
$handler->display->display_options['fields']['php_5']['php_output'] = '<?php echo $value; ?>';
$handler->display->display_options['fields']['php_5']['use_php_click_sortable'] = '0';
$handler->display->display_options['fields']['php_5']['php_click_sortable'] = '';
/* Field: Global: PHP */
$handler->display->display_options['fields']['php']['id'] = 'php';
$handler->display->display_options['fields']['php']['table'] = 'views';
$handler->display->display_options['fields']['php']['field'] = 'php';
$handler->display->display_options['fields']['php']['label'] = 'Map';
$handler->display->display_options['fields']['php']['use_php_setup'] = 0;
$handler->display->display_options['fields']['php']['php_value'] = 'if($row->name_1 == "London" && $row->name !="RAP"){
$mapImageUrl = "/images/imperial-map.jpg";
} else if($row->name_1 == "London" && $row->name =="RAP"){
$mapImageUrl = "/images/makerversity-map.jpg";
} else if($row->name_1 == "Manchester") {
$mapImageUrl = "/images/mosi-map.jpg";
} else if($row->name_1 == "Bristol") {
$mapImageUrl = "/images/uwe-map.jpg";
} else if($row->name_1 == "Brighton") {
$mapImageUrl = "/images/falmer-map.jpg";
} else {
$mapImageUrl = "";
}
return $mapImageUrl;';
$handler->display->display_options['fields']['php']['php_output'] = 'url goes here/<?php echo $value; ?>';
$handler->display->display_options['fields']['php']['use_php_click_sortable'] = '0';
$handler->display->display_options['fields']['php']['php_click_sortable'] = '';
/* Field: Global: PHP */
$handler->display->display_options['fields']['php_1']['id'] = 'php_1';
$handler->display->display_options['fields']['php_1']['table'] = 'views';
$handler->display->display_options['fields']['php_1']['field'] = 'php';
$handler->display->display_options['fields']['php_1']['label'] = 'Course Time';
$handler->display->display_options['fields']['php_1']['use_php_setup'] = 0;
$handler->display->display_options['fields']['php_1']['php_value'] = '$cTime = "All day";
If($row->name_1 == "London" && $row->name == "VGD" || $row->name == "ROB" || $row->name == "RAP" || $row->name == "ANI2D" || $row->name == "DMJR" || $row->name_1 == "London" && $row->name == "MIN") {
$cTime = "9am-5pm";
} else {
$cTime = "10am-3pm";
}
return $cTime;';
$handler->display->display_options['fields']['php_1']['php_output'] = '<?php echo $value; ?>';
$handler->display->display_options['fields']['php_1']['use_php_click_sortable'] = '0';
$handler->display->display_options['fields']['php_1']['php_click_sortable'] = '';
/* Field: Global: PHP */
$handler->display->display_options['fields']['php_2']['id'] = 'php_2';
$handler->display->display_options['fields']['php_2']['table'] = 'views';
$handler->display->display_options['fields']['php_2']['field'] = 'php';
$handler->display->display_options['fields']['php_2']['label'] = 'Drop Off';
$handler->display->display_options['fields']['php_2']['use_php_setup'] = 0;
$handler->display->display_options['fields']['php_2']['php_value'] = '$cTime = "All day";
If($row->name_1 == "London" && $row->name == "VGD" || $row->name == "ROB" || $row->name == "RAP" || $row->name == "ANI2D" || $row->name == "DMJR" || $row->name_1 == "London" && $row->name == "MIN") {
$cTime = "8:45am";
} else {
$cTime = "9:45am";
}
return $cTime;';
$handler->display->display_options['fields']['php_2']['php_output'] = '<?php echo $value; ?>';
$handler->display->display_options['fields']['php_2']['use_php_click_sortable'] = '0';
$handler->display->display_options['fields']['php_2']['php_click_sortable'] = '';
/* Field: Global: PHP */
$handler->display->display_options['fields']['php_3']['id'] = 'php_3';
$handler->display->display_options['fields']['php_3']['table'] = 'views';
$handler->display->display_options['fields']['php_3']['field'] = 'php';
$handler->display->display_options['fields']['php_3']['label'] = 'What to bring';
$handler->display->display_options['fields']['php_3']['use_php_setup'] = 0;
$handler->display->display_options['fields']['php_3']['php_value'] = '$materials = "message text goes here.";
If($row->name == "TCJ" || $row->name == "TCP") {
$materials = "message text goes here";
} else if ($row->name == "MIN") {
$materials = "message text goes here.";
}
return $materials;';
$handler->display->display_options['fields']['php_3']['php_output'] = '<?php echo $value; ?>';
$handler->display->display_options['fields']['php_3']['use_php_click_sortable'] = '0';
$handler->display->display_options['fields']['php_3']['php_click_sortable'] = '';
/* Field: Global: PHP */
$handler->display->display_options['fields']['php_6']['id'] = 'php_6';
$handler->display->display_options['fields']['php_6']['table'] = 'views';
$handler->display->display_options['fields']['php_6']['field'] = 'php';
$handler->display->display_options['fields']['php_6']['label'] = 'Directions';
$handler->display->display_options['fields']['php_6']['use_php_setup'] = 0;
$handler->display->display_options['fields']['php_6']['php_value'] = '$directions = "";
If ($row->name_1 == "London" && $row->name != "RAP") {
$directions = "message text goes here.";
} else if ($row->name_1 == "London" && $row->name == "RAP") {
$directions = "message text goes here";
} else if ($row->name_1 == "Manchester") {
$directions = "message text goes here.";
} else if ($row->name_1 == "Bristol") {
$directions = "message text goes here.";
} else if ($row->name_1 == "Brighton") {
$directions = "message text goes here.";
}
return $directions;';
$handler->display->display_options['fields']['php_6']['php_output'] = '<?php echo $value; ?>';
$handler->display->display_options['fields']['php_6']['use_php_click_sortable'] = '0';
$handler->display->display_options['fields']['php_6']['php_click_sortable'] = '';
/* Field: Global: PHP */
$handler->display->display_options['fields']['php_7']['id'] = 'php_7';
$handler->display->display_options['fields']['php_7']['table'] = 'views';
$handler->display->display_options['fields']['php_7']['field'] = 'php';
$handler->display->display_options['fields']['php_7']['label'] = 'Extended Care';
$handler->display->display_options['fields']['php_7']['use_php_setup'] = 0;
$handler->display->display_options['fields']['php_7']['php_value'] = 'If($row->name_1 != "London"){
$exc = "message text goes here";
} else {
$exc = "";
}
return $exc';
$handler->display->display_options['fields']['php_7']['php_output'] = '<?php echo $value; ?>';
$handler->display->display_options['fields']['php_7']['use_php_click_sortable'] = '0';
$handler->display->display_options['fields']['php_7']['php_click_sortable'] = '';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'order' => 'order',
);

/* Display: Welcome */
$handler = $view->new_display('page', 'Welcome', 'page');
$handler->display->display_options['display_description'] = 'Welcome Emails';
$handler->display->display_options['path'] = 'welcome-emails';
$handler->display->display_options['menu']['type'] = 'normal';
$handler->display->display_options['menu']['title'] = 'Emails';
$handler->display->display_options['menu']['name'] = 'features';

/* Display: Data export */
$handler = $view->new_display('views_data_export', 'Data export', 'views_data_export_1');
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'views_data_export_csv';
$handler->display->display_options['style_options']['provide_file'] = 1;
$handler->display->display_options['style_options']['filename'] = '%view_%timestamp-full.csv';
$handler->display->display_options['style_options']['parent_sort'] = 0;
$handler->display->display_options['style_options']['quote'] = 1;
$handler->display->display_options['style_options']['trim'] = 0;
$handler->display->display_options['style_options']['replace_newlines'] = 0;
$handler->display->display_options['style_options']['header'] = 1;
$handler->display->display_options['style_options']['keep_html'] = 0;
$handler->display->display_options['path'] = 'welcome-email-csv';
$handler->display->display_options['displays'] = array(
  'page' => 'page',
  'default' => 0,
);
$handler->display->display_options['use_batch'] = 'batch';
$handler->display->display_options['segment_size'] = '400';

?>
SocialNicheGuru’s picture

need to provide a patch but the fix in views_php_handler_field.inc at about line 119 is

 // add &$values needed for post_execute not pre_execute
  function post_execute(&$values) {
    return $this->php_post_execute();
  }

There are several post_execute functions in views. I went with the definition in the views field handler:
modules/field/views_handler_field_field.inc:628: function post_execute(&$values) {

I did not find a specific views handler pre_execute function so I guess the one defined in views.inc should work just fine. Thus no error for that function.

Anybody’s picture

The patch from #17 looks nearly fine.

One thing was just that

function post_execute(&$values) {
    return $this->php_post_execute();
}

was missing the $values parameter, which lead to the problem described in #19. This is now fixed with the patch attached.

The question is, if pre_execute is required anyway. What's the reason for that? Is that ever being called?
views_field_handler does not contain such a function. See https://api.drupal.org/api/views/handlers!views_handler_field.inc/class/...

I've tested the export with the patch and it works great :)

Let's finish this!

rcodina’s picture

I have the problem described here and patch on #23 don't work for me.

zmove’s picture

Status: Needs review » Reviewed & tested by the community

patch #17 perfectly works

fizk’s picture

Status: Reviewed & tested by the community » Closed (cannot reproduce)

I can't reproduce this issue with the latest 7.x-1.x-dev. Please reopen if you can and provide a list of steps to reproduce.

rcodina’s picture

Status: Closed (cannot reproduce) » Needs work
Related issues: +#2101801: Make caching compatible with Views PHP

@fizk Just try to create a new search api view, then enable cache on it (Search specific for example) and then add a Views PHP field on it. The preview will work but the normal execution of view will fail. If you then disable the cache or delete the PHP field, the views will work.

fizk’s picture

@rcodina Thanks, I'll try to get back to this sometime this week. If I forget, please ping me.

abhishek.pareek’s picture

patch #17 did the trick but gives strict warning as described in #19,

patch #23 worked for me.

skessler’s picture

This appears to still be a problem. I tried to apply #23 but that does not appear to work with 7.x-1.0-alpha3.

Thanks,
Steve

skessler’s picture

I should update this. It is only a porblem if using batches export.

Thaanks,
Steve

boromino’s picture

This patch passes $static between batch segments.

boromino’s picture

Pass $static in batch instead of $_SESSION.

boromino’s picture

themic8’s picture

Thank you @boromino. The patch works.

Note: I only need the patch when doing a batch export. Otherwise the patch is not needed.

Liam Morland’s picture

Status: Needs review » Needs work

Patch does not apply. Please put into an issue fork.

nessunluogo’s picture

#34 saved me. Thanks @boromino!

skylord’s picture

Status: Needs work » Needs review

Hm. While updating old clients' site stated #34 applies cleanly on 1.1 and works OK. Please, review it.

SilviuChingaru’s picture

This patch is not working for computed fields because the filter is triggered before fields are rendered so the filter will not work on Global: Math or Global: Text fields that have NULL values when the filter plugin is called.

In vs. 7.x-2.x this was solved using code:

function php_pre_render() {
  // (...)
    $normalized_row->$id = $this->view->field[$id]->theme($result);
  // (...)
}

but in 7.x-1.x the code is

function php_pre_render() {
  // (...)
  $normalized_row->$field = isset($row->{$handler->field_alias}) ? $row->{$handler->field_alias} : NULL;
  // (...)
}

And because a math field is calculated only in render stage, in pre_render stage, field has no value.

The best fix will be #2451759: Provide method get_value() for views_handler_field_math in views core.