WooCommerce Code Reference

PostMetaToOrderMetaMigrator extends MetaToMetaTableMigrator

Helper class to migrate records from the WordPress post meta table to the custom orders meta table.

Table of Contents

$errors  : array<string|int, mixed>
An array of cummulated error messages.
$excluded_columns  : array<string|int, mixed>
List of meta keys to exclude from migration.
$schema_config  : array<string|int, mixed>
Schema config, see __construct for more details.
__construct()  : mixed
PostMetaToOrderMetaMigrator constructor.
fetch_data_for_migration_for_ids()  : array<string|int, array<string|int, mixed>>
Fetch data for migration.
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.
get_meta_config()  : array<string|int, mixed>
Generate config for meta data migration.
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.
build_meta_table_query()  : string
Helper method to build query used to fetch data from source meta table.
classify_update_insert_records()  : array<string|int, array<string|int, mixed>>
Classify each record on whether to migrate or update.
generate_insert_sql_for_batch()  : string
Generate insert sql queries for batches.
generate_update_sql_for_batch()  : string
Generate update SQL for given batch.
get_already_migrated_records()  : array<string|int, mixed>
Helper method to get already migrated records. Will be used to find prevent migration of already migrated records.

Properties

Methods

fetch_data_for_migration_for_ids()

Fetch data for migration.

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

Array of IDs to fetch data for.

Return values
array<string|int, array<string|int, mixed>>Data, will of the form: array( 'id_1' => array( 'column1' => array( value1_1, value1_2...), 'column2' => array(value2_1, value2_2...), ...), ..., )

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

build_meta_table_query()

Helper method to build query used to fetch data from source meta table.

private build_meta_table_query(array<string|int, mixed> $entity_ids) : string
Parameters
$entity_ids : array<string|int, mixed>

List of entity IDs to build meta query for.

Return values
stringQuery that can be used to fetch data.

classify_update_insert_records()

Classify each record on whether to migrate or update.

private classify_update_insert_records(array<string|int, mixed> $to_migrate, array<string|int, mixed> $already_migrated) : array<string|int, array<string|int, mixed>>
Parameters
$to_migrate : array<string|int, mixed>

Records to migrate.

$already_migrated : array<string|int, mixed>

Records already migrated.

Return values
array<string|int, array<string|int, mixed>>Returns two arrays, first for records to migrate, and second for records to upgrade.

generate_insert_sql_for_batch()

Generate insert sql queries for batches.

private generate_insert_sql_for_batch(array<string|int, mixed> $batch) : string
Parameters
$batch : array<string|int, mixed>

Data to generate queries for.

Return values
stringInsert SQL query.

generate_update_sql_for_batch()

Generate update SQL for given batch.

private generate_update_sql_for_batch(array<string|int, mixed> $batch) : string
Parameters
$batch : array<string|int, mixed>

List of data to generate update SQL for. Should be in same format as output of $this->fetch_data_for_migration_for_ids.

Return values
stringQuery to update batch records.

get_already_migrated_records()

Helper method to get already migrated records. Will be used to find prevent migration of already migrated records.

private get_already_migrated_records(array<string|int, mixed> $entity_ids) : array<string|int, mixed>
Parameters
$entity_ids : array<string|int, mixed>

List of entity ids to check for.

Return values
array<string|int, mixed>Already migrated records.