Automattic\WooCommerce\Database\Migrations

MetaToCustomTableMigrator::build_meta_data_query()privateWC 1.0

Helper method to build query that will be used to fetch data from source meta table.

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

Хуков нет.

Возвращает

Строку. Query for fetching meta data.

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

// private - только в коде основоного (родительского) класса
$result = $this->build_meta_data_query( $entity_ids ): string;
$entity_ids(массив) (обязательный)
List of IDs to fetch metadata for.

Код MetaToCustomTableMigrator::build_meta_data_query() WC 6.8.0

private function build_meta_data_query( array $entity_ids ): string {
	global $wpdb;

	$meta_table                = $this->schema_config['source']['meta']['table_name'];
	$meta_keys                 = array_keys( $this->meta_column_mapping );
	$meta_key_column           = $this->schema_config['source']['meta']['meta_key_column'];
	$meta_value_column         = $this->schema_config['source']['meta']['meta_value_column'];
	$meta_table_relational_key = $this->schema_config['source']['meta']['entity_id_column'];

	$meta_column_string = implode( ', ', array_fill( 0, count( $meta_keys ), '%s' ) );
	$entity_id_string   = implode( ', ', array_fill( 0, count( $entity_ids ), '%d' ) );

	// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- $meta_table_relational_key, $meta_key_column, $meta_value_column and $meta_table is escaped for backticks. $entity_id_string and $meta_column_string are placeholders.
	$query = $wpdb->prepare(
		"
SELECT `$meta_table_relational_key` as entity_id, `$meta_key_column` as meta_key, `$meta_value_column` as meta_value
FROM `$meta_table`
WHERE
`$meta_table_relational_key` IN ( $entity_id_string )
AND `$meta_key_column` IN ( $meta_column_string );
",
		array_merge(
			$entity_ids,
			$meta_keys
		)
	);

	// phpcs:enable

	return $query;
}