| @@ -3,8 +3,15 @@ | ||
| 3 | 3 | namespace SpringDevs\Subscription; |
| 4 | 4 | |
| 5 | 5 | use SpringDevs\Subscription\Installer; |
| 6 | 6 | |
| 7 | +// HPOS: This file uses direct SQL on postmeta for migration/upgrade tasks only. | |
| 8 | +// Do NOT use direct SQL for live WooCommerce order data access—use WooCommerce CRUD for HPOS compatibility. | |
| 9 | +// All live order data access must use WooCommerce CRUD methods. | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * Upgrade class | |
| 13 | + */ | |
| 7 | 14 | class Upgrade { |
| 8 | 15 | |
| 9 | 16 | public function run() { |
| 10 | 17 | if ( version_compare( '1.1.0', get_option( 'subscrpt_version' ), '>' ) ) { |
| @@ -22,10 +29,9 @@ | ||
| 22 | 29 | } |
| 23 | 30 | |
| 24 | 31 | public function move_product_meta() { |
| 25 | 32 | global $wpdb; |
| 26 | - $product_meta_query = 'SELECT * FROM ' . $wpdb->prefix . "postmeta WHERE meta_key='subscrpt_general'"; | |
| 27 | - $products_meta = $wpdb->get_results( $product_meta_query ); | |
| 33 | + $products_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->postmeta} WHERE meta_key = %s", 'subscrpt_general' ) ); | |
| 28 | 34 | foreach ( $products_meta as $product_meta ) { |
| 29 | 35 | update_post_meta( $product_meta->post_id, '_subscrpt_meta', unserialize( $product_meta->meta_value ) ); |
| 30 | 36 | update_post_meta( |
| 31 | 37 | $product_meta->post_id, |
| @@ -43,13 +49,11 @@ | ||
| 43 | 49 | |
| 44 | 50 | public function update_subscription_meta() { |
| 45 | 51 | global $wpdb; |
| 46 | 52 | |
| 47 | - $subscription_meta_query = 'SELECT * FROM ' . $wpdb->prefix . "postmeta WHERE meta_key='_subscrpt_order_general'"; | |
| 48 | - $subscriptions_meta = $wpdb->get_results( $subscription_meta_query ); | |
| 53 | + $subscriptions_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->postmeta} WHERE meta_key = %s", '_subscrpt_order_general' ) ); | |
| 49 | 54 | |
| 50 | - $subscription_history_query = 'SELECT * FROM ' . $wpdb->prefix . "postmeta WHERE meta_key='_subscrpt_order_history'"; | |
| 51 | - $histories = $wpdb->get_results( $subscription_history_query ); | |
| 55 | + $histories = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->postmeta} WHERE meta_key = %s", '_subscrpt_order_history' ) ); | |
| 52 | 56 | |
| 53 | 57 | foreach ( $subscriptions_meta as $subscription_meta ) { |
| 54 | 58 | $subscription_meta_value = unserialize( $subscription_meta->meta_value ); |
| 55 | 59 | $order_item_id = 0; |
| @@ -123,10 +127,9 @@ | ||
| 123 | 127 | } |
| 124 | 128 | |
| 125 | 129 | public function update_comment_meta() { |
| 126 | 130 | global $wpdb; |
| 127 | - $query = 'SELECT * FROM ' . $wpdb->prefix . "commentmeta WHERE meta_key='subscrpt_activity'"; | |
| 128 | - $comments_meta = $wpdb->get_results( $query ); | |
| 131 | + $comments_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->commentmeta} WHERE meta_key = %s", 'subscrpt_activity' ) ); | |
| 129 | 132 | foreach ( $comments_meta as $comment_meta ) { |
| 130 | 133 | update_comment_meta( $comment_meta->comment_id, '_subscrpt_activity', $comment_meta->meta_value ); |
| 131 | 134 | delete_comment_meta( $comment_meta->comment_id, 'subscrpt_activity' ); |
| 132 | 135 | } |