Automattic\WooCommerce\Internal\CLI\Migrator\Lib

ImportSession::get_activepublic staticWC 1.0

Gets the most recent active import session.

Method of the class: ImportSession{}

No Hooks.

Returns

WP_Import_Session|null. The most recent import or null if none found

Usage

$result = ImportSession::get_active();

ImportSession::get_active() code WC 10.8.1

public static function get_active() {
	$posts = get_posts(
		array(
			'post_type'      => self::POST_TYPE,
			'post_status'    => array( 'publish' ),
			'posts_per_page' => 1,
			'orderby'        => 'date',
			'order'          => 'DESC',
			'meta_query'     => array(
				// @TODO: This somehow makes $post empty.
				// array(
				// 'key' => 'current_stage',
				// 'value' => WP_Stream_Importer::STAGE_FINISHED,
				// 'compare' => '!='
				// )
			),
		)
	);

	if ( empty( $posts ) ) {
		return false;
	}

	return new self( $posts[0]->ID );
}