Skip to:
Content
Pages
Categories
Search
Top
Bottom

Repair tool with cron


  • liderxlt
    Participant

    @liderxlt

    Hi, I have a project which updates the forum daily through an import program.

    What I need is to run the repair tool that has bbpress once a day, when all imports are finished.

    I found this code but I can not make it work.

    function bbp_register_default_repair_tools() {
    
      // Topic meta
      bbp_register_repair_tool( array(
      'id' => 'bbp-sync-topic-meta',
      'description' => __( 'Recalculate parent topic for each reply', 'bbpress' ),
      'callback' => 'bbp_admin_repair_topic_meta',
      'priority' => 5,
      'overhead' => esc_html__( 'Low', 'bbpress' ),
      'components' => array( bbp_get_reply_post_type() )
      ) );
    
      // Forum meta
      bbp_register_repair_tool( array(
      'id' => 'bbp-sync-forum-meta',
      'description' => __( 'Recalculate parent forum for each topic and reply', 'bbpress' ),
      'callback' => 'bbp_admin_repair_forum_meta',
      'priority' => 10,
      'overhead' => esc_html__( 'Low', 'bbpress' ),
      'components' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() )
      ) );
    
      // Forum visibility
      bbp_register_repair_tool( array(
      'id' => 'bbp-sync-forum-visibility',
      'description' => __( 'Recalculate private and hidden forums', 'bbpress' ),
      'callback' => 'bbp_admin_repair_forum_visibility',
      'priority' => 15,
      'overhead' => esc_html__( 'Low', 'bbpress' ),
      'components' => array( bbp_get_forum_post_type() )
      ) );
    
      // Sync all topics in all forums
      bbp_register_repair_tool( array(
      'id' => 'bbp-sync-all-topics-forums',
      'description' => __( 'Recalculate last activity in each topic and forum', 'bbpress' ),
      'callback' => 'bbp_admin_repair_freshness',
      'priority' => 20,
      'overhead' => esc_html__( 'High', 'bbpress' ),
      'components' => array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() )
      ) );
    
      // Sync all sticky topics in all forums
      bbp_register_repair_tool( array(
      'id' => 'bbp-sync-all-topics-sticky',
      'description' => __( 'Recalculate sticky relationship of each topic', 'bbpress' ),
      'callback' => 'bbp_admin_repair_sticky',
      'priority' => 25,
      'overhead' => esc_html__( 'Low', 'bbpress' ),
      'components' => array( bbp_get_topic_post_type() )
      ) );
    
      // Sync all hierarchical reply positions
      bbp_register_repair_tool( array(
      'id' => 'bbp-sync-all-reply-positions',
      'description' => __( 'Recalculate the position of each reply', 'bbpress' ),
      'callback' => 'bbp_admin_repair_reply_menu_order',
      'priority' => 30,
      'overhead' => esc_html__( 'High', 'bbpress' ),
      'components' => array( bbp_get_reply_post_type() )
      ) );
    
      // Sync all BuddyPress group forum relationships
      bbp_register_repair_tool( array(
      'id' => 'bbp-group-forums',
      'description' => __( 'Repair BuddyPress Group Forum relationships', 'bbpress' ),
      'callback' => 'bbp_admin_repair_group_forum_relationship',
      'priority' => 35,
      'overhead' => esc_html__( 'Low', 'bbpress' ),
      'components' => array( bbp_get_forum_post_type() )
      ) );
    
      // Update closed topic counts
      bbp_register_repair_tool( array(
      'id' => 'bbp-sync-closed-topics',
      'description' => __( 'Repair closed topics', 'bbpress' ),
      'callback' => 'bbp_admin_repair_closed_topics',
      'priority' => 40,
      'overhead' => esc_html__( 'Medium', 'bbpress' ),
      'components' => array( bbp_get_topic_post_type() )
      ) );
    
      // Count topics
      bbp_register_repair_tool( array(
      'id' => 'bbp-forum-topics',
      'description' => __( 'Count topics in each forum', 'bbpress' ),
      'callback' => 'bbp_admin_repair_forum_topic_count',
      'priority' => 45,
      'overhead' => esc_html__( 'Medium', 'bbpress' ),
      'components' => array( bbp_get_forum_post_type(), bbp_get_topic_post_type() )
      ) );
    
      // Count forum replies
      bbp_register_repair_tool( array(
      'id' => 'bbp-forum-replies',
      'description' => __( 'Count replies in each forum', 'bbpress' ),
      'callback' => 'bbp_admin_repair_forum_reply_count',
      'priority' => 50,
      'overhead' => esc_html__( 'High', 'bbpress' ),
      'components' => array( bbp_get_forum_post_type(), bbp_get_reply_post_type() )
      ) );
    
      // Count topic replies
      bbp_register_repair_tool( array(
      'id' => 'bbp-topic-replies',
      'description' => __( 'Count replies in each topic', 'bbpress' ),
      'callback' => 'bbp_admin_repair_topic_reply_count',
      'priority' => 55,
      'overhead' => esc_html__( 'High', 'bbpress' ),
      'components' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() )
      ) );
    
      // Count topic voices
      bbp_register_repair_tool( array(
      'id' => 'bbp-topic-voices',
      'description' => __( 'Count voices in each topic', 'bbpress' ),
      'callback' => 'bbp_admin_repair_topic_voice_count',
      'priority' => 60,
      'overhead' => esc_html__( 'Medium', 'bbpress' ),
      'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() )
      ) );
    
      // Count non-published replies to each topic
      bbp_register_repair_tool( array(
      'id' => 'bbp-topic-hidden-replies',
      'description' => __( 'Count pending, spammed, & trashed replies in each topic', 'bbpress' ),
      'callback' => 'bbp_admin_repair_topic_hidden_reply_count',
      'priority' => 65,
      'overhead' => esc_html__( 'High', 'bbpress' ),
      'components' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() )
      ) );
    
      // Recount topics for each user
      bbp_register_repair_tool( array(
      'id' => 'bbp-user-topics',
      'description' => __( 'Recount topics for each user', 'bbpress' ),
      'callback' => 'bbp_admin_repair_user_topic_count',
      'priority' => 70,
      'overhead' => esc_html__( 'Medium', 'bbpress' ),
      'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() )
      ) );
    
      // Recount topics for each user
      bbp_register_repair_tool( array(
      'id' => 'bbp-user-replies',
      'description' => __( 'Recount replies for each user', 'bbpress' ),
      'callback' => 'bbp_admin_repair_user_reply_count',
      'priority' => 75,
      'overhead' => esc_html__( 'Medium', 'bbpress' ),
      'components' => array( bbp_get_reply_post_type(), bbp_get_user_rewrite_id() )
      ) );
    
      // Remove unpublished topics from user favorites
      bbp_register_repair_tool( array(
      'id' => 'bbp-user-favorites',
      'description' => __( 'Remove unpublished topics from user favorites', 'bbpress' ),
      'callback' => 'bbp_admin_repair_user_favorites',
      'priority' => 80,
      'overhead' => esc_html__( 'Medium', 'bbpress' ),
      'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() )
      ) );
    
      // Remove unpublished topics from user subscriptions
      bbp_register_repair_tool( array(
      'id' => 'bbp-user-topic-subscriptions',
      'description' => __( 'Remove unpublished topics from user subscriptions', 'bbpress' ),
      'callback' => 'bbp_admin_repair_user_topic_subscriptions',
      'priority' => 85,
      'overhead' => esc_html__( 'Medium', 'bbpress' ),
      'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() )
      ) );
    
      // Remove unpublished forums from user subscriptions
      bbp_register_repair_tool( array(
      'id' => 'bbp-user-forum-subscriptions',
      'description' => __( 'Remove unpublished forums from user subscriptions', 'bbpress' ),
      'callback' => 'bbp_admin_repair_user_forum_subscriptions',
      'priority' => 90,
      'overhead' => esc_html__( 'Medium', 'bbpress' ),
      'components' => array( bbp_get_forum_post_type(), bbp_get_user_rewrite_id() )
      ) );
    
      // Remove unpublished forums from user subscriptions
      bbp_register_repair_tool( array(
      'id' => 'bbp-user-role-map',
      'description' => __( 'Remap existing users to default forum roles', 'bbpress' ),
      'callback' => 'bbp_admin_repair_user_roles',
      'priority' => 95,
      'overhead' => esc_html__( 'Low', 'bbpress' ),
      'components' => array( bbp_get_user_rewrite_id() )
      ) );
      }
