Skip to:
Content

BuddyPress.org

Changeset 1048


Ignore:
Timestamp:
02/10/2009 08:50:05 PM (16 years ago)
Author:
apeatling
Message:

Fixes #464

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r1040 r1048  
    306306}
    307307
    308 function bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ) {
     308function bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ) { 
    309309    if ( !BP_Activity_Activity::delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ) )
    310310        return false;
  • trunk/bp-activity/bp-activity-classes.php

    r1038 r1048  
    8686    function delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id = false ) {
    8787        global $wpdb, $bp;
    88        
     88               
    8989        if ( !$user_id )
    9090            return false;
     
    9494       
    9595        if ( $secondary_item_id )
    96             $secondary_sql = $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id );
    97        
    98         //error_log($wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) );
    99         //error_log($wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity_cached WHERE item_id = %d{$secondary_sql} AND component_name = %s AND component_action = %s", $item_id, $component_name, $component_action ) );
    100         //error_log($wpdb->prepare( "DELETE FROM " . $bp->activity->table_name_sitewide . " WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) );
    101        
    102         $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) );
     96            $secondary_sql = $wpdb->prepare( "AND secondary_item_id = %d", $secondary_item_id );
     97       
     98        if ( $component_action ) {
     99            $component_action_sql = $wpdb->prepare( "AND component_action = %s AND user_id = %d", $component_action, $user_id );
     100            $cached_component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action );
     101        }
     102       
     103        error_log( $component_action );
     104       
     105        error_log( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity WHERE item_id = %d {$secondary_sql} AND component_name = %s {$component_action_sql}", $item_id, $component_name ) );
     106        error_log( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity_cached WHERE item_id = %d {$secondary_sql} AND component_name = %s {$cached_component_action_sql}", $item_id, $component_name ) );
     107        error_log( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_sitewide} WHERE item_id = %d {$secondary_sql} AND component_name = %s {$component_action_sql}", $item_id, $component_name ) );
     108       
     109        $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity WHERE item_id = %d {$secondary_sql} AND component_name = %s {$component_action_sql}", $item_id, $component_name ) );
    103110               
    104111        // Delete this entry from the users' cache table and the sitewide cache table
    105         $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity_cached WHERE item_id = %d{$secondary_sql} AND component_name = %s AND component_action = %s", $item_id, $component_name, $component_action ) );
    106         $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_sitewide} WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) );
     112        $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity_cached WHERE item_id = %d {$secondary_sql} AND component_name = %s {$cached_component_action_sql}", $item_id, $component_name ) );
     113        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_sitewide} WHERE item_id = %d {$secondary_sql} AND component_name = %s {$component_action_sql}", $item_id, $component_name ) );
    107114       
    108115        return true;
  • trunk/bp-blogs.php

    r1032 r1048  
    268268        break;
    269269        case 'new_blog_post':
    270             $post = new BP_Blogs_Post($item_id);
     270            $post = new BP_Blogs_Post($secondary_item_id);
    271271           
    272272            if ( !$post )
     
    296296                return false;
    297297
    298             $comment = new BP_Blogs_Comment($item_id);
     298            $comment = new BP_Blogs_Comment($secondary_item_id);
    299299           
    300300            if ( !$comment )
     
    432432           
    433433            // Record in activity streams
    434             bp_blogs_record_activity( array( 'item_id' => $recorded_post_id, 'component_name' => 'blogs', 'component_action' => 'new_blog_post', 'is_private' => $is_private, 'user_id' => $recorded_post->user_id ) );
     434            bp_blogs_record_activity( array( 'item_id' => $recorded_post->blog_id, 'secondary_item_id' => $recorded_post_id, 'component_name' => 'blogs', 'component_action' => 'new_blog_post', 'is_private' => $is_private, 'user_id' => $recorded_post->user_id ) );
    435435        }
    436436    } else {
     
    508508               
    509509                // Record in activity streams
    510                 bp_blogs_record_activity( array( 'item_id' => $recorded_commment_id, 'component_name' => 'blogs', 'component_action' => 'new_blog_comment', 'is_private' => $is_private, 'user_id' => $recorded_comment->user_id ) );
     510                bp_blogs_record_activity( array( 'item_id' => $recorded_comment->blog_id, 'secondary_item_id' => $recorded_commment_id, 'component_name' => 'blogs', 'component_action' => 'new_blog_comment', 'is_private' => $is_private, 'user_id' => $recorded_comment->user_id ) );
    511511            }
    512512        } else {
     
    635635
    636636function bp_blogs_remove_data_for_blog( $blog_id ) {
     637    global $bp;
     638   
    637639    /* If this is regular blog, delete all data for that blog. */
    638640    BP_Blogs_Blog::delete_blog_for_all( $blog_id );
    639641    BP_Blogs_Post::delete_posts_for_blog( $blog_id );       
    640642    BP_Blogs_Comment::delete_comments_for_blog( $blog_id );
     643
     644    // Delete activity stream item
     645    bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component_name' => 'blogs', 'component_action' => false, 'user_id' => $bp->loggedin_user->id ) );
    641646
    642647    do_action( 'bp_blogs_remove_data_for_blog', $blog_id );
     
    722727
    723728    if ( !$meta_key ) {
    724         $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->blogs->table_name_blogpmeta . " WHERE blog_id = %d", $blog_id ) );     
     729        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id ) );     
    725730    } else if ( !$meta_value ) {
    726731        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s AND meta_value = %s", $blog_id, $meta_key, $meta_value ) );
  • trunk/bp-blogs/bp-blogs-classes.php

    r1041 r1048  
    2121        global $wpdb, $bp;
    2222       
    23         $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp->blogs->table_name . " WHERE id = %d", $this->id ) );
     23        $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) );
    2424
    2525        $this->user_id = $blog->user_id;
     
    4040        if ( $this->id ) {
    4141            // Update
    42             $sql = $wpdb->prepare( "UPDATE " . $bp->blogs->table_name . " SET user_id = %d, blog_id = %d WHERE id = %d", $this->user_id, $this->blog_id, $this->id );
     42            $sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name} SET user_id = %d, blog_id = %d WHERE id = %d", $this->user_id, $this->blog_id, $this->id );
    4343        } else {
    4444            // Save
    45             $sql = $wpdb->prepare( "INSERT INTO " . $bp->blogs->table_name . " ( user_id, blog_id ) VALUES ( %d, %d )", $this->user_id, $this->blog_id );
     45            $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name} ( user_id, blog_id ) VALUES ( %d, %d )", $this->user_id, $this->blog_id );
    4646        }
    4747       
     
    5858        global $bp, $wpdb;
    5959       
    60         return $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM " . $bp->blogs->table_name . " WHERE user_id = %d AND blog_id = %d", $this->user_id, $this->blog_id ) );
     60        return $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $this->user_id, $this->blog_id ) );
    6161    }
    6262   
     
    6666        global $wpdb, $bp;
    6767       
     68        if ( !$bp->blogs )
     69            bp_blogs_setup_globals();
     70       
    6871        bp_blogs_delete_blogmeta( $blog_id );
    6972
    70         return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->blogs->table_name . " WHERE blog_id = %d", $blog_id ) );
     73        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
    7174    }
    7275   
     
    7477        global $wpdb, $bp;
    7578       
     79        if ( !$bp->blogs )
     80            bp_blogs_setup_globals();
     81       
    7682        if ( !$user_id )
    7783            $user_id = $bp->loggedin_user->id;
    7884
    79         return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->blogs->table_name . " WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
     85        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
    8086    }
    8187   
    8288    function delete_blogs_for_user( $user_id = null ) {
    8389        global $wpdb, $bp;
     90       
     91        if ( !$bp->blogs )
     92            bp_blogs_setup_globals();
    8493
    8594        if ( !$user_id )
    8695            $user_id = $bp->loggedin_user->id;
    8796
    88         return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->blogs->table_name . " WHERE user_id = %d", $user_id ) );
     97        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
    8998    }
    9099   
    91100    function get_blogs_for_user( $user_id = null ) {
    92101        global $bp, $wpdb;
     102       
     103        if ( !$bp->blogs )
     104            bp_blogs_setup_globals();
    93105       
    94106        if ( !$user_id )
     
    97109        // Show logged in users their hidden blogs.
    98110        if ( !bp_is_home() )
    99             $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM " . $bp->blogs->table_name . " b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ", $user_id) );
     111            $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ", $user_id) );
    100112        else
    101             $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM " . $bp->blogs->table_name . " b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ", $user_id) );
     113            $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ", $user_id) );
    102114           
    103115        $total_blog_count = BP_Blogs_Blog::total_blog_count( $user_id );
     
    121133            bp_blogs_setup_globals();
    122134       
    123         return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM " . $bp->blogs->table_name . " WHERE blog_id = %d", $blog_id ) );
     135        return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
    124136    }
    125137   
     
    135147        // If the user is logged in return the blog count including their hidden blogs.
    136148        if ( !bp_is_home() )
    137             return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(b.blog_id) FROM " . $bp->blogs->table_name . " b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );
     149            return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );
    138150        else
    139             return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(b.blog_id) FROM " . $bp->blogs->table_name . " b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );           
     151            return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );         
    140152    }
    141153   
    142154    function get_all( $limit = null, $page = null ) {
    143155        global $bp, $wpdb;
     156       
     157        if ( !$bp->blogs )
     158            bp_blogs_setup_globals();
    144159       
    145160        if ( $limit && $page ) {
     
    155170    function get_by_letter( $letter, $limit = null, $page = null ) {
    156171        global $bp, $wpdb;
     172       
     173        if ( !$bp->blogs )
     174            bp_blogs_setup_globals();
    157175       
    158176        like_escape($letter);
     
    171189        global $wpdb, $bp;
    172190       
     191        if ( !$bp->blogs )
     192            bp_blogs_setup_globals();
     193       
    173194        like_escape($filter);
    174195       
     
    186207        global $bp, $wpdb;
    187208       
     209        if ( !$bp->blogs )
     210            bp_blogs_setup_globals();
     211       
    188212        if ( $limit && $page ) {
    189213            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    190             $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(b.blog_id) FROM " . $bp->blogs->table_name . " b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY rand()" ) );
    191         }
    192        
    193         $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM " . $bp->blogs->table_name . " b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0  ORDER BY rand() {$pag_sql}" ) );       
     214            $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY rand()" ) );
     215        }
     216       
     217        $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0  ORDER BY rand() {$pag_sql}" ) );         
    194218       
    195219        return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
     
    198222    function is_hidden( $blog_id ) {
    199223        global $wpdb;
     224
     225        if ( !$bp->blogs )
     226            bp_blogs_setup_globals();
    200227       
    201228        if ( !(int)$wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT public FROM {$wpdb->base_prefix}blogs WHERE blog_id = %d", $blog_id ) ) )
     
    263290    function delete( $post_id, $blog_id ) {
    264291        global $wpdb, $bp, $current_user;
     292       
     293        if ( !$bp->blogs )
     294            bp_blogs_setup_globals();
    265295
    266296        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d AND post_id = %d", $blog_id, $post_id ) );
     
    270300        global $wpdb, $bp;
    271301       
     302        if ( !$bp->blogs )
     303            bp_blogs_setup_globals();
     304       
    272305        if ( !$user_id )
    273306            $user_id = $current_user->ID;
     
    278311    function delete_posts_for_user( $user_id = null ) {
    279312        global $wpdb, $bp;
     313       
     314        if ( !$bp->blogs )
     315            bp_blogs_setup_globals();
    280316
    281317        if ( !$user_id )
     
    288324        global $wpdb, $bp;
    289325       
     326        if ( !$bp->blogs )
     327            bp_blogs_setup_globals();
     328       
    290329        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d", $blog_id ) );
    291330    }
     
    293332    function get_latest_posts( $blog_id = null, $limit = 5 ) {
    294333        global $wpdb, $bp;
     334       
     335        if ( !$bp->blogs )
     336            bp_blogs_setup_globals();
    295337       
    296338        if ( $blog_id )
     
    308350    function get_posts_for_user( $user_id = null ) {
    309351        global $bp, $wpdb;
     352       
     353        if ( !$bp->blogs )
     354            bp_blogs_setup_globals();
    310355       
    311356        if ( !$user_id )
     
    442487    function delete( $comment_id, $blog_id ) {
    443488        global $wpdb, $bp, $current_user;
     489       
     490        if ( !$bp->blogs )
     491            bp_blogs_setup_globals();
    444492           
    445493        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE comment_id = %d AND blog_id = %d", $comment_id, $blog_id ) );
     
    449497        global $wpdb, $bp, $current_user;
    450498       
     499        if ( !$bp->blogs )
     500            bp_blogs_setup_globals();
     501       
    451502        if ( !$user_id )
    452503            $user_id = $current_user->ID;
     
    457508    function delete_comments_for_user( $user_id = null ) {
    458509        global $wpdb, $bp;
     510       
     511        if ( !$bp->blogs )
     512            bp_blogs_setup_globals();
    459513
    460514        if ( !$user_id )
     
    467521        global $wpdb, $bp;
    468522       
     523        if ( !$bp->blogs )
     524            bp_blogs_setup_globals();
     525       
    469526        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE blog_id = %d", $blog_id ) );
    470527    }
     
    472529    function get_comments_for_user( $user_id = null ) {
    473530        global $bp, $wpdb;
     531       
     532        if ( !$bp->blogs )
     533            bp_blogs_setup_globals();
    474534
    475535        if ( !$user_id )
Note: See TracChangeset for help on using the changeset viewer.