Automattic\WooCommerce\Database\Migrations

MetaToCustomTableMigrator::pre_process_row()privateWC 1.0

Helper method to pre-process rows to make sure we parse the correct type.

Метод класса: 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.

Code of MetaToCustomTableMigrator::pre_process_row() WC 7.1.0

private function pre_process_row( $row, $schema, $alias, $destination_alias ) {
	if ( in_array( $schema['type'], array( 'int', 'decimal' ), true ) ) {
		if ( '' === $row[ $alias ] || null === $row[ $alias ] ) {
			$row[ $alias ] = 0; // $wpdb->prepare forces empty values to 0.
		}
		$row[ $alias ]             = wc_format_decimal( $row[ $alias ], false, true );
		$row[ $destination_alias ] = wc_format_decimal( $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;
		}
	}
	if ( is_null( $row[ $alias ] ) ) {
		$row[ $alias ] = $this->get_type_defaults( $schema['type'] );
	}

	return $row;
}