Automattic\WooCommerce\Internal\DataStores\Orders

CustomOrdersTableController::sync_nowpublicWC 1.0

Callback to trigger a sync immediately by clicking a button on the Features screen.

Method of the class: CustomOrdersTableController{}

No Hooks.

Returns

null. Nothing (null).

Usage

$CustomOrdersTableController = new CustomOrdersTableController();
$CustomOrdersTableController->sync_now();

CustomOrdersTableController::sync_now() code WC 10.7.0

public function sync_now() {
	$section = filter_input( INPUT_GET, 'section' );
	if ( 'features' !== $section ) {
		return;
	}

	if ( filter_input( INPUT_GET, self::SYNC_QUERY_ARG, FILTER_VALIDATE_BOOLEAN ) ) {
		$action = 'sync-now';
	} elseif ( filter_input( INPUT_GET, self::STOP_SYNC_QUERY_ARG, FILTER_VALIDATE_BOOLEAN ) ) {
		$action = 'stop-sync';
	} else {
		return;
	}

	if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ?? '' ) ), "hpos-{$action}" ) ) {
		WC_Admin_Settings::add_error(
			'sync-now' === $action ?
				esc_html__( 'Unable to start synchronization. The link you followed may have expired.', 'woocommerce' )
				: esc_html__( 'Unable to stop synchronization. The link you followed may have expired.', 'woocommerce' )
		);
		return;
	}

	$this->data_cleanup->toggle_flag( false );

	if ( 'sync-now' === $action ) {
		if ( ! $this->data_synchronizer->check_orders_table_exists() && ! $this->data_synchronizer->create_database_tables() ) {
			WC_Admin_Settings::add_error(
				__( 'Unable to create HPOS tables for synchronization.', 'woocommerce' )
			);
			return;
		}

		$this->batch_processing_controller->enqueue_processor( DataSynchronizer::class );
	} else {
		$this->batch_processing_controller->remove_processor( DataSynchronizer::class );
	}
}