WooCommerce Code Reference

TableMigrator

Base class for implementing WP posts to order tables migrations handlers.

It mainly contains methods to deal with error handling.

Table of Contents

$errors  : array<string|int, mixed>
An array of cummulated error messages.
fetch_sanitized_migration_data()  : array<string|int, array<string|int, mixed>>
Return data to be migrated for a batch of entities.
process_migration_batch_for_ids()  : array<string|int, mixed>
Migrate a batch of orders, logging any database error that could arise and the exception thrown if any.
process_migration_data()  : array<string|int, mixed>
Process migration data for a batch of entities.
add_error()  : void
Add an error message to the errors list unless it's there already.
clear_errors()  : void
Clear the error messages list.
db_get_results()  : mixed
Run $wpdb->get_results and add the error, if any, to the errors list.
db_query()  : mixed
Run $wpdb->query and add the error, if any, to the errors list.
get_errors()  : array<string|int, mixed>
Get the list of error messages added.
maybe_add_insert_or_update_error()  : void
Check if the amount of processed database rows matches the amount of orders to process, and log an error if not.
process_migration_batch_for_ids_core()  : void
The core method that actually performs the migration for the supplied batch of order ids.

Properties

Methods

fetch_sanitized_migration_data()

Return data to be migrated for a batch of entities.

public fetch_sanitized_migration_data(array<string|int, mixed> $entity_ids) : array<string|int, array<string|int, mixed>>
Parameters
$entity_ids : array<string|int, mixed>

Ids of entities to migrate.

Return values
array<string|int, array<string|int, mixed>>Data to be migrated. Would be of the form: array( 'data' => array( ... ), 'errors' => array( ... ) ).

process_migration_batch_for_ids()

Migrate a batch of orders, logging any database error that could arise and the exception thrown if any.

public process_migration_batch_for_ids(array<string|int, mixed> $entity_ids) : array<string|int, mixed>
Parameters
$entity_ids : array<string|int, mixed>

Order ids to migrate.

Tags
deprecated
8.0.0

Use fetch_sanitized_migration_data and process_migration_data instead.

Return values
array<string|int, mixed>An array containing the keys 'errors' (array of strings) and 'exception' (exception object or null).

process_migration_data()

Process migration data for a batch of entities.

public process_migration_data(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>

Data to be migrated. Should be of the form: array( 'data' => array( ... ) ) as returned by the fetch_sanitized_migration_data method.

Return values
array<string|int, mixed>Array of errors and exception if any.

add_error()

Add an error message to the errors list unless it's there already.

protected add_error(string $error) : void
Parameters
$error : string

The error message to add.

Return values
void

db_get_results()

Run $wpdb->get_results and add the error, if any, to the errors list.

protected db_get_results([string|null $query = null ][, string $output = OBJECT ]) : mixed
Parameters
$query : string|null = null

The SQL query to run.

$output : string = OBJECT

Any of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K constants.

Return values
mixedWhatever $wpdb->get_results returns.

db_query()

Run $wpdb->query and add the error, if any, to the errors list.

protected db_query(string $query) : mixed
Parameters
$query : string

The SQL query to run.

Return values
mixedWhatever $wpdb->query returns.

maybe_add_insert_or_update_error()

Check if the amount of processed database rows matches the amount of orders to process, and log an error if not.

protected maybe_add_insert_or_update_error(string $operation, array<string|int, mixed>|bool $received_rows_count) : void
Parameters
$operation : string

Operation performed, 'insert' or 'update'.

$received_rows_count : array<string|int, mixed>|bool

Value returned by @wpdb after executing the query.

Return values
void

process_migration_batch_for_ids_core()

The core method that actually performs the migration for the supplied batch of order ids.

protected abstract process_migration_batch_for_ids_core(array<string|int, mixed> $entity_ids) : void

It doesn't need to deal with database errors nor with exceptions.

Parameters
$entity_ids : array<string|int, mixed>

Order ids to migrate.

Tags
deprecated
8.0.0

Use fetch_sanitized_migration_data and process_migration_data instead.

Return values
void