Automattic\WooCommerce\Internal\DataStores\Orders
LegacyDataHandler::validate_backfill_fields
Validates meta_keys and property names for a partial order backfill.
Method of the class: LegacyDataHandler{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->validate_backfill_fields( $fields, $order );
- $fields(array) (required)
- An array possibly having entries with index
'meta_keys'and/or'props', corresponding to an array of order meta keys and/or order properties. - $order(WC_Abstract_Order) (required)
- The order being validated.
LegacyDataHandler::validate_backfill_fields() LegacyDataHandler::validate backfill fields code WC 10.7.0
private function validate_backfill_fields( array $fields, \WC_Abstract_Order $order ) {
if ( ! $fields ) {
return;
}
if ( ! empty( $fields['meta_keys'] ) ) {
$internal_meta_keys = array_unique(
array_merge(
$this->data_store->get_internal_meta_keys(),
$this->data_store->get_cpt_data_store_instance()->get_internal_meta_keys()
)
);
$possibly_internal_keys = array_intersect( $internal_meta_keys, $fields['meta_keys'] );
if ( ! empty( $possibly_internal_keys ) ) {
throw new \Exception(
esc_html(
sprintf(
// translators: %s is a comma separated list of metakey names.
_n(
'%s is an internal meta key. Use --props to set it.',
'%s are internal meta keys. Use --props to set them.',
count( $possibly_internal_keys ),
'woocommerce'
),
implode( ', ', $possibly_internal_keys )
)
)
);
}
}
if ( ! empty( $fields['props'] ) ) {
$invalid_props = array_filter(
$fields['props'],
function ( $prop_name ) use ( $order ) {
return ! method_exists( $order, "get_{$prop_name}" );
}
);
if ( ! empty( $invalid_props ) ) {
throw new \Exception(
esc_html(
sprintf(
// translators: %s is a list of order property names.
_n(
'%s is not a valid order property.',
'%s are not valid order properties.',
count( $invalid_props ),
'woocommerce'
),
implode( ', ', $invalid_props )
)
)
);
}
}
}