Automattic\WooCommerce\Internal\DataStores\Orders

CustomOrdersTableController::process_pre_update_optionpublicWC 1.0

Handler for the setting pre-update hook. We use it to verify that authoritative orders table switch doesn't happen while sync is pending.

Method of the class: CustomOrdersTableController{}

No Hooks.

Returns

null. Nothing (null).

Usage

$CustomOrdersTableController = new CustomOrdersTableController();
$CustomOrdersTableController->process_pre_update_option( $value, $option, $old_value );
$value(mixed) (required)
New value of the setting.
$option(string) (required)
Setting name.
$old_value(mixed) (required)
Old value of the setting.

CustomOrdersTableController::process_pre_update_option() code WC 10.7.0

public function process_pre_update_option( $value, $option, $old_value ) {
	if ( DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION === $option && $value !== $old_value ) {
		$this->order_cache->flush();
		return $value;
	}

	if ( self::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION !== $option ) {
		return $value;
	}

	if ( $old_value === $value ) {
		return $value;
	}

	$this->order_cache->flush();
	if ( ! $this->data_synchronizer->check_orders_table_exists() ) {
		$this->data_synchronizer->create_database_tables();
	}

	$tables_created = get_option( DataSynchronizer::ORDERS_TABLE_CREATED ) === 'yes';
	if ( ! $tables_created ) {
		return 'no';
	}

	if ( ! $this->changing_data_source_with_sync_pending_is_allowed() && $this->data_synchronizer->has_orders_pending_sync() ) {
		throw new \Exception( "The authoritative table for orders storage can't be changed while there are orders out of sync" );
	}

	return $value;
}