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
PostMetaToOrderMetaMigrator.php
73 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Migration class for migrating from WPPostMeta to OrderMeta table. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Database\Migrations\CustomOrderTable; |
| 7 | |
| 8 | use Automattic\WooCommerce\Database\Migrations\MetaToMetaTableMigrator; |
| 9 | use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore; |
| 10 | |
| 11 | /** |
| 12 | * Helper class to migrate records from the WordPress post meta table |
| 13 | * to the custom orders meta table. |
| 14 | * |
| 15 | * @package Automattic\WooCommerce\Database\Migrations\CustomOrderTable |
| 16 | */ |
| 17 | class PostMetaToOrderMetaMigrator extends MetaToMetaTableMigrator { |
| 18 | |
| 19 | /** |
| 20 | * List of meta keys to exclude from migration. |
| 21 | * |
| 22 | * @var array |
| 23 | */ |
| 24 | private $excluded_columns; |
| 25 | |
| 26 | /** |
| 27 | * PostMetaToOrderMetaMigrator constructor. |
| 28 | * |
| 29 | * @param array $excluded_columns List of meta keys to exclude from migration. |
| 30 | */ |
| 31 | public function __construct( $excluded_columns ) { |
| 32 | $this->excluded_columns = $excluded_columns; |
| 33 | parent::__construct(); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Generate config for meta data migration. |
| 38 | * |
| 39 | * @return array Meta data migration config. |
| 40 | */ |
| 41 | protected function get_meta_config(): array { |
| 42 | global $wpdb; |
| 43 | |
| 44 | return array( |
| 45 | 'source' => array( |
| 46 | 'meta' => array( |
| 47 | 'table_name' => $wpdb->postmeta, |
| 48 | 'entity_id_column' => 'post_id', |
| 49 | 'meta_id_column' => 'meta_id', |
| 50 | 'meta_key_column' => 'meta_key', |
| 51 | 'meta_value_column' => 'meta_value', |
| 52 | ), |
| 53 | 'entity' => array( |
| 54 | 'table_name' => $wpdb->posts, |
| 55 | 'source_id_column' => 'ID', |
| 56 | 'id_column' => 'ID', |
| 57 | ), |
| 58 | 'excluded_keys' => $this->excluded_columns, |
| 59 | ), |
| 60 | 'destination' => array( |
| 61 | 'meta' => array( |
| 62 | 'table_name' => OrdersTableDataStore::get_meta_table_name(), |
| 63 | 'entity_id_column' => 'order_id', |
| 64 | 'meta_key_column' => 'meta_key', |
| 65 | 'meta_value_column' => 'meta_value', |
| 66 | 'entity_id_type' => 'int', |
| 67 | 'meta_id_column' => 'id', |
| 68 | ), |
| 69 | ), |
| 70 | ); |
| 71 | } |
| 72 | } |
| 73 |