Creates_Reports.php
1 year ago
Migration.php
1 year ago
Migration_10.php
2 years ago
Migration_11.php
2 years ago
Migration_12.php
1 year ago
Migration_13.php
2 years ago
Migration_14.php
2 years ago
Migration_15.php
2 years ago
Migration_16.php
2 years ago
Migration_17.php
1 year ago
Migration_18.php
2 years ago
Migration_19.php
2 years ago
Migration_1_0.php
2 years ago
Migration_1_6.php
2 years ago
Migration_1_8.php
2 years ago
Migration_1_9.php
2 years ago
Migration_2.php
2 years ago
Migration_20.php
2 years ago
Migration_21.php
2 years ago
Migration_22.php
2 years ago
Migration_23.php
1 year ago
Migration_24.php
2 years ago
Migration_25.php
2 years ago
Migration_26.php
2 years ago
Migration_27.php
2 years ago
Migration_28.php
2 years ago
Migration_29.php
2 years ago
Migration_3.php
2 years ago
Migration_30.php
2 years ago
Migration_31.php
2 years ago
Migration_32.php
2 years ago
Migration_33.php
2 years ago
Migration_34.php
1 year ago
Migration_35.php
1 year ago
Migration_36.php
1 year ago
Migration_37.php
1 year ago
Migration_38.php
1 year ago
Migration_39.php
1 year ago
Migration_4.php
2 years ago
Migration_40.php
1 year ago
Migration_41.php
1 year ago
Migration_42.php
1 year ago
Migration_43.php
1 year ago
Migration_44.php
9 months ago
Migration_45.php
8 months ago
Migration_46.php
8 months ago
Migration_47.php
8 months ago
Migration_48.php
8 months ago
Migration_49.php
8 months ago
Migration_5.php
2 years ago
Migration_50.php
9 months ago
Migration_51.php
8 months ago
Migration_52.php
8 months ago
Migration_6.php
2 years ago
Migration_7.php
1 year ago
Migration_8.php
2 years ago
Migration_9.php
2 years ago
Migration_Job.php
1 year ago
Migrations.php
8 months ago
Step_Migration.php
6 months ago
Migration_37.php
44 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Migrations; |
| 4 | |
| 5 | use IAWP\Query; |
| 6 | /** @internal */ |
| 7 | class Migration_37 extends \IAWP\Migrations\Step_Migration |
| 8 | { |
| 9 | /** |
| 10 | * @return int |
| 11 | */ |
| 12 | protected function database_version() : int |
| 13 | { |
| 14 | return 37; |
| 15 | } |
| 16 | /** |
| 17 | * @return array |
| 18 | */ |
| 19 | protected function queries() : array |
| 20 | { |
| 21 | return [$this->remove_duplicate_woocommerce_orders(), $this->remove_duplicate_surecart_orders(), $this->add_unique_index_for_woocommerce_order_id(), $this->add_unique_index_for_surecart_order_id()]; |
| 22 | } |
| 23 | private function remove_duplicate_woocommerce_orders() : string |
| 24 | { |
| 25 | $orders_table = Query::get_table_name(Query::ORDERS); |
| 26 | return "\n DELETE orders\n FROM\n {$orders_table} orders\n JOIN (\n SELECT\n woocommerce_order_id,\n MIN(order_id) AS first_order_id\n FROM\n {$orders_table}\n GROUP BY\n woocommerce_order_id\n ) first_orders ON orders.woocommerce_order_id = first_orders.woocommerce_order_id\n AND orders.order_id > first_orders.first_order_id; \n "; |
| 27 | } |
| 28 | private function remove_duplicate_surecart_orders() : string |
| 29 | { |
| 30 | $orders_table = Query::get_table_name(Query::ORDERS); |
| 31 | return "\n DELETE orders\n FROM\n {$orders_table} orders\n JOIN (\n SELECT\n surecart_order_id,\n MIN(order_id) AS first_order_id\n FROM\n {$orders_table}\n GROUP BY\n surecart_order_id\n ) first_orders ON orders.surecart_order_id = first_orders.surecart_order_id\n AND orders.order_id > first_orders.first_order_id;\n "; |
| 32 | } |
| 33 | private function add_unique_index_for_woocommerce_order_id() : string |
| 34 | { |
| 35 | $orders_table = Query::get_table_name(Query::ORDERS); |
| 36 | return "\n CREATE UNIQUE INDEX orders_woocommerce_order_id_index ON {$orders_table} (woocommerce_order_id)\n "; |
| 37 | } |
| 38 | private function add_unique_index_for_surecart_order_id() : string |
| 39 | { |
| 40 | $orders_table = Query::get_table_name(Query::ORDERS); |
| 41 | return "\n CREATE UNIQUE INDEX orders_surecart_order_id_index ON {$orders_table} (surecart_order_id)\n "; |
| 42 | } |
| 43 | } |
| 44 |