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{}

Хуков нет.

Возвращает

Массив. Processed row.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->pre_process_row( $row, $schema, $alias, $destination_alias );
$row(массив) (обязательный)
Both migrated and source data for a single row.
$schema(массив) (обязательный)
Column schema.
$alias(строка) (обязательный)
Name of source column.
$destination_alias(строка) (обязательный)
Name of destination column.

Код MetaToCustomTableMigrator::pre_process_row() WC 8.7.0

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;
}