Automattic\WooCommerce\Internal\ProductAttributesLookup

DataRegenerator::add_initiate_regeneration_entry_to_tools_array()privateWC 1.0

Add a 'Regenerate product attributes lookup table' entry to the Status - Tools page.

Method of the class: DataRegenerator{}

No Hooks.

Return

Array. The tools array with the entry added.

Usage

// private - for code of main (parent) class only
$result = $this->add_initiate_regeneration_entry_to_tools_array( $tools_array );
$tools_array(array) (required)
The tool definitions array that is passed ro the woocommerce_debug_tools filter.

DataRegenerator::add_initiate_regeneration_entry_to_tools_array() code WC 8.6.1

private function add_initiate_regeneration_entry_to_tools_array( array $tools_array ) {
	if ( ! $this->data_store->check_lookup_table_exists() ) {
		return $tools_array;
	}

	$generation_is_in_progress = $this->data_store->regeneration_is_in_progress();
	$generation_was_aborted    = $this->data_store->regeneration_was_aborted();

	$entry = array(
		'name'             => __( 'Regenerate the product attributes lookup table', 'woocommerce' ),
		'desc'             => __( 'This tool will regenerate the product attributes lookup table data from existing product(s) data. This process may take a while.', 'woocommerce' ),
		'requires_refresh' => true,
		'callback'         => function() {
			$this->initiate_regeneration_from_tools_page();
			return __( 'Product attributes lookup table data is regenerating', 'woocommerce' );

		},
		'selector'         => array(
			'description'   => __( 'Select a product to regenerate the data for, or leave empty for a full table regeneration:', 'woocommerce' ),
			'class'         => 'wc-product-search',
			'search_action' => 'woocommerce_json_search_products',
			'name'          => 'regenerate_product_attribute_lookup_data_product_id',
			'placeholder'   => esc_attr__( 'Search for a product…', 'woocommerce' ),
		),
	);

	if ( $generation_is_in_progress ) {
		$entry['button'] = sprintf(
			/* translators: %d: How many products have been processed so far. */
			__( 'Filling in progress (%d)', 'woocommerce' ),
			get_option( 'woocommerce_attribute_lookup_processed_count', 0 )
		);
		$entry['disabled'] = true;
	} else {
		$entry['button'] = __( 'Regenerate', 'woocommerce' );
	}

	$tools_array['regenerate_product_attributes_lookup_table'] = $entry;

	if ( $generation_is_in_progress ) {
		$entry = array(
			'name'             => __( 'Abort the product attributes lookup table regeneration', 'woocommerce' ),
			'desc'             => __( 'This tool will abort the regenerate product attributes lookup table regeneration. After this is done the process can be either started over, or resumed to continue where it stopped.', 'woocommerce' ),
			'requires_refresh' => true,
			'callback'         => function() {
				$this->abort_regeneration_from_tools_page();
				return __( 'Product attributes lookup table regeneration process has been aborted.', 'woocommerce' );
			},
			'button'           => __( 'Abort', 'woocommerce' ),
		);
		$tools_array['abort_product_attributes_lookup_table_regeneration'] = $entry;
	} elseif ( $generation_was_aborted ) {
		$processed_count = get_option( 'woocommerce_attribute_lookup_processed_count', 0 );
		$entry           = array(
			'name'             => __( 'Resume the product attributes lookup table regeneration', 'woocommerce' ),
			'desc'             =>
				sprintf(
					/* translators: %1$s = count of products already processed. */
					__( 'This tool will resume the product attributes lookup table regeneration at the point in which it was aborted (%1$s products were already processed).', 'woocommerce' ),
					$processed_count
				),
			'requires_refresh' => true,
			'callback'         => function() {
				$this->resume_regeneration_from_tools_page();
				return __( 'Product attributes lookup table regeneration process has been resumed.', 'woocommerce' );
			},
			'button'           => __( 'Resume', 'woocommerce' ),
		);
		$tools_array['resume_product_attributes_lookup_table_regeneration'] = $entry;
	}

	return $tools_array;
}