CLIRunner.php
4 months ago
PostMetaToOrderMetaMigrator.php
2 years ago
PostToOrderAddressTableMigrator.php
2 years ago
PostToOrderOpTableMigrator.php
2 years ago
PostToOrderTableMigrator.php
3 years ago
PostsToOrdersMigrationController.php
1 year ago
PostToOrderTableMigrator.php
145 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class for WPPost To order table migrator. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Database\Migrations\CustomOrderTable; |
| 7 | |
| 8 | use Automattic\WooCommerce\Database\Migrations\MetaToCustomTableMigrator; |
| 9 | |
| 10 | /** |
| 11 | * Helper class to migrate records from the WordPress post table |
| 12 | * to the custom order table (and only that table - PostsToOrdersMigrationController |
| 13 | * is used for fully migrating orders). |
| 14 | */ |
| 15 | class PostToOrderTableMigrator extends MetaToCustomTableMigrator { |
| 16 | |
| 17 | /** |
| 18 | * Get schema config for wp_posts and wc_order table. |
| 19 | * |
| 20 | * @return array Config. |
| 21 | */ |
| 22 | protected function get_schema_config(): array { |
| 23 | global $wpdb; |
| 24 | |
| 25 | $table_names = array( |
| 26 | 'orders' => $wpdb->prefix . 'wc_orders', |
| 27 | 'addresses' => $wpdb->prefix . 'wc_order_addresses', |
| 28 | 'op_data' => $wpdb->prefix . 'wc_order_operational_data', |
| 29 | 'meta' => $wpdb->prefix . 'wc_orders_meta', |
| 30 | ); |
| 31 | |
| 32 | return array( |
| 33 | 'source' => array( |
| 34 | 'entity' => array( |
| 35 | 'table_name' => $wpdb->posts, |
| 36 | 'meta_rel_column' => 'ID', |
| 37 | 'destination_rel_column' => 'ID', |
| 38 | 'primary_key' => 'ID', |
| 39 | ), |
| 40 | 'meta' => array( |
| 41 | 'table_name' => $wpdb->postmeta, |
| 42 | 'meta_id_column' => 'meta_id', |
| 43 | 'meta_key_column' => 'meta_key', |
| 44 | 'meta_value_column' => 'meta_value', |
| 45 | 'entity_id_column' => 'post_id', |
| 46 | ), |
| 47 | ), |
| 48 | 'destination' => array( |
| 49 | 'table_name' => $table_names['orders'], |
| 50 | 'source_rel_column' => 'id', |
| 51 | 'primary_key' => 'id', |
| 52 | 'primary_key_type' => 'int', |
| 53 | ), |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Get columns config. |
| 59 | * |
| 60 | * @return \string[][] Config. |
| 61 | */ |
| 62 | protected function get_core_column_mapping(): array { |
| 63 | return array( |
| 64 | 'ID' => array( |
| 65 | 'type' => 'int', |
| 66 | 'destination' => 'id', |
| 67 | ), |
| 68 | 'post_status' => array( |
| 69 | 'type' => 'string', |
| 70 | 'destination' => 'status', |
| 71 | ), |
| 72 | 'post_date_gmt' => array( |
| 73 | 'type' => 'date', |
| 74 | 'destination' => 'date_created_gmt', |
| 75 | ), |
| 76 | 'post_modified_gmt' => array( |
| 77 | 'type' => 'date', |
| 78 | 'destination' => 'date_updated_gmt', |
| 79 | ), |
| 80 | 'post_parent' => array( |
| 81 | 'type' => 'int', |
| 82 | 'destination' => 'parent_order_id', |
| 83 | ), |
| 84 | 'post_type' => array( |
| 85 | 'type' => 'string', |
| 86 | 'destination' => 'type', |
| 87 | ), |
| 88 | 'post_excerpt' => array( |
| 89 | 'type' => 'string', |
| 90 | 'destination' => 'customer_note', |
| 91 | ), |
| 92 | ); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Get meta data config. |
| 97 | * |
| 98 | * @return \string[][] Config. |
| 99 | */ |
| 100 | public function get_meta_column_config(): array { |
| 101 | return array( |
| 102 | '_order_currency' => array( |
| 103 | 'type' => 'string', |
| 104 | 'destination' => 'currency', |
| 105 | ), |
| 106 | '_order_tax' => array( |
| 107 | 'type' => 'decimal', |
| 108 | 'destination' => 'tax_amount', |
| 109 | ), |
| 110 | '_order_total' => array( |
| 111 | 'type' => 'decimal', |
| 112 | 'destination' => 'total_amount', |
| 113 | ), |
| 114 | '_customer_user' => array( |
| 115 | 'type' => 'int', |
| 116 | 'destination' => 'customer_id', |
| 117 | ), |
| 118 | '_billing_email' => array( |
| 119 | 'type' => 'string', |
| 120 | 'destination' => 'billing_email', |
| 121 | ), |
| 122 | '_payment_method' => array( |
| 123 | 'type' => 'string', |
| 124 | 'destination' => 'payment_method', |
| 125 | ), |
| 126 | '_payment_method_title' => array( |
| 127 | 'type' => 'string', |
| 128 | 'destination' => 'payment_method_title', |
| 129 | ), |
| 130 | '_customer_ip_address' => array( |
| 131 | 'type' => 'string', |
| 132 | 'destination' => 'ip_address', |
| 133 | ), |
| 134 | '_customer_user_agent' => array( |
| 135 | 'type' => 'string', |
| 136 | 'destination' => 'user_agent', |
| 137 | ), |
| 138 | '_transaction_id' => array( |
| 139 | 'type' => 'string', |
| 140 | 'destination' => 'transaction_id', |
| 141 | ), |
| 142 | ); |
| 143 | } |
| 144 | } |
| 145 |