Automattic\WooCommerce\Database\Migrations
MetaToCustomTableMigrator::pre_process_row()
Helper method to pre-process rows to make sure we parse the correct type.
Method of the class: MetaToCustomTableMigrator{}
No Hooks.
Return
Array
. Processed row.
Usage
// private - for code of main (parent) class only $result = $this->pre_process_row( $row, $schema, $alias, $destination_alias );
- $row(array) (required)
- Both migrated and source data for a single row.
- $schema(array) (required)
- Column schema.
- $alias(string) (required)
- Name of source column.
- $destination_alias(string) (required)
- Name of destination column.
MetaToCustomTableMigrator::pre_process_row() MetaToCustomTableMigrator::pre process row code WC 9.7.1
private function pre_process_row( $row, $schema, $alias, $destination_alias ) { if ( ! isset( $row[ $alias ] ) ) { $row[ $alias ] = $this->get_type_defaults( $schema['type'] ); } if ( is_null( $row[ $destination_alias ] ) ) { $row[ $destination_alias ] = $this->get_type_defaults( $schema['type'] ); } if ( in_array( $schema['type'], array( 'int', 'decimal', 'float' ), true ) ) { if ( '' === $row[ $alias ] || null === $row[ $alias ] ) { $row[ $alias ] = 0; // $wpdb->prepare forces empty values to 0. } $row[ $alias ] = wc_format_decimal( floatval( $row[ $alias ] ), false, true ); $row[ $destination_alias ] = wc_format_decimal( floatval( $row[ $destination_alias ] ), false, true ); } if ( 'bool' === $schema['type'] ) { $row[ $alias ] = wc_string_to_bool( $row[ $alias ] ); $row[ $destination_alias ] = wc_string_to_bool( $row[ $destination_alias ] ); } if ( 'date_epoch' === $schema['type'] ) { if ( '' === $row[ $alias ] || null === $row[ $alias ] ) { $row[ $alias ] = null; } else { $row[ $alias ] = ( new \DateTime( "@{$row[ $alias ]}" ) )->format( 'Y-m-d H:i:s' ); } if ( '0000-00-00 00:00:00' === $row[ $destination_alias ] ) { $row[ $destination_alias ] = null; } } return $row; }