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
PostToOrderOpTableMigrator.php
142 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class for WPPost to wc_order_operational_details migrator. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Database\Migrations\CustomOrderTable; |
| 7 | |
| 8 | use Automattic\WooCommerce\Database\Migrations\MetaToCustomTableMigrator; |
| 9 | use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore; |
| 10 | |
| 11 | /** |
| 12 | * Helper class to migrate records from the WordPress post table |
| 13 | * to the custom order operations table. |
| 14 | * |
| 15 | * @package Automattic\WooCommerce\Database\Migrations\CustomOrderTable |
| 16 | */ |
| 17 | class PostToOrderOpTableMigrator extends MetaToCustomTableMigrator { |
| 18 | |
| 19 | /** |
| 20 | * Get schema config for wp_posts and wc_order_operational_detail table. |
| 21 | * |
| 22 | * @return array Config. |
| 23 | */ |
| 24 | protected function get_schema_config(): array { |
| 25 | global $wpdb; |
| 26 | |
| 27 | return array( |
| 28 | 'source' => array( |
| 29 | 'entity' => array( |
| 30 | 'table_name' => $wpdb->posts, |
| 31 | 'meta_rel_column' => 'ID', |
| 32 | 'destination_rel_column' => 'ID', |
| 33 | 'primary_key' => 'ID', |
| 34 | ), |
| 35 | 'meta' => array( |
| 36 | 'table_name' => $wpdb->postmeta, |
| 37 | 'meta_id_column' => 'meta_id', |
| 38 | 'meta_key_column' => 'meta_key', |
| 39 | 'meta_value_column' => 'meta_value', |
| 40 | 'entity_id_column' => 'post_id', |
| 41 | ), |
| 42 | ), |
| 43 | 'destination' => array( |
| 44 | 'table_name' => OrdersTableDataStore::get_operational_data_table_name(), |
| 45 | 'source_rel_column' => 'order_id', |
| 46 | 'primary_key' => 'id', |
| 47 | 'primary_key_type' => 'int', |
| 48 | ), |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | /** |
| 54 | * Get columns config. |
| 55 | * |
| 56 | * @return \string[][] Config. |
| 57 | */ |
| 58 | protected function get_core_column_mapping(): array { |
| 59 | return array( |
| 60 | 'ID' => array( |
| 61 | 'type' => 'int', |
| 62 | 'destination' => 'order_id', |
| 63 | ), |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | * Get meta data config. |
| 70 | * |
| 71 | * @return \string[][] Config. |
| 72 | */ |
| 73 | public function get_meta_column_config(): array { |
| 74 | return array( |
| 75 | '_created_via' => array( |
| 76 | 'type' => 'string', |
| 77 | 'destination' => 'created_via', |
| 78 | ), |
| 79 | '_order_version' => array( |
| 80 | 'type' => 'string', |
| 81 | 'destination' => 'woocommerce_version', |
| 82 | ), |
| 83 | '_prices_include_tax' => array( |
| 84 | 'type' => 'bool', |
| 85 | 'destination' => 'prices_include_tax', |
| 86 | ), |
| 87 | '_recorded_coupon_usage_counts' => array( |
| 88 | 'type' => 'bool', |
| 89 | 'destination' => 'coupon_usages_are_counted', |
| 90 | ), |
| 91 | '_download_permissions_granted' => array( |
| 92 | 'type' => 'bool', |
| 93 | 'destination' => 'download_permission_granted', |
| 94 | ), |
| 95 | '_cart_hash' => array( |
| 96 | 'type' => 'string', |
| 97 | 'destination' => 'cart_hash', |
| 98 | ), |
| 99 | '_new_order_email_sent' => array( |
| 100 | 'type' => 'bool', |
| 101 | 'destination' => 'new_order_email_sent', |
| 102 | ), |
| 103 | '_order_key' => array( |
| 104 | 'type' => 'string', |
| 105 | 'destination' => 'order_key', |
| 106 | ), |
| 107 | '_order_stock_reduced' => array( |
| 108 | 'type' => 'bool', |
| 109 | 'destination' => 'order_stock_reduced', |
| 110 | ), |
| 111 | '_date_paid' => array( |
| 112 | 'type' => 'date_epoch', |
| 113 | 'destination' => 'date_paid_gmt', |
| 114 | ), |
| 115 | '_date_completed' => array( |
| 116 | 'type' => 'date_epoch', |
| 117 | 'destination' => 'date_completed_gmt', |
| 118 | ), |
| 119 | '_order_shipping_tax' => array( |
| 120 | 'type' => 'decimal', |
| 121 | 'destination' => 'shipping_tax_amount', |
| 122 | ), |
| 123 | '_order_shipping' => array( |
| 124 | 'type' => 'decimal', |
| 125 | 'destination' => 'shipping_total_amount', |
| 126 | ), |
| 127 | '_cart_discount_tax' => array( |
| 128 | 'type' => 'decimal', |
| 129 | 'destination' => 'discount_tax_amount', |
| 130 | ), |
| 131 | '_cart_discount' => array( |
| 132 | 'type' => 'decimal', |
| 133 | 'destination' => 'discount_total_amount', |
| 134 | ), |
| 135 | '_recorded_sales' => array( |
| 136 | 'type' => 'bool', |
| 137 | 'destination' => 'recorded_sales', |
| 138 | ), |
| 139 | ); |
| 140 | } |
| 141 | } |
| 142 |