Automattic\WooCommerce\Database\Migrations

MetaToCustomTableMigrator::process_migration_data()publicWC 1.0

Process migration data for a batch of entities.

Method of the class: MetaToCustomTableMigrator{}

No Hooks.

Return

Array. Array of errors and exception if any.

Usage

$MetaToCustomTableMigrator = new MetaToCustomTableMigrator();
$MetaToCustomTableMigrator->process_migration_data( $data );
$data(array) (required)
Data to be migrated. Should be of the form: array( 'data' => array( ... ) ) as returned by the fetch_sanitized_migration_data method.

MetaToCustomTableMigrator::process_migration_data() code WC 9.0.1

public function process_migration_data( array $data ) {
	$this->clear_errors();
	$exception = null;

	if ( ! isset( $data['data'] ) || ! is_array( $data['data'] ) || count( $data['data'] ) === 0 ) {
		return array(
			'errors'    => $this->get_errors(),
			'exception' => null,
		);
	}

	try {
		$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 );

		$to_update = array_intersect_key( $data['data'], $existing_records );
		$this->process_update_batch( $to_update, $existing_records );
	} catch ( \Exception $e ) {
		$exception = $e;
	}

	return array(
		'errors'    => $this->get_errors(),
		'exception' => $exception,
	);
}