Automattic\WooCommerce\Database\Migrations

MetaToMetaTableMigrator::fetch_data_for_migration_for_ids()privateWC 1.0

Fetch data for migration.

Method of the class: MetaToMetaTableMigrator{}

No Hooks.

Return

Array[]. Data, will of the form: array( 'id_1' => array( 'column1' => array( value1_1, value1_2...), 'column2' => array(value2_1, value2_2...), ...), ..., )

Usage

// private - for code of main (parent) class only
$result = $this->fetch_data_for_migration_for_ids( $entity_ids ): array;
$entity_ids(array) (required)
Array of IDs to fetch data for.

MetaToMetaTableMigrator::fetch_data_for_migration_for_ids() code WC 7.1.1

private function fetch_data_for_migration_for_ids( array $entity_ids ): array {
	if ( empty( $entity_ids ) ) {
		return array();
	}

	$meta_query = $this->build_meta_table_query( $entity_ids );

	$meta_data_rows = $this->db_get_results( $meta_query );
	if ( empty( $meta_data_rows ) ) {
		return array();
	}

	foreach ( $meta_data_rows as $migrate_row ) {
		if ( ! isset( $to_migrate[ $migrate_row->entity_id ] ) ) {
			$to_migrate[ $migrate_row->entity_id ] = array();
		}

		if ( ! isset( $to_migrate[ $migrate_row->entity_id ][ $migrate_row->meta_key ] ) ) {
			// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
			$to_migrate[ $migrate_row->entity_id ][ $migrate_row->meta_key ] = array();
		}

		$to_migrate[ $migrate_row->entity_id ][ $migrate_row->meta_key ][] = $migrate_row->meta_value;
	}

	return $to_migrate;
}