Viewing 7 replies - 1 through 7 (of 7 total)

  • Robin W
    Moderator

    @robin-w

    what functions are you using to create the topics/replies – if you are creating topics and replies using bbpress functions, then repair shouldn’t be needed.

    do you want me to take a look at your import code ?


    liderxlt
    Participant

    @liderxlt

    Hello, thanks for answering @robin-w
    I’m using an import plugin called wpallimport.

    Do you suggest that when importing, update the topic or reply data that you are importing at that moment?

    If possible, I would like to do it with a scheduled task since I have more than 100 daily imports with a pro- file of 300 imported records for each one. Imports are scheduled to run between 13 pm and 17 pm.

    I think that if I execute repair only once (5:30 pm) I will demand less from my server and I will be able to import it faster.


    Robin W
    Moderator

    @robin-w

    the functions you need to call are in

    includes/admin/tools.php

    so if you wanted to run the topic reply count you would link this function to cron

    bbp_admin_repair_topic_reply_count()

    But be careful about running mulitples of these, they are really resource hungry !


    dralawady
    Participant

    @dralawady

    @liderxlt : have you managed to get it sorted. I’m trying to add a code snipped to BuddyBoss theme to run forum repair on daily basis. Can you share the code snippet with me please?


    @robin-w
    : how can make use of includes/admin/tools.php functions through a theme code snippet?


    Robin W
    Moderator

    @robin-w

    You need to get this working within Cron.

    2 choices

    1. pay someone to write a plugin specifically for you to use cron to do this
    2. use a cron plugin such as https://wordpress.org/plugins/advanced-cron-manager/ and add the tasks in there

    I suggest you go for option 2 – free and would probably be much better


    dralawady
    Participant

    @dralawady

    @robin-w: I guess my problem is in adding the event to the cron. The function I’m trying to run is bbp_admin_repair_freshness and it’s declared in tools.php file, however there is no hook attached to it. I tried the this snippet code but it didn’t work:

    if ( ! wp_next_scheduled( 'bbp_sync_forum_topics_activity' ) ) {
    	wp_schedule_event( time(), 'hourly', 'bbp_sync_forum_topics_activity' );
    }
    
    add_action( 'bbp_sync_forum_topics_activity', 'bbp_admin_repair_freshness' );
    

    Robin W
    Moderator

    @robin-w

    sorry, I can’t say why that would not work.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar