Skip to:
Content

BuddyPress.org

Ticket #6431: 6431.3.patch

File 6431.3.patch, 10.3 KB (added by dcavins, 8 years ago)

Fix up legacy forum functions to avoid use of get_group_extras().

  • src/bp-groups/classes/class-bp-groups-group.php

    diff --git src/bp-groups/classes/class-bp-groups-group.php src/bp-groups/classes/class-bp-groups-group.php
    index 9b89695..4ef990c 100644
    class BP_Groups_Group { 
    13201320
    13211321                if ( !empty( $user_id ) ) {
    13221322                        $user_id      = absint( esc_sql( $user_id ) );
    1323                         $paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY f.topics DESC {$pag_sql}" );
    1324                         $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql}" );
     1323                        $paged_group_ids = $wpdb->get_results( "SELECT DISTINCT g.id FROM {$bp->groups->table_name_groupmeta} gm, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm.group_id AND (gm.meta_key = 'forum_id' AND gm.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY f.topics DESC {$pag_sql}" );
     1324                        $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm.group_id AND (gm.meta_key = 'forum_id' AND gm.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql}" );
    13251325                } else {
    1326                         $paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} {$exclude_sql} ORDER BY f.topics DESC {$pag_sql}" );
    1327                         $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} {$exclude_sql}" );
     1326                        $paged_group_ids = $wpdb->get_results( "SELECT DISTINCT g.id FROM {$bp->groups->table_name_groupmeta} gm, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm.group_id AND (gm.meta_key = 'forum_id' AND gm.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} {$exclude_sql} ORDER BY f.topics DESC {$pag_sql}" );
     1327                        $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm.group_id AND (gm.meta_key = 'forum_id' AND gm.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} {$exclude_sql}" );
    13281328                }
    13291329
    1330                 if ( !empty( $populate_extras ) ) {
    1331                         foreach ( (array) $paged_groups as $group ) {
    1332                                 $group_ids[] = $group->id;
     1330                $uncached_group_ids = bp_get_non_cached_ids( $paged_group_ids, 'bp_groups' );
     1331                if ( $uncached_group_ids ) {
     1332                        $group_ids_sql = implode( ',', array_map( 'intval', $uncached_group_ids ) );
     1333                        $group_data_objects = $wpdb->get_results( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id IN ({$group_ids_sql})" );
     1334                        foreach ( $group_data_objects as $group_data_object ) {
     1335                                wp_cache_set( $group_data_object->id, $group_data_object, 'bp_groups' );
    13331336                        }
    1334                         $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
    13351337                }
    13361338
    1337                 return array( 'groups' => $paged_groups, 'total' => $total_groups );
     1339                $paged_groups = array();
     1340                foreach ( $paged_group_ids as $paged_group_id ) {
     1341                        $paged_groups[] = new BP_Groups_Group( $paged_group_id );
     1342                }
     1343
     1344                return array( 'groups' => $paged_groups, 'total' => (int) $total_groups );
    13381345        }
    13391346
    13401347        /**
    class BP_Groups_Group { 
    14261433
    14271434                if ( !empty( $user_id ) ) {
    14281435                        $user_id = esc_sql( $user_id );
    1429                         $paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY f.posts ASC {$pag_sql}" );
    1430                         $total_groups = $wpdb->get_results( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.posts > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} " );
     1436                        $paged_group_ids = $wpdb->get_results( "SELECT DISTINCT g.id FROM {$bp->groups->table_name_groupmeta} gm, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm.group_id AND (gm.meta_key = 'forum_id' AND gm.meta_value = f.forum_id) {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY f.posts ASC {$pag_sql}" );
     1437                        $total_groups = $wpdb->get_results( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm.group_id AND (gm.meta_key = 'forum_id' AND gm.meta_value = f.forum_id) AND f.posts > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} " );
    14311438                } else {
    1432                         $paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.posts > 0 {$hidden_sql} {$search_sql} {$exclude_sql} ORDER BY f.posts ASC {$pag_sql}" );
    1433                         $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) {$hidden_sql} {$search_sql} {$exclude_sql}" );
     1439                        $paged_group_ids = $wpdb->get_results( "SELECT DISTINCT g.id FROM {$bp->groups->table_name_groupmeta} gm, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm.group_id AND (gm.meta_key = 'forum_id' AND gm.meta_value = f.forum_id) AND f.posts > 0 {$hidden_sql} {$search_sql} {$exclude_sql} ORDER BY f.posts ASC {$pag_sql}" );
     1440                        $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm.group_id AND (gm.meta_key = 'forum_id' AND gm.meta_value = f.forum_id) {$hidden_sql} {$search_sql} {$exclude_sql}" );
    14341441                }
    14351442
    1436                 if ( !empty( $populate_extras ) ) {
    1437                         foreach ( (array) $paged_groups as $group ) {
    1438                                 $group_ids[] = $group->id;
     1443                $uncached_group_ids = bp_get_non_cached_ids( $paged_group_ids, 'bp_groups' );
     1444                if ( $uncached_group_ids ) {
     1445                        $group_ids_sql = implode( ',', array_map( 'intval', $uncached_group_ids ) );
     1446                        $group_data_objects = $wpdb->get_results( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id IN ({$group_ids_sql})" );
     1447                        foreach ( $group_data_objects as $group_data_object ) {
     1448                                wp_cache_set( $group_data_object->id, $group_data_object, 'bp_groups' );
    14391449                        }
    1440                         $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
    14411450                }
    14421451
    1443                 return array( 'groups' => $paged_groups, 'total' => $total_groups );
     1452                $paged_groups = array();
     1453                foreach ( $paged_group_ids as $paged_group_id ) {
     1454                        $paged_groups[] = new BP_Groups_Group( $paged_group_id );
     1455                }
     1456
     1457                return array( 'groups' => $paged_groups, 'total' => (int) $total_groups );
    14441458        }
    14451459
    14461460        /**