Automattic\WooCommerce\Internal\DataStores\Orders

CustomOrdersTableController::process_updated_option_fts_indexpublicWC 1.0

Process option that enables FTS index on orders table. Tries to create an FTS index when option is enabled.

Method of the class: CustomOrdersTableController{}

No Hooks.

Returns

null. Nothing (null).

Usage

$CustomOrdersTableController = new CustomOrdersTableController();
$CustomOrdersTableController->process_updated_option_fts_index( $option, $old_value, $value );
$option(string) (required)
Option name.
$old_value(string) (required)
Old value of the option.
$value(string) (required)
New value of the option.

CustomOrdersTableController::process_updated_option_fts_index() code WC 10.3.6

public function process_updated_option_fts_index( $option, $old_value, $value ) {
	if ( self::HPOS_FTS_INDEX_OPTION !== $option ) {
		return;
	}

	if ( 'yes' !== $value ) {
		return;
	}

	if ( ! $this->custom_orders_table_usage_is_enabled() ) {
		update_option( self::HPOS_FTS_INDEX_OPTION, 'no', true );
		if ( class_exists( 'WC_Admin_Settings' ) ) {
			WC_Admin_Settings::add_error( __( 'Failed to create FTS index on orders table. This feature is only available when High-performance order storage is enabled.', 'woocommerce' ) );
		}
		return;
	}

	if ( ! $this->db_util->fts_index_on_order_address_table_exists() ) {
		$this->db_util->create_fts_index_order_address_table();
	}

	// Check again to see if index was actually created.
	if ( $this->db_util->fts_index_on_order_address_table_exists() ) {
		update_option( self::HPOS_FTS_ADDRESS_INDEX_CREATED_OPTION, 'yes', false );
	} else {
		update_option( self::HPOS_FTS_ADDRESS_INDEX_CREATED_OPTION, 'no', false );
		if ( class_exists( 'WC_Admin_Settings ' ) ) {
			WC_Admin_Settings::add_error( __( 'Failed to create FTS index on address table', 'woocommerce' ) );
		}
	}

	if ( ! $this->db_util->fts_index_on_order_item_table_exists() ) {
		$this->db_util->create_fts_index_order_item_table();
	}

	// Check again to see if index was actually created.
	if ( $this->db_util->fts_index_on_order_item_table_exists() ) {
		update_option( self::HPOS_FTS_ORDER_ITEM_INDEX_CREATED_OPTION, 'yes', false );
	} else {
		update_option( self::HPOS_FTS_ORDER_ITEM_INDEX_CREATED_OPTION, 'no', false );
		if ( class_exists( 'WC_Admin_Settings ' ) ) {
			WC_Admin_Settings::add_error( __( 'Failed to create FTS index on order item table', 'woocommerce' ) );
		}
	}
}