WooCommerce Code Reference

MigrationHelper
in package

Helper class to assist with migration related operations.

Table of Contents

$wpdb_placeholder_for_type  : array<string|int, string>
Placeholders that we will use in building $wpdb queries.
escape_and_add_backtick()  : array<string|int, mixed>|string|array<string|int, string>
Helper method to escape backtick in column and table names.
escape_schema_for_backtick()  : array<string|int, mixed>
Helper method to escape backtick in various schema fields.
generate_on_duplicate_statement_clause()  : string
Generates ON DUPLICATE KEY UPDATE clause to be used in migration.
get_wpdb_placeholder_for_type()  : string
Return $wpdb->prepare placeholder for data type.
migrate_country_states()  : bool
Migrate state codes in all the required places in the database, needed after they change for a given country.
migrate_country_states_for_misc_data()  : void
Migrate state codes in all the required places in the database (except orders).
migrate_country_states_for_orders()  : bool
Migrate state codes for orders in the orders table and in the posts table.
migrate_country_states_for_shipping_locations()  : void
Migrate state codes in the shipping locations table.
migrate_country_states_for_store_location()  : void
Migrate the state code for the store location.
migrate_country_states_for_tax_rates()  : void
Migrate state codes in the tax rates table.

Properties

$wpdb_placeholder_for_type

Placeholders that we will use in building $wpdb queries.

private static array<string|int, string> $wpdb_placeholder_for_type = array('int' => '%d', 'decimal' => '%f', 'string' => '%s', 'date' => '%s', 'date_epoch' => '%s', 'bool' => '%d')

Methods

escape_and_add_backtick()

Helper method to escape backtick in column and table names.

public static escape_and_add_backtick(string|array<string|int, mixed> $identifier) : array<string|int, mixed>|string|array<string|int, string>

WP does not provide a method to escape table/columns names yet, but hopefully soon in @link https://core.trac.wordpress.org/ticket/52506

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

Column or table name.

Return values
array<string|int, mixed>|string|array<string|int, string>Escaped identifier.

escape_schema_for_backtick()

Helper method to escape backtick in various schema fields.

public static escape_schema_for_backtick(array<string|int, mixed> $schema_config) : array<string|int, mixed>
Parameters
$schema_config : array<string|int, mixed>

Schema config.

Return values
array<string|int, mixed>Schema config escaped for backtick.

generate_on_duplicate_statement_clause()

Generates ON DUPLICATE KEY UPDATE clause to be used in migration.

public static generate_on_duplicate_statement_clause(array<string|int, mixed> $columns) : string
Parameters
$columns : array<string|int, mixed>

List of column names.

Return values
stringSQL clause for INSERT...ON DUPLICATE KEY UPDATE

get_wpdb_placeholder_for_type()

Return $wpdb->prepare placeholder for data type.

public static get_wpdb_placeholder_for_type(string $type) : string
Parameters
$type : string

Data type.

Return values
string$wpdb placeholder.

migrate_country_states()

Migrate state codes in all the required places in the database, needed after they change for a given country.

public static migrate_country_states(string $country_code, array<string|int, mixed> $old_to_new_states_mapping) : bool
Parameters
$country_code : string

The country that has the states for which the migration is needed.

$old_to_new_states_mapping : array<string|int, mixed>

An associative array where keys are the old state codes and values are the new state codes.

Return values
boolTrue if there are more records that need to be migrated, false otherwise.

migrate_country_states_for_misc_data()

Migrate state codes in all the required places in the database (except orders).

private static migrate_country_states_for_misc_data(string $country_code, array<string|int, mixed> $old_to_new_states_mapping) : void
Parameters
$country_code : string

The country that has the states for which the migration is needed.

$old_to_new_states_mapping : array<string|int, mixed>

An associative array where keys are the old state codes and values are the new state codes.

Return values
void

migrate_country_states_for_orders()

Migrate state codes for orders in the orders table and in the posts table.

private static migrate_country_states_for_orders(string $country_code, array<string|int, mixed> $old_to_new_states_mapping) : bool

It will migrate only N2(number of states) records, being N equal to 100 by default but this number can be modified via the woocommerce_migrate_country_states_for_orders_batch_size filter.

Parameters
$country_code : string

The country that has the states for which the migration is needed.

$old_to_new_states_mapping : array<string|int, mixed>

An associative array where keys are the old state codes and values are the new state codes.

Return values
boolTrue if there are more records that need to be migrated, false otherwise.

migrate_country_states_for_shipping_locations()

Migrate state codes in the shipping locations table.

private static migrate_country_states_for_shipping_locations(string $country_code, array<string|int, mixed> $old_to_new_states_mapping) : void
Parameters
$country_code : string

The country that has the states for which the migration is needed.

$old_to_new_states_mapping : array<string|int, mixed>

An associative array where keys are the old state codes and values are the new state codes.

Return values
void

migrate_country_states_for_store_location()

Migrate the state code for the store location.

private static migrate_country_states_for_store_location(string $country_code, array<string|int, mixed> $old_to_new_states_mapping) : void
Parameters
$country_code : string

The country that has the states for which the migration is needed.

$old_to_new_states_mapping : array<string|int, mixed>

An associative array where keys are the old state codes and values are the new state codes.

Return values
void

migrate_country_states_for_tax_rates()

Migrate state codes in the tax rates table.

private static migrate_country_states_for_tax_rates(string $country_code, array<string|int, mixed> $old_to_new_states_mapping) : void
Parameters
$country_code : string

The country that has the states for which the migration is needed.

$old_to_new_states_mapping : array<string|int, mixed>

An associative array where keys are the old state codes and values are the new state codes.

Return values
void