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 9.1.2

protected function build_verification_query( $source_ids ) {
	$source_table                  = $this->schema_config['source']['entity']['table_name'];
	$destination_table             = $this->schema_config['destination']['table_name'];
	$destination_source_rel_column = $this->schema_config['destination']['source_rel_column'];
	$source_destination_rel_column = $this->schema_config['source']['entity']['destination_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();
	$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 ) {
		$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 ) );

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

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