Skip to:
Content

bbPress.org

Changeset 948


Ignore:
Timestamp:
09/24/2007 06:07:29 PM (19 years ago)
Author:
mdawaffe
Message:

revert bb_pull_cols stuff since get_cols won't actually change. Fixes #728 #744

Location:
trunk/bb-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-includes/bozo.php

    r916 r948  
    7777        $old = (array) $bbdb->get_col("SELECT topic_id FROM $bbdb->topicmeta WHERE meta_key = 'bozos'");
    7878        $old = array_flip($old);
    79         if ( $topics = (array) $bbdb->get_results("SELECT topic_id, poster_id, COUNT(post_id) AS count FROM $bbdb->posts WHERE post_status > 1 GROUP BY topic_id, poster_id") ) :
    80             list($topic_ids, $poster_ids, $counts) = bb_pull_cols( $topics, 'topic_id', 'poster_id', 'count' );
     79        if ( $topics = (array) $bbdb->get_col("SELECT topic_id, poster_id, COUNT(post_id) FROM $bbdb->posts WHERE post_status > 1 GROUP BY topic_id, poster_id") ) :
    8180            echo "\t\t" . __("Counting bozo posts...") . "<br />\n";
    82             $unique_topics = array_unique($topic_ids);
     81            $unique_topics = array_unique($topics);
     82            $posters = (array) $bbdb->get_col('', 1);
     83            $counts = (array) $bbdb->get_col('', 2);
    8384            foreach ($unique_topics as $i):
    8485                $bozos = array();
    85                 $indices = array_keys($topic_ids, $i);
     86                $indices = array_keys($topics, $i);
    8687                foreach ( $indices as $index )
    87                     $bozos[(int) $poster_ids[$index]] = (int) $counts[$index];
     88                    $bozos[(int) $posters[$index]] = (int) $counts[$index];
    8889                if ( $bozos ) :
    8990                    bb_update_topicmeta( $i, 'bozos', $bozos );
     
    9192                endif;
    9293            endforeach;
    93             unset($topics, $topic_ids, $poster_ids, $counts, $unique_topics, $i, $bozos);
     94            unset($topics, $t, $i, $counts, $posters, $bozos);
    9495        endif;
    9596        if ( $old ) :
     
    112113                $topics_replied = (int) $bbdb->get_var("SELECT COUNT(DISTINCT topic_id) FROM $bbdb->posts WHERE post_status = 0 AND poster_id = '$user'");
    113114                bb_update_usermeta( $user, $bb_table_prefix. 'topics_replied', $topics_replied );
    114                 $bozos = (array) $bbdb->get_results("SELECT topic_id, COUNT(post_id) AS count FROM $bbdb->posts WHERE post_status > 1 AND poster_id = '$user' GROUP BY topic_id");
    115                 if ( $c = count($bozos) ) :
    116                     $bozo_topics = array();
     115                $bozo_keys = (array) $bbdb->get_col("SELECT topic_id, COUNT(post_id) FROM $bbdb->posts WHERE post_status > 1 AND poster_id = '$user' GROUP BY topic_id");
     116                $bozo_values = (array) $bbdb->get_col('', 1);
     117                if ( $c = count($bozo_keys) ) :
    117118                    for ( $i=0; $i < $c; $i++ )
    118                         $bozo_topics[(int) $bozos[$i]->topic_id] = (int) $bozos[$i]->count;
     119                        $bozo_topics[(int) $bozo_keys[$i]] = (int) $bozo_values[$i];
    119120                    bb_update_usermeta( $user, $bozo_mkey, $bozo_topics );
    120121                else :
     
    126127                $bbdb->query("DELETE FROM $bbdb->usermeta WHERE user_id IN ($no_bozos) AND meta_key = '$bozo_mkey'");
    127128            endif;
     129            unset($users, $user, $topics_replied, $bozo_keys, $bozo_values, $bozo_topics);
    128130        endif;
    129131        _e("Done counting bozo topics.\n\n");
  • trunk/bb-includes/deprecated.php

    r941 r948  
    492492endif;
    493493
     494// With no extra arguments, converts array of objects into object of arrays
     495// With extra arguments corresponding to name of object properties, returns array of arrays:
     496//     list($a, $b) = bb_pull_cols( $obj_array, 'a', 'b' );
     497function bb_pull_cols( $obj_array ) {
     498    $r = new stdClass;
     499    foreach ( array_keys($obj_array) as $o )
     500        foreach ( get_object_vars( $obj_array[$o] ) as $k => $v )
     501            $r->{$k}[] = $v;
     502
     503    if ( 1 == func_num_args() )
     504        return $r;
     505
     506    $args = func_get_args();
     507    $args = array_splice($args, 1);
     508
     509    $a = array();
     510    foreach ( $args as $arg )
     511        $a[] = $r->$arg;
     512    return $a;
     513}
    494514
    495515?>
  • trunk/bb-includes/functions.php

    r940 r948  
    347347    if ( !isset( $thread_ids_cache[$topic_id] ) ) {
    348348        $where = apply_filters('get_thread_post_ids_where', 'AND post_status = 0');
    349         $thread_ids = (array) $bbdb->get_results("SELECT post_id, poster_id FROM $bbdb->posts WHERE topic_id = $topic_id $where ORDER BY post_time");
    350         list($thread_ids_cache[$topic_id]['post'], $thread_ids_cache[$topic_id]['poster']) = bb_pull_cols( $thread_ids, 'post_id', 'poster_id' );
     349        $thread_ids_cache[$topic_id]['post'] = (array) $bbdb->get_col("SELECT post_id, poster_id FROM $bbdb->posts WHERE topic_id = $topic_id $where ORDER BY post_time");
     350        $thread_ids_cache[$topic_id]['poster'] = (array) $bbdb->get_col('', 1);
    351351    }
    352352    return $thread_ids_cache[$topic_id];
     
    793793
    794794    // We care about the tag in this topic and if it's in other topics, but not which other topics
    795     $topics = (array) $bbdb->get_results("SELECT topic_id, COUNT(*) AS count FROM $bbdb->tagged WHERE tag_id = '$tag_id' GROUP BY topic_id = '$topic_id'");
    796     list($topic_ids, $counts) = bb_pull_topics( $topics, 'topic_id', 'count' );
    797 
    798     if ( !$here = $counts[$topic_ids[$topic_id]] ) // Topic doesn't have this tag
     795    $topics = array_flip((array) $bbdb->get_col("SELECT topic_id, COUNT(*) FROM $bbdb->tagged WHERE tag_id = '$tag_id' GROUP BY topic_id = '$topic_id'"));
     796    $counts = (array) $bbdb->get_col('', 1);
     797    if ( !$here = $counts[$topics[$topic_id]] ) // Topic doesn't have this tag
    799798        return false;
    800799
     
    22502249}
    22512250
    2252 // With no extra arguments, converts array of objects into object of arrays
    2253 // With extra arguments corresponding to name of object properties, returns array of arrays:
    2254 //     list($a, $b) = bb_pull_cols( $obj_array, 'a', 'b' );
    2255 function bb_pull_cols( $obj_array ) {
    2256     $r = new stdClass;
    2257     foreach ( array_keys($obj_array) as $o )
    2258         foreach ( get_object_vars( $obj_array[$o] ) as $k => $v )
    2259             $r->{$k}[] = $v;
    2260 
    2261     if ( 1 == func_num_args() )
    2262         return $r;
    2263 
    2264     $args = func_get_args();
    2265     $args = array_splice($args, 1);
    2266 
    2267     $a = array();
    2268     foreach ( $args as $arg )
    2269         $a[] = $r->$arg;
    2270     return $a;
    2271 }
    2272 
    22732251?>
Note: See TracChangeset for help on using the changeset viewer.