BuddyDev

Search

Activities : no storage, erase all activities automatically every year

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #14309

    Hi,
    Activities generate a lot of data storage in the database

    1 / how not to store in the database, the registration of a new member that appears in the activities (for example)
    2 / how to erase all activities (of any type) automatically every year
    3 / hide those that are less interesting

    I feel that this function does not work anymore with the latest version of buddypress. If I disable it, => all works
    I activate it by trying several solutions and nothing else works !!

    add_filter( 'bp_after_has_activities_parse_args', 'activites_affiche_infos' );
    function activites_affiche_infos( $retval ) {
     //  if ( bp_is_active( 'activity' ) ) {
       $retval['action'] = array(        
        'activity_comment',
        'activity_update',
        //'created_group',
        //'friendship_created',
        'joined_group',
        'last_activity',
        //'new_avatar',
        'new_blog_comment',
        'new_blog_post',
        //'new_member',
        'updated_profile'        
        );
    	return $retval;	
    //	}
    }

    Regards

  • Keymaster
    (BuddyDev Team)
    Posts: 21785
    Brajesh Singh on #14328

    Hi Herve,

    1. Please see https://buddydev.com/buddypress/disallowing-activity-recording-for-components-or-some-activity-types-in-buddypress/

    2. You will need to replace the table and the year for each of the following instructions.

    a). List all activities for a user

    
    SELECT * FROM 'wp_bp_activity' WHERE YEAR(date_recorded) = 2016
    

    b). Delete for a year

    
    
    DELETE FROM <code>wp_bp_activity</code> WHERE YEAR(date_recorded) = 2016
    
    

    c). List orphan activity meta

    
    SELECT * FROM <code>wp_bp_activity_meta</code> WHERE activity_id NOT IN( SELECT id from wp_bp_activity )
    
    

    d). Cleanup the orphan meta

    
    DELETE FROM <code>wp_bp_activity_meta</code> WHERE activity_id NOT IN( SELECT id from wp_bp_activity )
    
    

    All the above actions are destructive and it is strongly suggested to take database backup before them. Also, Manually deleting activity will cause other complications.

    3. The less interesting needs to be quantified. How do you define something less interesting?

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #14559

    Hello Brajesh,

    First of all thank you for the answer. I was long because I needed to be clearer.

    1 / it works but what does it mean ” //reset either component or type, both will cause a failure in saving activity”?
    If I understand correctly, it’s a question of not using the 2 snippets at the same time

    2 / actually i want to be very careful using sql.
    I found a plugin https://wordpress.org/plugins/bulk-delete/ which will be able to use me to suppress all the members (and therefore activities) of a test site
    The 2nd solution I found to delete people who register on the site but never finish their registration

    function spammersdeletion() {
        global $wpdb;
        $from = strtotime('-30 day', time());
        $wpdb->query('DELETE FROM wp_users WHERE DATE(user_registered) < "'.date('Y-m-d', $from).'"AND user_status = "2"');
    }
    
    add_action('init','spammersdeletion');

    3 / I do not want to see in the selector
    a) Items deleted from storage $excluded_types = array( 'friendship_created', 'new_member' );
    b) updating the profile “updated_profile”
    Regards

  • Keymaster
    (BuddyDev Team)
    Posts: 21785
    Brajesh Singh on #14568

    Hi Herve,

    1. It is just to let you know how it works. By failing to save, the type is excluded from saving.

    2. I will not suggest using the code snippet you have posted. It is inefficient. You should not run t on each request. If you do it using cron or other task and run once a day, that will be fine.

    3. Do you want to exclude ‘friendship_created’, ‘new_member’ ‘updated_profile’ ?

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #14572

    Hello Brajesh
    1/ ok
    2/ ok
    3/ yes
    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 21785
    Brajesh Singh on #14618

    Hi Herve,
    Here is the code for three

    
    /**
     * Exclude BuddyPress activity types form listing.
     *
     * @param array $args activity args.
     *
     * @return array
     */
    function buddydev_exclude_activity_types( $args ) {
    
        // do not modify if the scope is laready set.
    	if ( ! empty( $args['scope'] ) ) {
    		return $args;
    	}
        // exclude the activity types if scope is not set.
    	$args['filter_query'] = array(
    		array(
    			'column'  => 'type',
    			'value'   => array( 'friendship_created', 'new_member', 'updated_profile' ),
    			'compare' => 'NOT IN'
    		)
    	);
    
    	return $args;
    }
    
    add_filter( 'bp_after_has_activities_parse_args', 'buddydev_exclude_activity_types' );
    

    Hope this helps.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #14632

    Hello Brajesh

    I misspoke because it does not work as I thought
    I do not want to record ‘friendship_created’, ‘new_member’, ‘updated_profile’
    Ok with https://buddydev.com/buddypress/disallowing-activity-recording-for-components-or-some-activity-types-in-buddypress/
    It is therefore necessary to hide the term in the selector
    https://screenshots.firefox.com/QPEVCbltOA8Mrpc6/null

    I had a code similar to this one that worked before:

    add_filter( 'bp_after_has_activities_parse_args', 'activites_affiche_infos' );
    function activites_affiche_infos( $retval ) {
     //  if ( bp_is_active( 'activity' ) ) {
       $retval['action'] = array(        
        'activity_comment',
        'activity_update',
        //'created_group',
        //'friendship_created',
        'joined_group',
        'last_activity',
        //'new_avatar',
        'new_blog_comment',
        'new_blog_post',
        //'new_member',
        'updated_profile'        
        );
    	return $retval;	
    //	}
    }

    It does not work anymore.
    I think there have been changes in buddypress !!
    this is not urgent
    I prefer to have help on https://buddydev.com/support/forums/topic/to-the-connection-of-an-existing-member-change-role-plan/

    Regards

  • Keymaster
    (BuddyDev Team)
    Posts: 21785
    Brajesh Singh on #14687

    Hi Herve,
    My code was not for disabling filter, It was to filter out the activity list and exclude those types.

    Your code for hiding filter is incorrect.

    You will need to use something like this

    
    
    /**
     * Remove activity filters in all context.
     * 
     * @param array $filters filters.
     *
     * @return array
     */
    function buddydev_remove_activity_filters_from_dropdown( $filters ) {
        $hidden = array(
                'friendship_accepted,friendship_created',// yup, use it as single key to hide Friendship.
                'joined_group',
                'new_blog_comment',
        );
    
        foreach ( $hidden as $key ) {
            if( isset( $filters[$key] ) ) {
                unset( $filters[$key]);
            }
        }
    
        return $filters;
    }
    add_filter( 'bp_get_activity_show_filters_options', 'buddydev_remove_activity_filters_from_dropdown' );
    

    Add the keys to hidden and they will be filtered out.

    PS:- I will be helping out with the other topic but need some time on that. Hopefully tomorrow I will be able to rethink on that issue and provide code.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #14728

    Hello Brajesh,

    cool it works 🙂
    It is therefore quite different from the old method.

    For registration of the match in function buddydev_exclude_activity_types_from_recording( &$activity ) { … I put
    $excluded_types = array( 'friendship_created', 'new_member' );

    Do I have to put too
    $excluded_types = array( 'friendship_accepted,friendship_created' ...
    in function buddydev_remove_activity_filters_from_dropdown( $filters )

    I said my priority to receive the answer for what is most important to me, because I know that you also have priorities for work to make choices.
    Regards

You must be logged in to reply to this topic.

This topic is: not resolved