Automattic\WooCommerce\Database\Migrations

MetaToMetaTableMigrator::generate_insert_sql_for_batch()privateWC 1.0

Generate insert sql queries for batches.

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

Хуков нет.

Возвращает

Строку. Insert SQL query.

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

// private - только в коде основоного (родительского) класса
$result = $this->generate_insert_sql_for_batch( $batch ): string;
$batch(массив) (обязательный)
Data to generate queries for.

Код MetaToMetaTableMigrator::generate_insert_sql_for_batch() WC 9.3.3

private function generate_insert_sql_for_batch( array $batch ): string {
	global $wpdb;

	$table             = $this->schema_config['destination']['meta']['table_name'];
	$meta_key_column   = $this->schema_config['destination']['meta']['meta_key_column'];
	$meta_value_column = $this->schema_config['destination']['meta']['meta_value_column'];
	$entity_id_column  = $this->schema_config['destination']['meta']['entity_id_column'];
	$column_sql        = "(`$entity_id_column`, `$meta_key_column`, `$meta_value_column`)";

	$entity_id_column_placeholder = MigrationHelper::get_wpdb_placeholder_for_type( $this->schema_config['destination']['meta']['entity_id_type'] );
	$placeholder_string           = "$entity_id_column_placeholder, %s, %s";
	$values                       = array();
	foreach ( $batch as $entity_id => $rows ) {
		foreach ( $rows as $meta_key => $meta_values ) {
			foreach ( $meta_values as $meta_value ) {
				$query_params = array(
					$entity_id,
					$meta_key,
					$meta_value,
				);
				// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders
				$value_sql = $wpdb->prepare( "$placeholder_string", $query_params );
				$values[]  = $value_sql;
			}
		}
	}

	$values_sql = implode( '), (', $values );

	return "INSERT IGNORE INTO $table $column_sql VALUES ($values_sql)";
}