Automattic\WooCommerce\Database\Migrations

MetaToCustomTableMigrator::build_verification_query()protectedWC 1.0

Generate query to fetch data from both source and destination tables. Use the results in verify_data to verify if data was migrated properly.

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

Хуков нет.

Возвращает

Строку. SELECT statement.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->build_verification_query( $source_ids );
$source_ids(массив) (обязательный)
Array of IDs in source table.

Код MetaToCustomTableMigrator::build_verification_query() WC 6.8.0

protected function build_verification_query( $source_ids ) {
	$source_table                  = $this->schema_config['source']['entity']['table_name'];
	$meta_table                    = $this->schema_config['source']['meta']['table_name'];
	$destination_table             = $this->schema_config['destination']['table_name'];
	$meta_entity_id_column         = $this->schema_config['source']['meta']['entity_id_column'];
	$meta_key_column               = $this->schema_config['source']['meta']['meta_key_column'];
	$meta_value_column             = $this->schema_config['source']['meta']['meta_value_column'];
	$destination_source_rel_column = $this->schema_config['destination']['source_rel_column'];
	$source_destination_rel_column = $this->schema_config['source']['entity']['destination_rel_column'];
	$source_meta_rel_column        = $this->schema_config['source']['entity']['meta_rel_column'];

	$source_destination_join_clause = "$destination_table ON $destination_table.$destination_source_rel_column = $source_table.$source_destination_rel_column";

	$meta_select_clauses        = array();
	$meta_join_clauses          = array();
	$source_select_clauses      = array();
	$destination_select_clauses = array();

	foreach ( $this->core_column_mapping as $column_name => $schema ) {
		$source_select_column         = isset( $schema['select_clause'] ) ? $schema['select_clause'] : "$source_table.$column_name";
		$source_select_clauses[]      = "$source_select_column as {$source_table}_{$column_name}";
		$destination_select_clauses[] = "$destination_table.{$schema['destination']} as {$destination_table}_{$schema['destination']}";
	}

	foreach ( $this->meta_column_mapping as $meta_key => $schema ) {
		$meta_table_alias             = "meta_source_{$schema['destination']}";
		$meta_select_clauses[]        = "$meta_table_alias.$meta_value_column AS $meta_table_alias";
		$meta_join_clauses[]          = "
$meta_table $meta_table_alias ON
$meta_table_alias.$meta_entity_id_column = $source_table.$source_meta_rel_column AND
$meta_table_alias.$meta_key_column = '$meta_key'
";
		$destination_select_clauses[] = "$destination_table.{$schema['destination']} as {$destination_table}_{$schema['destination']}";
	}

	$select_clause = implode( ', ', array_merge( $source_select_clauses, $meta_select_clauses, $destination_select_clauses ) );

	$meta_join_clause = implode( ' LEFT JOIN ', $meta_join_clauses );

	$where_clause = $this->get_where_clause_for_verification( $source_ids );

	return "
SELECT $select_clause
FROM $source_table
    LEFT JOIN $source_destination_join_clause
    LEFT JOIN $meta_join_clause
WHERE $where_clause
";
}