Skip to content

Commit

Permalink
Add support for partial backfills to wp wc hpos backfill CLI tool
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeatorres committed Mar 8, 2024
1 parent df1c544 commit e1459d6
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,12 @@ function( $key, $hpos_value, $cpt_value ) {
* - posts
* ---
*
* [--meta_keys=<meta_keys>]
* : Comma separated list of meta keys to backfill.
*
* [--props=<props>]
* : Comma separated list of order properties to backfill.
*
* @since 8.6.0
*
* @param array $args Positional arguments passed to the command.
Expand Down Expand Up @@ -1140,8 +1146,14 @@ public function backfill( array $args = array(), array $assoc_args = array() ) {
WP_CLI::error( __( 'Please use different source (--from) and destination (--to) datastores.', 'woocommerce' ) );
}

$fields = array_intersect_key( $assoc_args, array_flip( array( 'meta_keys', 'props' ) ) );
foreach ( $fields as &$field_names ) {
$field_names = is_string( $field_names ) ? array_map( 'trim', explode( ',', $field_names ) ) : $field_names;
$field_names = array_unique( array_filter( array_filter( $field_names, 'is_string' ) ) );
}

try {
$legacy_handler->backfill_order_to_datastore( $order_id, $from, $to );
$legacy_handler->backfill_order_to_datastore( $order_id, $from, $to, $fields );
} catch ( \Exception $e ) {
WP_CLI::error(
sprintf(
Expand Down

0 comments on commit e1459d6

Please sign in to comment.