PostsToOrdersMigrationController
in package
This is the main class used to perform the complete migration of orders from the posts table to the custom orders table.
Table of Contents
- LOGS_SOURCE_NAME = 'posts-to-orders-migration'
- The source name to use for logs.
- $all_migrators : array<string|int, TableMigrator>
- Array of objects used to perform the migration.
- $error_logger : WC_Logger
- Error logger for migration errors.
- __construct() : mixed
- PostsToOrdersMigrationController constructor.
- get_migrated_meta_keys() : array<string|int, string>
- Helper method to get migrated keys for all the tables in this controller.
- migrate_order() : void
- Migrates an order from the posts table to the custom orders tables.
- migrate_orders() : void
- Migrates a set of orders from the posts table to the custom orders tables.
- verify_migrated_orders() : array<string|int, mixed>
- Verify whether the given order IDs were migrated properly or not.
- commit_transaction() : bool
- Commit the current database transaction.
- db_query() : bool
- Execute a database query and log any errors.
- handle_migration_error() : mixed
- Log migration errors if any.
- maybe_start_transaction() : bool|null
- Start a database transaction if the configuration mandates so.
- rollback_transaction() : bool
- Rollback the current database transaction.
Constants
LOGS_SOURCE_NAME
The source name to use for logs.
public
mixed
LOGS_SOURCE_NAME
= 'posts-to-orders-migration'
Properties
$all_migrators
Array of objects used to perform the migration.
private
array<string|int, TableMigrator>
$all_migrators
$error_logger
Error logger for migration errors.
private
WC_Logger
$error_logger
Methods
__construct()
PostsToOrdersMigrationController constructor.
public
__construct() : mixed
Return values
mixed —get_migrated_meta_keys()
Helper method to get migrated keys for all the tables in this controller.
public
get_migrated_meta_keys() : array<string|int, string>
Return values
array<string|int, string> — Array of meta keys.migrate_order()
Migrates an order from the posts table to the custom orders tables.
public
migrate_order(int $order_post_id) : void
Parameters
- $order_post_id : int
-
Post ID of the order to migrate.
Return values
void —migrate_orders()
Migrates a set of orders from the posts table to the custom orders tables.
public
migrate_orders(array<string|int, mixed> $order_post_ids) : void
Parameters
- $order_post_ids : array<string|int, mixed>
-
List of post IDs of the orders to migrate.
Return values
void —verify_migrated_orders()
Verify whether the given order IDs were migrated properly or not.
public
verify_migrated_orders(array<string|int, mixed> $order_post_ids) : array<string|int, mixed>
Parameters
- $order_post_ids : array<string|int, mixed>
-
Order IDs.
Return values
array<string|int, mixed> — Array of failed IDs along with columns.commit_transaction()
Commit the current database transaction.
private
commit_transaction() : bool
Return values
bool — True on success, false on error.db_query()
Execute a database query and log any errors.
private
db_query(string $query[, bool $supress_errors = false ]) : bool
Parameters
- $query : string
-
The SQL query to execute.
- $supress_errors : bool = false
-
Whether to suppress errors.
Return values
bool — True if the query succeeded, false if there were errors.handle_migration_error()
Log migration errors if any.
private
handle_migration_error(array<string|int, mixed> $order_post_ids, array<string|int, mixed> $errors, Exception|null $exception, bool|null $using_transactions, string $name) : mixed
Parameters
- $order_post_ids : array<string|int, mixed>
-
List of post IDs of the orders to migrate.
- $errors : array<string|int, mixed>
-
List of errors to log.
- $exception : Exception|null
-
Exception to log.
- $using_transactions : bool|null
-
Whether transactions were used.
- $name : string
-
Name of the migrator.
Return values
mixed —maybe_start_transaction()
Start a database transaction if the configuration mandates so.
private
maybe_start_transaction() : bool|null
Tags
Return values
bool|null — True if transaction started, false if transactions won't be used, null if transaction failed to start.rollback_transaction()
Rollback the current database transaction.
private
rollback_transaction() : bool