Skip to:
Content

bbPress.org


Ignore:
Timestamp:
12/27/2016 11:07:27 PM (7 years ago)
Author:
johnjamesjacoby
Message:

Tools: Avoid duplicate entries for favorites & subscriptions.

This fixes a bug in the 2.6.0 upgrade routine where running the tool multiple times could add duplicate metadata.

See #2959.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/tools.php

    r6183 r6188  
    22462246        // Add user ID to all favorited posts
    22472247        foreach ( $post_ids as $post_id ) {
     2248
     2249            // Skip if already exists
     2250            if ( $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(*) FROM {$bbp_db->postmeta} WHERE post_id = %d AND meta_key = %s AND meta_value = %d" ), $post_id, '_bbp_favorite', $meta->user_id ) ) {
     2251                continue;
     2252            }
     2253
     2254            // Add the post meta
    22482255            $added = add_post_meta( $post_id, '_bbp_favorite', $meta->user_id, false );
    22492256
     
    23022309        // Add user ID to all favorited posts
    23032310        foreach ( $post_ids as $post_id ) {
     2311
     2312            // Skip if already exists
     2313            if ( $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(*) FROM {$bbp_db->postmeta} WHERE post_id = %d AND meta_key = %s AND meta_value = %d" ), $post_id, '_bbp_subscription', $meta->user_id ) ) {
     2314                continue;
     2315            }
     2316
     2317            // Add the post meta
    23042318            $added = add_post_meta( $post_id, '_bbp_subscription', $meta->user_id, false );
    23052319
Note: See TracChangeset for help on using the changeset viewer.