Automattic\WooCommerce\Database\Migrations

MetaToCustomTableMigrator::verify_entity_columns()privateWC 1.0

Helper method to verify and compare core columns.

Метод класса: MetaToCustomTableMigrator{}

No Hooks.

Return

Array. Array of failed IDs if any, along with columns/meta_key names.

Usage

// private - for code of main (parent) class only
$result = $this->verify_entity_columns( $row, $failed_ids );
$row(array) (required)
Both migrated and source data for a single row.
$failed_ids(array) (required)
Array of failed IDs.

Code of MetaToCustomTableMigrator::verify_entity_columns() WC 7.1.0

private function verify_entity_columns( $row, $failed_ids ) {
	$primary_key_column = "{$this->schema_config['source']['entity']['table_name']}_{$this->schema_config['source']['entity']['primary_key']}";
	foreach ( $this->core_column_mapping as $column_name => $schema ) {
		$source_alias      = "{$this->schema_config['source']['entity']['table_name']}_$column_name";
		$destination_alias = "{$this->schema_config['destination']['table_name']}_{$schema['destination']}";
		$row               = $this->pre_process_row( $row, $schema, $source_alias, $destination_alias );
		if ( $row[ $source_alias ] !== $row[ $destination_alias ] ) {
			if ( ! isset( $failed_ids[ $row[ $primary_key_column ] ] ) ) {
				$failed_ids[ $row[ $primary_key_column ] ] = array();
			}
			$failed_ids[ $row[ $primary_key_column ] ][] = array(
				'column'         => $column_name,
				'original_value' => $row[ $source_alias ],
				'new_value'      => $row[ $destination_alias ],
			);
		}
	}

	return $failed_ids;
}