Skip to content
Snippets Groups Projects
Commit bdcd3745 authored by Mohammad Jangda's avatar Mohammad Jangda
Browse files

Introduce CLI commands for pulling in an individual site or sitegroup

parent 7f847445
Branches
No related tags found
No related merge requests found
<?php
WP_CLI::add_command( 'syndication', 'Syndication_CLI_Command' );
class Syndication_CLI_Command extends WP_CLI_Command {
function pull_site( $args, $assoc_args ) {
$assoc_args = wp_parse_args( $assoc_args, array(
'site_id' => 0,
) );
$site_id = intval( $assoc_args['site_id'] );
$site = get_post( $site_id );
var_dump( $site_id, $site );
if ( ! $site || 'syn_site' !== $site->post_type )
WP_CLI::error( "Please select a valid site." );
// enable verbosity
$this->_make_em_talk_pull();
$this->_get_syndication_server()->pull_content( array( $site ) );
}
function pull_sitegroup( $args, $assoc_args ) {
$assoc_args = wp_parse_args( $assoc_args, array(
'sitegroup' => '',
) );
$sitegroup = sanitize_key( $assoc_args['sitegroup'] );
if ( empty( $sitegroup ) )
WP_CLI::error( "Please specify a valid sitegroup" );
$server = $this->_get_syndication_server();
$sites = $server->get_sites_by_sitegroup( $sitegroup );
// enable verbosity
$this->_make_em_talk_pull();
// do it, to it
$server->pull_content( $sites );
}
function _make_em_talk_pull() {
// output when a post is new or updated
add_filter( 'syn_pre_pull_posts', function( $posts, $site, $client ) {
WP_CLI::line( sprintf( 'Processing feed %s (%d)', $site->post_title, $site->ID ) );
WP_CLI::line( sprintf( '-- found %s posts', count( $posts ) ) );
return $posts;
}, 10, 3 );
add_action( 'syn_post_pull_new_post', function( $result, $post, $site, $transport_type, $client ) {
WP_CLI::line( sprintf( '-- New post #%d (%s)', $result, $post['post_guid'] ) );
}, 10, 5 );
add_action( 'syn_post_pull_edit_post', function( $result, $post, $site, $transport_type, $client ) {
WP_CLI::line( sprintf( '-- Updated post #%d (%s)', $result, $post['post_guid'] ) );
}, 10, 5 );
}
function _get_syndication_server() {
global $push_syndication_server;
return $push_syndication_server;
}
}
...@@ -21,5 +21,8 @@ if( apply_filters( 'syn_use_async_jobs', false ) ) ...@@ -21,5 +21,8 @@ if( apply_filters( 'syn_use_async_jobs', false ) )
if ( !defined( 'PUSH_SYNDICATION_ENVIRONMENT' ) ) if ( !defined( 'PUSH_SYNDICATION_ENVIRONMENT' ) )
define( 'PUSH_SYNDICATION_ENVIRONMENT', 'WP' ); define( 'PUSH_SYNDICATION_ENVIRONMENT', 'WP' );
if ( defined( 'WP_CLI' ) && WP_CLI )
require_once( dirname( __FILE__ ) . '/includes/class-wp-cli.php' );
$push_syndication_server_class = PUSH_SYNDICATION_ENVIRONMENT . '_Push_Syndication_Server'; $push_syndication_server_class = PUSH_SYNDICATION_ENVIRONMENT . '_Push_Syndication_Server';
$push_syndication_server = new $push_syndication_server_class(); $push_syndication_server = new $push_syndication_server_class();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment