Automattic\WooCommerce\DataBase\Migrations\CustomOrderTable

CLIRunner::disable()publicWC 1.0

Disables custom order tables (HPOS) and posts to authoritative if HPOS and post tables are in sync.

OPTIONS

[--with-sync]
Also disables sync (if it's currently enabled).
--- default: false
---

EXAMPLES

Disable HPOS. wp wc hpos disable

Method of the class: CLIRunner{}

No Hooks.

Return

null. Nothing (null).

Usage

$CLIRunner = new CLIRunner();
$CLIRunner->disable( $args, $assoc_args );
$args(array) (required)
Positional arguments passed to the command.
$assoc_args(array) (required)
Associative arguments (options) passed to the command.

CLIRunner::disable() code WC 9.0.1

public function disable( $args, $assoc_args ) {
	$assoc_args = wp_parse_args(
		$assoc_args,
		array(
			'with-sync' => false,
		)
	);

	WP_CLI::log( __( 'Running pre-disable checks...', 'woocommerce' ) );

	/** DataSynchronizer instance @var DataSynchronizer $data_synchronizer */
	$data_synchronizer = wc_get_container()->get( DataSynchronizer::class );
	$pending_orders    = $data_synchronizer->get_total_pending_count();
	if ( $pending_orders > 0 ) {
		return WP_CLI::error(
			sprintf(
				// translators: %s is the command to run (wp wc cot sync).
				__( '[Failed] There are orders pending sync. Please run `%s` to sync pending orders.', 'woocommerce' ),
				'wp wc hpos sync',
			)
		);
	}

	/** FeaturesController instance @var FeaturesController $feature_controller */
	$feature_controller = wc_get_container()->get( FeaturesController::class );

	/** CustomOrdersTableController instance @var CustomOrdersTableController $cot_status */
	$cot_status = wc_get_container()->get( CustomOrdersTableController::class );
	if ( ! $cot_status->custom_orders_table_usage_is_enabled() ) {
		WP_CLI::warning( __( 'HPOS is already disabled.', 'woocommerce' ) );
	} else {
		$feature_controller->change_feature_enable( 'custom_order_tables', false );
		if ( $cot_status->custom_orders_table_usage_is_enabled() ) {
			return WP_CLI::warning( __( 'HPOS could not be disabled.', 'woocommerce' ) );
		} else {
			WP_CLI::success( __( 'HPOS disabled.', 'woocommerce' ) );
		}
	}

	if ( $assoc_args['with-sync'] ) {
		if ( ! $data_synchronizer->data_sync_is_enabled() ) {
			return WP_CLI::warning( __( 'Sync is already disabled.', 'woocommerce' ) );
		}
		$feature_controller->change_feature_enable( DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION, false );
		if ( $data_synchronizer->data_sync_is_enabled() ) {
			return WP_CLI::warning( __( 'Sync could not be disabled.', 'woocommerce' ) );
		} else {
			WP_CLI::success( __( 'Sync disabled.', 'woocommerce' ) );
		}
	}
}