Automattic\WooCommerce\Internal\Admin

OrderTaxLookupMigrator::handle_woocommerce_debug_tools │ public │ WC 1.0

Add the tool to start or stop the background rebuild.

Method of the class: OrderTaxLookupMigrator{}

No Hooks.

Returns

array. Updated tools array.

Usage

$OrderTaxLookupMigrator = new OrderTaxLookupMigrator();
$OrderTaxLookupMigrator->handle_woocommerce_debug_tools( $tools ): array;
$tools(array) (required)
Old tools array.

OrderTaxLookupMigrator::handle_woocommerce_debug_tools() code WC 11.2.1

public function handle_woocommerce_debug_tools( array $tools ): array {
	// A failed re-key would otherwise go unseen here: with no order counting as pending, the
	// tool would say there is nothing to rebuild. Say what is actually missing instead.
	if ( ! TaxesDataStore::lookup_is_keyed_by_order_item() ) {
		$tools['rebuild_analytics_tax_data'] = array(
			'name'     => __( 'Rebuild analytics tax data', 'woocommerce' ),
			'button'   => __( 'Rebuild', 'woocommerce' ),
			'disabled' => true,
			'desc'     => __( 'This will rebuild the Analytics tax data of orders recorded before WooCommerce kept a record of every tax line. The database change the rebuild needs is missing on this store. Run "Verify base database tables" to apply it, then come back here.', 'woocommerce' ),
		);

		return $tools;
	}

	$batch_processor = wc_get_container()->get( BatchProcessingController::class );
	$pending_count   = $this->get_total_pending_count();

	// The count stops at PENDING_COUNT_LIMIT, so say "or more" rather than a number the store
	// has already gone past.
	$pending_label = $pending_count < self::PENDING_COUNT_LIMIT
		? number_format_i18n( $pending_count )
		/* translators: %s: number of orders, where there are at least that many. */
		: sprintf( __( '%s+', 'woocommerce' ), number_format_i18n( self::PENDING_COUNT_LIMIT ) );

	if ( 0 === $pending_count ) {
		$tools['rebuild_analytics_tax_data'] = array(
			'name'     => __( 'Rebuild analytics tax data', 'woocommerce' ),
			'button'   => __( 'Rebuild', 'woocommerce' ),
			'disabled' => true,
			'desc'     => __( 'This will rebuild the Analytics tax data of orders recorded before WooCommerce kept a record of every tax line. There are currently no orders to rebuild.', 'woocommerce' ),
		);
	} elseif ( $batch_processor->is_enqueued( self::class ) ) {
		$tools['stop_rebuild_analytics_tax_data'] = array(
			'name'             => __( 'Stop rebuilding analytics tax data', 'woocommerce' ),
			'button'           => __( 'Stop rebuilding', 'woocommerce' ),
			'requires_refresh' => true,
			'desc'             => sprintf(
				/* translators: %s: number of orders still to rebuild. */
				_n(
					'This will stop the background process that rebuilds the Analytics tax data of orders recorded before WooCommerce kept a record of every tax line. There is currently %s order left to rebuild.',
					'This will stop the background process that rebuilds the Analytics tax data of orders recorded before WooCommerce kept a record of every tax line. There are currently %s orders left to rebuild.',
					$pending_count,
					'woocommerce'
				),
				$pending_label
			),
			'callback'         => array( $this, 'dequeue' ),
		);
	} else {
		$tools['rebuild_analytics_tax_data'] = array(
			'name'             => __( 'Rebuild analytics tax data', 'woocommerce' ),
			'button'           => __( 'Rebuild', 'woocommerce' ),
			'requires_refresh' => true,
			'desc'             => sprintf(
				/* translators: %s: number of orders to rebuild. */
				_n(
					'This will rebuild the Analytics tax data of orders recorded before WooCommerce kept a record of every tax line. The rebuild happens over time in the background (via Action Scheduler). There is currently %s order to rebuild.',
					'This will rebuild the Analytics tax data of orders recorded before WooCommerce kept a record of every tax line. The rebuild happens over time in the background (via Action Scheduler). There are currently %s orders to rebuild.',
					$pending_count,
					'woocommerce'
				),
				$pending_label
			),
			'callback'         => array( $this, 'enqueue' ),
		);
	}

	return $tools;
}