diff --git a/includes/class-wp-cli.php b/includes/class-wp-cli.php index 3270f82623afe90b6a1c282d4daf32d438a6c4a1..842f64c22d92e4f8a179123e052f8ae92cce152b 100644 --- a/includes/class-wp-cli.php +++ b/includes/class-wp-cli.php @@ -5,6 +5,45 @@ WP_CLI::add_command( 'syndication', 'Syndication_CLI_Command' ); class Syndication_CLI_Command extends WP_CLI_Command { var $enabled_verbosity = false; + /** + * Pushes all posts of a given type + * + * @subcommand push-all-posts + * @synopsis [--post_type=<post-type>] [--paged=<page>] + */ + function push_all_posts( $args, $assoc_args ) { + $assoc_args = wp_parse_args( $assoc_args, array( + 'post_type' => 'post', + 'paged' => 1 + ) ); + + $query_args = array( + 'post_type' => $assoc_args[ 'post_type' ], + 'posts_per_page' => 150, + 'paged' => $assoc_args[ 'paged' ] + ); + + $query = new WP_Query( $query_args ); + + while( $query->post_count ) { + WP_CLI::line( sprintf( 'Processing page %d', $query_args[ 'paged' ] ) ); + + foreach( $query->posts as $post ) { + WP_CLI::line( sprintf( 'Processing post %d (%s)', $post->ID, $post->post_title ) ); + + $this->push_post( array(), array( 'post_id' => $post->ID ) ); + } + + $this->stop_the_insanity(); + + sleep( 2 ); + + $query_args[ 'paged' ]++; + + $query = new WP_Query( $query_args ); + } + } + function push_post( $args, $assoc_args ) { $assoc_args = wp_parse_args( $assoc_args, array( 'post_id' => 0, @@ -115,4 +154,21 @@ class Syndication_CLI_Command extends WP_CLI_Command { global $push_syndication_server; return $push_syndication_server; } + + protected function stop_the_insanity() { + global $wpdb, $wp_object_cache; + + $wpdb->queries = array(); // or define( 'WP_IMPORTING', true ); + + if ( !is_object( $wp_object_cache ) ) + return; + + $wp_object_cache->group_ops = array(); + $wp_object_cache->stats = array(); + $wp_object_cache->memcache_debug = array(); + $wp_object_cache->cache = array(); + + if ( is_callable( $wp_object_cache, '__remoteset' ) ) + $wp_object_cache->__remoteset(); // important + } }