Automattic\WooCommerce\Internal\Admin\Schedulers

ImportScheduler::import_batch()public staticWC 1.0

Imports a batch of items to update.

Method of the class: ImportScheduler{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = ImportScheduler::import_batch( $batch_number, $days, $skip_existing );
$batch_number(int) (required)
Batch number to import (essentially a query page number).
$days(int|true|false) (required)
Number of days to import.
$skip_existing(true|false) (required)
Skip existing records.

ImportScheduler::import_batch() code WC 9.4.2

public static function import_batch( $batch_number, $days, $skip_existing ) {
	$batch_size = static::get_batch_size( 'import' );

	$properties = array(
		'batch_number' => $batch_number,
		'batch_size'   => $batch_size,
		'type'         => static::$name,
	);
	wc_admin_record_tracks_event( 'import_job_start', $properties );

	// When we are skipping already imported items, the table of items to import gets smaller in
	// every batch, so we want to always import the first page.
	$page  = $skip_existing ? 1 : $batch_number;
	$items = static::get_items( $batch_size, $page, $days, $skip_existing );

	foreach ( $items->ids as $id ) {
		static::import( $id );
	}

	$import_stats                              = get_option( self::IMPORT_STATS_OPTION, array() );
	$imported_count                            = absint( $import_stats[ static::$name ]['imported'] ) + count( $items->ids );
	$import_stats[ static::$name ]['imported'] = $imported_count;
	update_option( self::IMPORT_STATS_OPTION, $import_stats );

	$properties['imported_count'] = $imported_count;

	wc_admin_record_tracks_event( 'import_job_complete', $properties );
}