PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 1.3.1
Subscriptions for WooCommerce with Stripe Recurring Payments v1.3.1
2.0.0 1.11.2 1.11.1 1.11.0 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.6 1.9.5 trunk 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 All 61 releases
subscription / includes / Upgrade.php

Upgrade.php in Subscriptions for WooCommerce with Stripe Recurring Payments 1.3.1, at includes/Upgrade.php

135 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SpringDevs\Subscription;
4
5 use SpringDevs\Subscription\Installer;
6
7 class Upgrade {
8
9 public function run() {
10 if ( version_compare( '1.1.0', get_option( 'subscrpt_version' ), '>' ) ) {
11
12 // create histories table
13 $installer = new Installer();
14 $installer->create_tables();
15
16 // move product meta
17 $this->move_product_meta();
18 // update subscription meta
19 $this->update_subscription_meta();
20 $this->update_comment_meta();
21 }
22 }
23
24 public function move_product_meta() {
25 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 );
28 foreach ( $products_meta as $product_meta ) {
29 update_post_meta( $product_meta->post_id, '_subscrpt_meta', unserialize( $product_meta->meta_value ) );
30 update_post_meta(
31 $product_meta->post_id,
32 '_subscrpt_user_cancel',
33 get_post_meta(
34 $product_meta->post_id,
35 '_subscrpt_user_cancell',
36 true
37 )
38 );
39 delete_post_meta( $product_meta->post_id, '_subscrpt_user_cancell' );
40 delete_post_meta( $product_meta->post_id, 'subscrpt_general' );
41 }
42 }
43
44 public function update_subscription_meta() {
45 global $wpdb;
46
47 $subscription_meta_query = 'SELECT * FROM ' . $wpdb->prefix . "postmeta WHERE meta_key='_subscrpt_order_general'";
48 $subscriptions_meta = $wpdb->get_results( $subscription_meta_query );
49
50 $subscription_history_query = 'SELECT * FROM ' . $wpdb->prefix . "postmeta WHERE meta_key='_subscrpt_order_history'";
51 $histories = $wpdb->get_results( $subscription_history_query );
52
53 foreach ( $subscriptions_meta as $subscription_meta ) {
54 $subscription_meta_value = unserialize( $subscription_meta->meta_value );
55 $order_item_id = 0;
56 $order = wc_get_order( $subscription_meta_value['order_id'] );
57
58 if ( $order ) {
59 foreach ( $order->get_items() as $order_item ) {
60 if ( $order_item->get_product_id() == $subscription_meta_value['product_id'] ) {
61 $order_item_id = $order_item->get_id();
62 }
63 }
64 }
65
66 update_post_meta(
67 $subscription_meta->post_id,
68 '_order_subscrpt_meta',
69 array(
70 'order_id' => $subscription_meta_value['order_id'],
71 'order_item_id' => $order_item_id,
72 'trial' => $subscription_meta_value['trial'],
73 'start_date' => $subscription_meta_value['start_date'],
74 'next_date' => $subscription_meta_value['next_date'],
75 )
76 );
77
78 delete_post_meta( $subscription_meta->post_id, '_subscrpt_order_general' );
79 }
80
81 foreach ( $histories as $history ) {
82 $histories_meta = unserialize( $history->meta_value );
83
84 foreach ( $histories_meta as $history_meta ) {
85 $order = wc_get_order( $history_meta['order_id'] );
86 $product_meta = get_post_meta( $history_meta['product_id'], '_subscrpt_meta', true );
87 $order = wc_get_order( $history_meta['order_id'] );
88
89 if ( $order ) {
90 $order_item_id = 0;
91 foreach ( $order->get_items() as $order_item ) {
92 if ( $order_item->get_product_id() == $history_meta['product_id'] ) {
93 $order_item_id = $order_item->get_id();
94 wc_update_order_item_meta(
95 $order_item->get_id(),
96 '_subscrpt_meta',
97 array(
98 'time' => $product_meta['time'],
99 'type' => $product_meta['type'],
100 'trial' => $history_meta['trial'],
101 'start_date' => $history_meta['start_date'],
102 'next_date' => $history_meta['next_date'],
103 )
104 );
105 }
106 }
107
108 $history_table = $wpdb->prefix . 'subscrpt_order_relation';
109 $wpdb->insert(
110 $history_table,
111 array(
112 'subscription_id' => $history_meta['post_id'],
113 'order_id' => $history_meta['order_id'],
114 'order_item_id' => $order_item_id,
115 'type' => 'Parent Order' === $history_meta['stats'] ? 'new' : 'renew',
116 )
117 );
118 }
119 }
120
121 delete_post_meta( $history->post_id, '_subscrpt_order_history' );
122 }
123 }
124
125 public function update_comment_meta() {
126 global $wpdb;
127 $query = 'SELECT * FROM ' . $wpdb->prefix . "commentmeta WHERE meta_key='subscrpt_activity'";
128 $comments_meta = $wpdb->get_results( $query );
129 foreach ( $comments_meta as $comment_meta ) {
130 update_comment_meta( $comment_meta->comment_id, '_subscrpt_activity', $comment_meta->meta_value );
131 delete_comment_meta( $comment_meta->comment_id, 'subscrpt_activity' );
132 }
133 }
134 }
135