Automattic\WooCommerce\Database\Migrations

MetaToCustomTableMigrator::process_migration_batch_for_ids_core()protectedWC 1.0

Migrate a batch of entities from the posts table to the corresponding table.

Method of the class: MetaToCustomTableMigrator{}

No Hooks.

Return

null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->process_migration_batch_for_ids_core( $entity_ids ): void;
$entity_ids(array) (required)
Ids of entities to migrate.

MetaToCustomTableMigrator::process_migration_batch_for_ids_core() code WC 7.1.1

protected function process_migration_batch_for_ids_core( array $entity_ids ): void {
	$data = $this->fetch_data_for_migration_for_ids( $entity_ids );

	foreach ( $data['errors'] as $entity_id => $errors ) {
		foreach ( $errors as $column_name => $error_message ) {
			$this->add_error( "Error importing data for post with id $entity_id: column $column_name: $error_message" );
		}
	}

	if ( count( $data['data'] ) === 0 ) {
		return;
	}

	$entity_ids       = array_keys( $data['data'] );
	$existing_records = $this->get_already_existing_records( $entity_ids );

	$to_insert = array_diff_key( $data['data'], $existing_records );
	$this->process_insert_batch( $to_insert );

	$existing_records = array_filter(
		$existing_records,
		function( $record_data ) {
			return '1' === $record_data->modified;
		}
	);
	$to_update        = array_intersect_key( $data['data'], $existing_records );
	$this->process_update_batch( $to_update, $existing_records );
}