Skip to:
Content

BuddyPress.org

Opened 12 years ago

Closed 12 years ago

#4314 closed defect (bug) (fixed)

Invalid SQL query in BP_Groups_Group->get_global_forum_topic_count()

Reported by: djpaul's profile DJPaul Owned by: djpaul's profile DJPaul
Milestone: 1.6 Priority: normal
Severity: normal Version: 1.5.5
Component: Groups Keywords:
Cc:

Description

I am seeing the following message on a group's front page when there is a widget in the sidebar which uses the groups loop:

`[29-Jun-2012 15:39:00] WordPress database error 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 '(gm.meta_key = 'forum_id' AND gm.meta_value = t.forum_id) AND t.topic_status = at line 1 for query SELECT COUNT(t.topic_id) FROM wp_bb_topics AS t, wp_bp_groups AS g LEFT JOIN wp_bp_groups_groupmeta AS gm ON g.id = gm.group_id WHERE (gm.meta_key = 'forum_id' AND gm.meta_value = t.forum_id) AND g.status = 'public' AND t.topic_status = '0' AND t.topic_sticky != '2' (gm.meta_key = 'forum_id' AND gm.meta_value = t.forum_id) AND t.topic_status = '0' made by require, wp, WP->main, do_action_ref_array, call_user_func_array, bp_screens, do_action, call_user_func_array, groups_screen_group_home, bp_core_load_template, load_template, require_once, locate_template, load_template, require_once, dynamic_sidebar, call_user_func_array, WP_Widget->display_callback, Latest_Activity_Widget->widget, bp_has_forum_topics, BP_Forums_Template_Forum->construct, groups_total_public_forum_topic_count, BP_Groups_Group->get_global_forum_topic_count
`

The Latest_Activity_Widget is custom and is super simple, I can share the code for that privately if needed. In BP_Groups_Group->get_global_forum_topic_count(), the $extra_sql parameter is set from $bp->groups->filter_sql. It does not include an "AND" at the start of the statement, making the query invalid.

This does not exist on BP 1.2.10, and I'm seeing it when upgrading a site straight to 1.5.5. Can anyone else recreate this issue?

Change History (5)

#1 @boonebgorges
12 years ago

Confirmed. Do you think it's better to add the 'AND' in get_global_forum_topic_count() when concatenating, or in groups_add_forum_where_sql() before handing the value back? I'm thinking the former will be better for backpat (if that's a concern).

#2 @DJPaul
12 years ago

In get_global_forum_topic_count(), I agree. Site that I found this issue on, I quick-fixed in the same way.

#3 @boonebgorges
12 years ago

Have at it, my good man.

#4 @DJPaul
12 years ago

  • Milestone changed from Awaiting Review to 1.6
  • Owner set to DJPaul
  • Status changed from new to assigned

#5 @djpaul
12 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [6153]) Prevent invalid SQL query when getting global forum topic count. Fixes #4314, also see #4306. Props boonebgorges for initial patch.

  • The 'groups_total_public_forum_topic_count' filter in groups_total_public_forum_topic_count() has been deprecated, and will be removed in BP 1.7.
  • Use the new 'get_global_forum_topic_count_extra_sql' filter instead.
Note: See TracTickets for help on using tickets.