Skip to:
Content

bbPress.org

Changeset 5157


Ignore:
Timestamp:
11/20/2013 08:44:58 PM (8 years ago)
Author:
johnjamesjacoby
Message:

Forum Subscriptions:

  • Update @since and @deprecated to r5156.
  • Introduce tool for removing trashed and deleted forums from user subscriptions.
  • See #2299. Props netweb.
Location:
trunk/includes
Files:
7 edited

Legend:

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

    r5133 r5157  
    159159function bbp_admin_repair_list() {
    160160    $repair_list = array(
    161         0  => array( 'bbp-sync-topic-meta',        __( 'Recalculate the parent topic for each post',        'bbpress' ), 'bbp_admin_repair_topic_meta'               ),
    162         5  => array( 'bbp-sync-forum-meta',        __( 'Recalculate the parent forum for each post',        'bbpress' ), 'bbp_admin_repair_forum_meta'               ),
    163         10 => array( 'bbp-sync-forum-visibility',  __( 'Recalculate private and hidden forums',             'bbpress' ), 'bbp_admin_repair_forum_visibility'         ),
    164         15 => array( 'bbp-sync-all-topics-forums', __( 'Recalculate last activity in each topic and forum', 'bbpress' ), 'bbp_admin_repair_freshness'                ),
    165         20 => array( 'bbp-sync-all-topics-sticky', __( 'Recalculate the sticky relationship of each topic', 'bbpress' ), 'bbp_admin_repair_sticky'                   ),
    166         25 => array( 'bbp-group-forums',           __( 'Repair BuddyPress Group Forum relationships',       'bbpress' ), 'bbp_admin_repair_group_forum_relationship' ),
    167         30 => array( 'bbp-forum-topics',           __( 'Count topics in each forum',                        'bbpress' ), 'bbp_admin_repair_forum_topic_count'        ),
    168         35 => array( 'bbp-forum-replies',          __( 'Count replies in each forum',                       'bbpress' ), 'bbp_admin_repair_forum_reply_count'        ),
    169         40 => array( 'bbp-topic-replies',          __( 'Count replies in each topic',                       'bbpress' ), 'bbp_admin_repair_topic_reply_count'        ),
    170         45 => array( 'bbp-topic-voices',           __( 'Count voices in each topic',                        'bbpress' ), 'bbp_admin_repair_topic_voice_count'        ),
    171         50 => array( 'bbp-topic-hidden-replies',   __( 'Count spammed & trashed replies in each topic',     'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ),
    172         55 => array( 'bbp-user-topics',            __( 'Count topics for each user',                        'bbpress' ), 'bbp_admin_repair_user_topic_count'         ),
    173         60 => array( 'bbp-user-replies',           __( 'Count replies for each user',                       'bbpress' ), 'bbp_admin_repair_user_reply_count'         ),
    174         65 => array( 'bbp-user-favorites',         __( 'Remove trashed topics from user favorites',         'bbpress' ), 'bbp_admin_repair_user_favorites'           ),
    175         70 => array( 'bbp-user-subscriptions',     __( 'Remove trashed topics from user subscriptions',     'bbpress' ), 'bbp_admin_repair_user_subscriptions'       ),
    176         75 => array( 'bbp-user-role-map',          __( 'Remap existing users to default forum roles',       'bbpress' ), 'bbp_admin_repair_user_roles'               )
     161        0  => array( 'bbp-sync-topic-meta',          __( 'Recalculate the parent topic for each post',        'bbpress' ), 'bbp_admin_repair_topic_meta'               ),
     162        5  => array( 'bbp-sync-forum-meta',          __( 'Recalculate the parent forum for each post',        'bbpress' ), 'bbp_admin_repair_forum_meta'               ),
     163        10 => array( 'bbp-sync-forum-visibility',    __( 'Recalculate private and hidden forums',             'bbpress' ), 'bbp_admin_repair_forum_visibility'         ),
     164        15 => array( 'bbp-sync-all-topics-forums',   __( 'Recalculate last activity in each topic and forum', 'bbpress' ), 'bbp_admin_repair_freshness'                ),
     165        20 => array( 'bbp-sync-all-topics-sticky',   __( 'Recalculate the sticky relationship of each topic', 'bbpress' ), 'bbp_admin_repair_sticky'                   ),
     166        25 => array( 'bbp-group-forums',             __( 'Repair BuddyPress Group Forum relationships',       'bbpress' ), 'bbp_admin_repair_group_forum_relationship' ),
     167        30 => array( 'bbp-forum-topics',             __( 'Count topics in each forum',                        'bbpress' ), 'bbp_admin_repair_forum_topic_count'        ),
     168        35 => array( 'bbp-forum-replies',            __( 'Count replies in each forum',                       'bbpress' ), 'bbp_admin_repair_forum_reply_count'        ),
     169        40 => array( 'bbp-topic-replies',            __( 'Count replies in each topic',                       'bbpress' ), 'bbp_admin_repair_topic_reply_count'        ),
     170        45 => array( 'bbp-topic-voices',             __( 'Count voices in each topic',                        'bbpress' ), 'bbp_admin_repair_topic_voice_count'        ),
     171        50 => array( 'bbp-topic-hidden-replies',     __( 'Count spammed & trashed replies in each topic',     'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ),
     172        55 => array( 'bbp-user-topics',              __( 'Count topics for each user',                        'bbpress' ), 'bbp_admin_repair_user_topic_count'         ),
     173        60 => array( 'bbp-user-replies',             __( 'Count replies for each user',                       'bbpress' ), 'bbp_admin_repair_user_reply_count'         ),
     174        65 => array( 'bbp-user-favorites',           __( 'Remove trashed topics from user favorites',         'bbpress' ), 'bbp_admin_repair_user_favorites'           ),
     175        70 => array( 'bbp-user-topic-subscriptions', __( 'Remove trashed topics from user subscriptions',     'bbpress' ), 'bbp_admin_repair_user_topic_subscriptions' ),
     176        75 => array( 'bbp-user-forum-subscriptions', __( 'Remove trashed forums from user subscriptions',     'bbpress' ), 'bbp_admin_repair_user_forum_subscriptions' ),
     177        80 => array( 'bbp-user-role-map',            __( 'Remap existing users to default forum roles',       'bbpress' ), 'bbp_admin_repair_user_roles'               )
    177178    );
    178179    ksort( $repair_list );
     
    647648
    648649/**
    649  * Clean the users' subscriptions
     650 * Clean the users' topic subscriptions
    650651 *
    651652 * @since bbPress (r2668)
     
    656657 * @return array An array of the status code and the message
    657658 */
    658 function bbp_admin_repair_user_subscriptions() {
     659function bbp_admin_repair_user_topic_subscriptions() {
    659660    global $wpdb;
    660661
     
    677678
    678679        $subscriptions = array_intersect( $topics, explode( ',', $user->subscriptions ) );
     680        if ( empty( $subscriptions ) || !is_array( $subscriptions ) )
     681            continue;
     682
     683        $subscriptions_joined = implode( ',', $subscriptions );
     684        $values[]             = "('{$user->user_id}', '{$key}', '{$subscriptions_joined}')";
     685
     686        // Cleanup
     687        unset( $subscriptions, $subscriptions_joined );
     688    }
     689
     690    if ( !count( $values ) ) {
     691        $result = __( 'Nothing to remove!', 'bbpress' );
     692        return array( 0, sprintf( $statement, $result ) );
     693    }
     694
     695    $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';";
     696    if ( is_wp_error( $wpdb->query( $sql_delete ) ) )
     697        return array( 4, sprintf( $statement, $result ) );
     698
     699    foreach ( array_chunk( $values, 10000 ) as $chunk ) {
     700        $chunk = "\n" . implode( ",\n", $chunk );
     701        $sql_insert = "INSERT INTO `{$wpdb->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES $chunk;";
     702        if ( is_wp_error( $wpdb->query( $sql_insert ) ) ) {
     703            return array( 5, sprintf( $statement, $result ) );
     704        }
     705    }
     706
     707    return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) );
     708}
     709
     710/**
     711 * Clean the users' forum subscriptions
     712 *
     713 * @since bbPress (r5155)
     714 *
     715 * @uses bbp_get_forum_post_type() To get the topic post type
     716 * @uses wpdb::query() To run our recount sql queries
     717 * @uses is_wp_error() To check if the executed query returned {@link WP_Error}
     718 * @return array An array of the status code and the message
     719 */
     720function bbp_admin_repair_user_forum_subscriptions() {
     721    global $wpdb;
     722
     723    $statement = __( 'Removing trashed forums from user subscriptions… %s', 'bbpress' );
     724    $result    = __( 'Failed!', 'bbpress' );
     725    $key       = $wpdb->prefix . '_bbp_forum_subscriptions';
     726    $users     = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';" );
     727
     728    if ( is_wp_error( $users ) )
     729        return array( 1, sprintf( $statement, $result ) );
     730
     731    $forums = $wpdb->get_col( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" );
     732    if ( is_wp_error( $forums ) )
     733        return array( 2, sprintf( $statement, $result ) );
     734
     735    $values = array();
     736    foreach ( $users as $user ) {
     737        if ( empty( $user->subscriptions ) || !is_string( $user->subscriptions ) )
     738            continue;
     739
     740        $subscriptions = array_intersect( $forums, explode( ',', $user->subscriptions ) );
    679741        if ( empty( $subscriptions ) || !is_array( $subscriptions ) )
    680742            continue;
  • trunk/includes/common/functions.php

    r5156 r5157  
    11191119 * if there are, send notifications
    11201120 *
    1121  * @since bbPress (rxxxx)
     1121 * @since bbPress (r5156)
    11221122 *
    11231123 * @param int $topic_id ID of the newly made reply
  • trunk/includes/extend/buddypress/notifications.php

    r5155 r5157  
    5757 * for notifying topic and hierarchical reply authors of topic replies.
    5858 *
    59  * @since bbPress (rxxxx)
     59 * @since bbPress (r5156)
    6060 *
    6161 * @param int $reply_id
  • trunk/includes/forums/functions.php

    r5156 r5157  
    967967 * Remove a deleted forum from all users' subscriptions
    968968 *
    969  * @since bbPress (rxxxx)
     969 * @since bbPress (r5156)
    970970 *
    971971 * @param int $forum_id Get the forum ID to remove
  • trunk/includes/forums/template.php

    r5156 r5157  
    795795 * Output the forum subscription link
    796796 *
    797  * @since bbPress (rxxxx)
     797 * @since bbPress (r5156)
    798798 *
    799799 * @uses bbp_get_forum_subscription_link()
     
    808808     * A custom wrapper for bbp_get_user_subscribe_link()
    809809     *
    810      * @since bbPress (rxxxx)
     810     * @since bbPress (r5156)
    811811     *
    812812     * @uses bbp_parse_args()
     
    22152215 * Output checked value of forum subscription
    22162216 *
    2217  * @since bbPress (rxxxx)
     2217 * @since bbPress (r5156)
    22182218 *
    22192219 * @uses bbp_get_form_forum_subscribed() To get the subscribed checkbox value
     
    22252225     * Return checked value of forum subscription
    22262226     *
    2227      * @since bbPress (rxxxx)
     2227     * @since bbPress (r5156)
    22282228     *
    22292229     * @uses bbp_is_forum_edit() To check if it's the forum edit page
  • trunk/includes/topics/template.php

    r5156 r5157  
    18131813 * Output the topic subscription link
    18141814 *
    1815  * @since bbPress (rxxxx)
     1815 * @since bbPress (r5156)
    18161816 *
    18171817 * @uses bbp_get_topic_subscription_link()
     
    18261826     * A custom wrapper for bbp_get_user_subscribe_link()
    18271827     *
    1828      * @since bbPress (rxxxx)
     1828     * @since bbPress (r5156)
    18291829     *
    18301830     * @uses bbp_parse_args()
     
    18581858 * Output the topic favorite link
    18591859 *
    1860  * @since bbPress (rxxxx)
     1860 * @since bbPress (r5156)
    18611861 *
    18621862 * @uses bbp_get_topic_favorite_link()
     
    18711871     * A custom wrapper for bbp_get_user_favorite_link()
    18721872     *
    1873      * @since bbPress (rxxxx)
     1873     * @since bbPress (r5156)
    18741874     *
    18751875     * @uses bbp_parse_args()
  • trunk/includes/users/functions.php

    r5156 r5157  
    515515 * Get the users who have subscribed to the forum
    516516 *
    517  * @since bbPress (rxxxx)
     517 * @since bbPress (r5156)
    518518 *
    519519 * @param int $forum_id Optional. forum id
     
    571571 * @since bbPress (r2668)
    572572 *
    573  * @deprecated since bbPress (rxxxx)
     573 * @deprecated since bbPress (r5156)
    574574 *
    575575 * @param int $user_id Optional. User id
     
    617617 * Get a user's subscribed forums
    618618 *
    619  * @since bbPress (rxxxx)
     619 * @since bbPress (r5156)
    620620 *
    621621 * @param int $user_id Optional. User id
     
    648648 * Get a user's subscribed forum ids
    649649 *
    650  * @since bbPress (rxxxx)
     650 * @since bbPress (r5156)
    651651 *
    652652 * @param int $user_id Optional. User id
     
    694694 * Check if a topic or forum is in user's subscription list or not
    695695 *
    696  * @since bbPress (rxxxx)
     696 * @since bbPress (r5156)
    697697 *
    698698 * @param int $user_id Optional. User id
     
    748748 * Check if a forum is in user's subscription list or not
    749749 *
    750  * @since bbPress (rxxxx)
     750 * @since bbPress (r5156)
    751751 *
    752752 * @param int $user_id Optional. User id
     
    805805 * Check if a topic is in user's subscription list or not
    806806 *
    807  * @since bbPress (rxxxx)
     807 * @since bbPress (r5156)
    808808 *
    809809 * @param int $user_id Optional. User id
     
    862862 * Add a topic to user's subscriptions
    863863 *
    864  * @since bbPress (rxxxx)
     864 * @since bbPress (r5156)
    865865 *
    866866 * @param int $user_id Optional. User id
     
    908908 * Add a forum to user's subscriptions
    909909 *
    910  * @since bbPress (rxxxx)
     910 * @since bbPress (r5156)
    911911 *
    912912 * @param int $user_id Optional. User id
     
    10281028 * Remove a forum from user's subscriptions
    10291029 *
    1030  * @since bbPress (rxxxx)
     1030 * @since bbPress (r5156)
    10311031 *
    10321032 * @param int $user_id Optional. User id
     
    10751075 * Remove a topic from user's subscriptions
    10761076 *
    1077  * @since bbPress (rxxxx)
     1077 * @since bbPress (r5156)
    10781078 *
    10791079 * @param int $user_id Optional. User id
     
    11221122 * Handles the front end subscribing and unsubscribing forums
    11231123 *
    1124  * @since bbPress (rxxxx)
     1124 * @since bbPress (r5156)
    11251125 *
    11261126 * @param string $action The requested action to compare this function to
Note: See TracChangeset for help on using the changeset viewer.