We have a very odd problem here. All modules are latest from what I know:
- views 5.x-1.6
- votingapi 5.x-1.5
- image 5.x-1.4 (not latest, but will not take that due to known bugs there)
- fivestar 5.x-1.7
We use fivestar to rate content. Then simply want to create a view to show highest rated images. Export is like this:
$view = new stdClass();
$view->name = 'popular_images';
$view->description = 'Highest rated images';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = 'Highest rated images';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'table';
$view->url = 'popular/images';
$view->use_pager = TRUE;
$view->nodes_per_page = '25';
$view->menu = TRUE;
$view->menu_title = 'Images';
$view->menu_tab = TRUE;
$view->menu_tab_weight = '1';
$view->menu_tab_default = FALSE;
$view->menu_tab_default_parent = NULL;
$view->menu_tab_default_parent_type = 'normal';
$view->menu_parent_tab_weight = '0';
$view->menu_parent_title = '';
$view->sort = array (
array (
'tablename' => 'votingapi_cache_vote_percent_average',
'field' => 'value',
'sortorder' => 'DESC',
'options' => '',
),
array (
'tablename' => 'votingapi_cache_vote_percent_count',
'field' => 'value',
'sortorder' => 'DESC',
'options' => '',
),
array (
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array (
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'body',
'label' => 'Thumb/Description',
'handler' => 'views_handler_field_teaser',
),
array (
'tablename' => 'votingapi_cache_vote_percent_average',
'field' => 'value',
'label' => 'Rating',
'handler' => 'fivestar_views_value_display_handler',
),
array (
'tablename' => 'votingapi_cache_vote_percent_count',
'field' => 'value',
'label' => 'Votes',
'handler' => 'votingapi_views_formatter_raw',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'image',
),
),
array (
'tablename' => 'votingapi_cache_vote_percent_count',
'field' => 'value',
'operator' => '>',
'options' => '',
'value' => '0',
),
);
$view->exposed_filter = array (
);
$view->requires = array(votingapi_cache_vote_percent_average, votingapi_cache_vote_percent_count, node);
$views[$view->name] = $view;
No worries there.
Aside from the fact that this view only lasts a short amount of time before breaking. By 'break', I mean nothing is shown when trying to look at the view, and the following PHP errors appears:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '> '') ORDER BY DESC, DESC, node_created_created DESC LIMIT 0, 25' at line 1 query: SELECT DISTINCT(node.nid), value, node.created AS node_created_created FROM node node WHERE (node.type IN ('image')) AND (.value > '') ORDER BY DESC, DESC, node_created_created DESC LIMIT 0, 25 in /my/path/drupal-5.1/includes/database.mysql.inc on line 173.
I can't determine the exact cause. Time the view stays alive seems to be random:
- It's not cron.
- Clearing views cache doesn't fix this.
- It's not creating a new image.
- It's not voting on images.
- This is not limited to images, we rate other content and it happens with that also.
When the view breaks, export of it shows:
$view = new stdClass();
$view->name = 'popular_images';
$view->description = 'Highest rated images';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = 'Highest rated images';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'table';
$view->url = 'popular/images';
$view->use_pager = TRUE;
$view->nodes_per_page = '25';
$view->menu = TRUE;
$view->menu_title = 'Images';
$view->menu_tab = TRUE;
$view->menu_tab_weight = '1';
$view->menu_tab_default = FALSE;
$view->menu_tab_default_parent = NULL;
$view->menu_tab_default_parent_type = 'normal';
$view->menu_parent_tab_weight = '0';
$view->menu_parent_title = '';
$view->sort = array (
array (
'tablename' => 'votingapi_cache_vote_percent_average',
'field' => 'value',
'sortorder' => 'DESC',
'options' => '',
),
array (
'tablename' => 'votingapi_cache_vote_percent_count',
'field' => 'value',
'sortorder' => 'DESC',
'options' => '',
),
array (
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array (
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'body',
'label' => 'Thumb/Description',
'handler' => 'views_handler_field_teaser',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'image',
),
),
array (
'tablename' => 'votingapi_cache_vote_percent_count',
'field' => 'value',
'operator' => '>',
'options' => '',
'value' => '',
),
);
$view->exposed_filter = array (
);
$view->requires = array(votingapi_cache_vote_percent_average, votingapi_cache_vote_percent_count, node);
$views[$view->name] = $view;
To fix the broken view one can simply edit it. One can see that the filter and sort boxes that once has votingapi fields in are blank. I mean, they are there, but blank (BTW, this is also accompanied by the error Invalid argument supplied for foreach() in /my/path/drupal-5.1/includes/form.inc on line 947.).
'bin' the filter and sort criteria and save. View becomes:
$view = new stdClass();
$view->name = 'popular_images';
$view->description = 'Highest rated images';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = 'Highest rated images';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'table';
$view->url = 'popular/images';
$view->use_pager = TRUE;
$view->nodes_per_page = '25';
$view->menu = TRUE;
$view->menu_title = 'Images';
$view->menu_tab = TRUE;
$view->menu_tab_weight = '1';
$view->menu_tab_default = FALSE;
$view->menu_tab_default_parent = NULL;
$view->menu_tab_default_parent_type = 'normal';
$view->menu_parent_tab_weight = '0';
$view->menu_parent_title = '';
$view->sort = array (
array (
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array (
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'body',
'label' => 'Thumb/Description',
'handler' => 'views_handler_field_teaser',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'image',
),
),
);
$view->exposed_filter = array (
);
$view->requires = array(node);
$views[$view->name] = $view;
Not very useful, so add these back in (mysteriously the votingapi fields re-appear on the next edit) and the view can revert to that shown initially above. It will work for some time before breaking again.
Odd, and rather annoying.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | broken view fields.png | 15.58 KB | raintonr |
Comments
Comment #1
westbywest commentedI have now twice observed the same problem with votingapi and views.
Relevant module/drupal data:
drupal v5.2
actions v5.x-1.x-dev (2007-May-02)
taxonomy access control v5.x-1.1
views v5.x-1.6
views bonus pack v5.x-1.2-alpha1
vote_up/down 5.x-1.x-dev (2007-Oct-02)
votingapi v5.x-1.5
I set up a list view, where one of the fields is the sum of votes cast.
As previous poster explains, the votingapi fields disappear from the view edit page after a period of time, as do relevant fields and filter options (i.e. votingapi and vote_up/down). When viewing the affected view after this happens, I observed this SQL error about a missing column in the DB:
Is there something broken with the votingapi cache mechanism? This could explain the error appearing only after some time has passed. Removing the (now blank) list field from the view does not restore the votingapi options in the view edit page.
However, clearing the cache (via devel module) restores the voteapi fields to the view edit page, albeit temporarily.
Comment #2
raintonr commentedInvestigating further, I tried this:
- Fixed a broken view.
- Wrote a cron job which ran every 5 minutes to check view was still valid.
I did this around 12:30 (just after midday) and the cron job reported the view broken 9am the following day, so it lasted about 20h30m. Cron on our site runs every 15 if that is a clue.
FWIW, when I say 'fixed a broken view' - there are 3 views on our site using vote results. Fixing one seems to fix them all. When one breaks, they all do.
I tried
delete from cache_views;to see if things came back, but they don't. In order to 'fix' a view one has to delete the views API fields displayed in the table, after which point they miraculously return. Before deleting them the 'name', 'handler', etc. columns are blank (see attached grab).Still struggling with this then.
Comment #3
raintonr commentedFor a second time I fixed the view and left the cron job to watch it. This time fix was at 9:22pm, and it broke at 9:50pm the next day (24 hours and 28 minutes later).
Does this give anyone more clues?
Comment #4
raintonr commentedAh-ha!
This may be it... I discovered the
votingapi_views.incfile is included (withrequire_once) from within the functionvotingapi_menu.This function is not called during parts of the views process and therefore the voting fields disappear. A simple fix seems to be to move the
require_onceline from it's check withvotingapi_menuto just above that function in thevotingapi.modulefile.Comment #5
raintonr commentedI'm closing this issue as it's a votingapi.module bug. Issue raised there:
http://drupal.org/node/189311