Automattic\WooCommerce\Database\Migrations

MetaToMetaTableMigrator::generate_update_sql_for_batch()privateWC 1.0

Generate update SQL for given batch.

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

Хуков нет.

Возвращает

Строку. Query to update batch records.

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

// private - только в коде основоного (родительского) класса
$result = $this->generate_update_sql_for_batch( $batch ): string;
$batch(массив) (обязательный)
List of data to generate update SQL for. Should be in same format as output of $this->fetch_data_for_migration_for_ids.

Код MetaToMetaTableMigrator::generate_update_sql_for_batch() WC 6.7.0

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

	$table             = $this->schema_config['destination']['meta']['table_name'];
	$meta_id_column    = $this->schema_config['destination']['meta']['meta_id_column'];
	$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'];
	$columns           = array( $meta_id_column, $entity_id_column, $meta_key_column, $meta_value_column );
	$columns_sql       = implode( '`, `', $columns );

	$entity_id_column_placeholder = MigrationHelper::get_wpdb_placeholder_for_type( $this->schema_config['destination']['meta']['entity_id_type'] );
	$placeholder_string           = "%d, $entity_id_column_placeholder, %s, %s";
	$values                       = array();
	foreach ( $batch as $entity_id => $rows ) {
		foreach ( $rows as $meta_key => $meta_details ) {

			// phpcs:disable WordPress.DB.PreparedSQL, WordPress.DB.PreparedSQLPlaceholders
			$values[] = $wpdb->prepare(
				"( $placeholder_string )",
				array( $meta_details['id'], $entity_id, $meta_key, $meta_details['meta_value'] )
			);
			// phpcs:enable
		}
	}
	$value_sql = implode( ',', $values );

	$on_duplicate_key_clause = MigrationHelper::generate_on_duplicate_statement_clause( $columns );

	return "INSERT INTO $table ( `$columns_sql` ) VALUES $value_sql $on_duplicate_key_clause";
}