Ticket #5119: 5119.diff
File 5119.diff, 2.3 KB (added by , 12 years ago) |
---|
-
bp-groups/bp-groups-classes.php
353 353 $sql = array(); 354 354 $total_sql = array(); 355 355 356 $sql['select'] = "SELECT g.*, gm1.meta_value AS total_member_count, gm2.meta_value AS last_activity";356 $sql['select'] = "SELECT DISTINCT g.id as not_used, g.*, gm1.meta_value AS total_member_count, gm2.meta_value AS last_activity"; 357 357 $sql['from'] = " FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2,"; 358 358 359 359 if ( ! empty( $r['user_id'] ) ) { … … 468 468 // See #5099 469 469 if ( ! empty( $meta_query_sql['where'] ) ) { 470 470 // Join the groupmeta table 471 $total_sql['select'] .= ", {$bp->groups->table_name_groupmeta} gmmq";471 $total_sql['select'] .= ", ". substr( $meta_query_sql['join'], 0, -2 ); 472 472 473 473 // Modify the meta_query clause from paged_sql for our syntax 474 474 $meta_query_clause = preg_replace( '/^\s*AND/', '', $meta_query_sql['where'] ); 475 $meta_query_clause = str_replace( $bp->groups->table_name_groupmeta, 'gmmq', $meta_query_clause );476 475 $total_sql['where'][] = $meta_query_clause; 477 476 } 478 477 … … 560 559 // @todo It may be better in the long run to refactor 561 560 // the more general query syntax to accord better with 562 561 // BP/WP convention 563 preg_match( '/INNER JOIN (.*) ON/', $meta_sql['join'], $matches_a ); 564 preg_match( '/ON \((.*)\)$/', $meta_sql['join'], $matches_b ); 562 preg_match_all( '/INNER JOIN (.*) ON/', $meta_sql['join'], $matches_a ); 563 preg_match_all( '/ON \((.*)\)/', $meta_sql['join'], $matches_b ); 564 $array_where = explode( "\n", $meta_sql['where'] ); 565 565 566 if ( ! empty( $matches_a[1] ) && ! empty( $matches_b[1] ) ) { 566 $sql_array['join'] = $matches_a[1] . ', '; 567 $sql_array['where'] = preg_replace( '/^(\sAND\s+[\(\s]+)/', '$1' . $matches_b[1] . ' AND ', $meta_sql['where'] ); 567 $sql_array['join'] = implode( ',', $matches_a[1] ). ', '; 568 569 $sql_array['where'] = ''; 570 571 foreach( $matches_b[1] as $key => $group_id_clause ) { 572 $sql_array['where'] .= ' ' .preg_replace( '/^(AND\s+[\(\s]+)/', '$1' . $group_id_clause . ' AND ', ltrim( $array_where[$key] ) ); 573 } 574 568 575 } 569 576 } 570 577