@@ -15,256 +15,256 @@ |
||
15 | 15 | class EE_DMS_4_1_0_gateways extends EE_Data_Migration_Script_Stage |
16 | 16 | { |
17 | 17 | |
18 | - private bool $_converted_active_gateways = false; |
|
18 | + private bool $_converted_active_gateways = false; |
|
19 | 19 | |
20 | - protected array $_gateways_we_know_how_to_migrate = [ |
|
21 | - 'aim' => 'Aim', |
|
22 | - 'bank' => 'Bank', |
|
23 | - 'check' => 'Check', |
|
24 | - 'invoice' => 'Invoice', |
|
25 | - 'paypal' => 'Paypal_Standard', |
|
26 | - 'paypal_pro' => 'Paypal_Pro', |
|
20 | + protected array $_gateways_we_know_how_to_migrate = [ |
|
21 | + 'aim' => 'Aim', |
|
22 | + 'bank' => 'Bank', |
|
23 | + 'check' => 'Check', |
|
24 | + 'invoice' => 'Invoice', |
|
25 | + 'paypal' => 'Paypal_Standard', |
|
26 | + 'paypal_pro' => 'Paypal_Pro', |
|
27 | 27 | |
28 | - ]; |
|
28 | + ]; |
|
29 | 29 | |
30 | - protected array $_gateways_we_leave_alone = [ |
|
31 | - '2checkout' => '2checkout', |
|
32 | - 'anz' => 'Anz', |
|
33 | - 'atos' => 'Atos', |
|
34 | - 'authnet' => 'Authnet', |
|
35 | - 'beanstream' => 'Beanstream', |
|
36 | - 'evertec' => 'Evertec', |
|
37 | - 'eway' => 'Eway', |
|
38 | - 'eway_rapid3' => 'Eway_Rapid3', |
|
39 | - 'exact' => 'Exact', |
|
40 | - 'firstdata' => 'Firstdata', |
|
41 | - 'firstdat_e4' => 'Firstdata_E4', |
|
42 | - 'ideal' => 'Ideal', |
|
43 | - 'infusion_payment' => 'InfusionSoft', |
|
44 | - 'luottokunta' => 'Luottokunta', |
|
45 | - 'megasoft' => 'Megasoft', |
|
46 | - 'moneris_hpp' => 'Moneris_HPP', |
|
47 | - 'mwarrior' => 'Mwarrior', |
|
48 | - 'nab' => 'NAB', |
|
49 | - 'paychoice' => 'Paychoice', |
|
50 | - 'paytrace' => 'Paytrace', |
|
51 | - 'psigate' => 'Psigate', |
|
52 | - 'purchase_order' => 'Purchase_Order', |
|
53 | - 'qbms' => 'QBMS', |
|
54 | - 'quickpay' => 'Quickpay', |
|
55 | - 'realauth' => 'Realauth', |
|
56 | - 'securepay_aus' => 'Securepay_Aus', |
|
57 | - 'stripe' => 'Stripe', |
|
58 | - 'usaepay_offsite' => 'USAePay_Offsite', |
|
59 | - 'usaepay_onsite' => 'USAePay_Onsite', |
|
60 | - 'wepay' => 'Wepay', |
|
61 | - 'worldpay' => 'Worldpay', |
|
62 | - ]; |
|
30 | + protected array $_gateways_we_leave_alone = [ |
|
31 | + '2checkout' => '2checkout', |
|
32 | + 'anz' => 'Anz', |
|
33 | + 'atos' => 'Atos', |
|
34 | + 'authnet' => 'Authnet', |
|
35 | + 'beanstream' => 'Beanstream', |
|
36 | + 'evertec' => 'Evertec', |
|
37 | + 'eway' => 'Eway', |
|
38 | + 'eway_rapid3' => 'Eway_Rapid3', |
|
39 | + 'exact' => 'Exact', |
|
40 | + 'firstdata' => 'Firstdata', |
|
41 | + 'firstdat_e4' => 'Firstdata_E4', |
|
42 | + 'ideal' => 'Ideal', |
|
43 | + 'infusion_payment' => 'InfusionSoft', |
|
44 | + 'luottokunta' => 'Luottokunta', |
|
45 | + 'megasoft' => 'Megasoft', |
|
46 | + 'moneris_hpp' => 'Moneris_HPP', |
|
47 | + 'mwarrior' => 'Mwarrior', |
|
48 | + 'nab' => 'NAB', |
|
49 | + 'paychoice' => 'Paychoice', |
|
50 | + 'paytrace' => 'Paytrace', |
|
51 | + 'psigate' => 'Psigate', |
|
52 | + 'purchase_order' => 'Purchase_Order', |
|
53 | + 'qbms' => 'QBMS', |
|
54 | + 'quickpay' => 'Quickpay', |
|
55 | + 'realauth' => 'Realauth', |
|
56 | + 'securepay_aus' => 'Securepay_Aus', |
|
57 | + 'stripe' => 'Stripe', |
|
58 | + 'usaepay_offsite' => 'USAePay_Offsite', |
|
59 | + 'usaepay_onsite' => 'USAePay_Onsite', |
|
60 | + 'wepay' => 'Wepay', |
|
61 | + 'worldpay' => 'Worldpay', |
|
62 | + ]; |
|
63 | 63 | |
64 | 64 | |
65 | - public function __construct() |
|
66 | - { |
|
67 | - $this->_pretty_name = esc_html__("Gateways", "event_espresso"); |
|
68 | - parent::__construct(); |
|
69 | - } |
|
65 | + public function __construct() |
|
66 | + { |
|
67 | + $this->_pretty_name = esc_html__("Gateways", "event_espresso"); |
|
68 | + parent::__construct(); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - public function _migration_step($num_items_to_migrate = 50) |
|
73 | - { |
|
74 | - // loads existing EE_Config from DB, if it exists |
|
75 | - $new_gateway_config_obj = EE_Config::instance()->gateway; |
|
76 | - $items_actually_migrated = 0; |
|
77 | - // convert settings |
|
78 | - $gateways_to_deal_with = array_merge( |
|
79 | - $this->_gateways_we_know_how_to_migrate, |
|
80 | - $this->_gateways_we_leave_alone |
|
81 | - ); |
|
82 | - // just do a part of them on this request |
|
83 | - $gateways_to_deal_with = array_slice( |
|
84 | - $gateways_to_deal_with, |
|
85 | - $this->count_records_migrated(), |
|
86 | - $num_items_to_migrate |
|
87 | - );// $this->_gateways_we_know_how_to_migrate; |
|
88 | - foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) { |
|
89 | - $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
|
90 | - if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
91 | - // determine the old option's name |
|
92 | - $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug); |
|
93 | - if (! $old_gateway_settings) { |
|
94 | - // no settings existed for this gateway anyways... weird... |
|
95 | - $items_actually_migrated++; |
|
96 | - continue; |
|
97 | - } |
|
98 | - // now prepare the settings to make sure they're in the 4.1 format |
|
99 | - $new_gateway_settings = $this->_convert_gateway_settings( |
|
100 | - (array) $old_gateway_settings, |
|
101 | - $new_gateway_slug |
|
102 | - ); |
|
72 | + public function _migration_step($num_items_to_migrate = 50) |
|
73 | + { |
|
74 | + // loads existing EE_Config from DB, if it exists |
|
75 | + $new_gateway_config_obj = EE_Config::instance()->gateway; |
|
76 | + $items_actually_migrated = 0; |
|
77 | + // convert settings |
|
78 | + $gateways_to_deal_with = array_merge( |
|
79 | + $this->_gateways_we_know_how_to_migrate, |
|
80 | + $this->_gateways_we_leave_alone |
|
81 | + ); |
|
82 | + // just do a part of them on this request |
|
83 | + $gateways_to_deal_with = array_slice( |
|
84 | + $gateways_to_deal_with, |
|
85 | + $this->count_records_migrated(), |
|
86 | + $num_items_to_migrate |
|
87 | + );// $this->_gateways_we_know_how_to_migrate; |
|
88 | + foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) { |
|
89 | + $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
|
90 | + if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
91 | + // determine the old option's name |
|
92 | + $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug); |
|
93 | + if (! $old_gateway_settings) { |
|
94 | + // no settings existed for this gateway anyways... weird... |
|
95 | + $items_actually_migrated++; |
|
96 | + continue; |
|
97 | + } |
|
98 | + // now prepare the settings to make sure they're in the 4.1 format |
|
99 | + $new_gateway_settings = $this->_convert_gateway_settings( |
|
100 | + (array) $old_gateway_settings, |
|
101 | + $new_gateway_slug |
|
102 | + ); |
|
103 | 103 | |
104 | - $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings; |
|
105 | - // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but |
|
106 | - // I think it's ok to do right away this time (we wont need gateway settings elsewhere) |
|
107 | - delete_option($old_gateway_wp_option_name); |
|
108 | - } else {// it must be one of the ones we mostly leave alone |
|
109 | - global $wpdb; |
|
110 | - // yeah we could do this all in one query... and if you're reading this and would like to, go ahead. Although you'll |
|
111 | - // only be saving users 50 milliseconds the one time this runs... |
|
112 | - $wpdb->query( |
|
113 | - $wpdb->prepare( |
|
114 | - "UPDATE " . $wpdb->options . " SET autoload='no' WHERE option_name=%s", |
|
115 | - $old_gateway_wp_option_name |
|
116 | - ) |
|
117 | - ); |
|
118 | - } |
|
104 | + $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings; |
|
105 | + // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but |
|
106 | + // I think it's ok to do right away this time (we wont need gateway settings elsewhere) |
|
107 | + delete_option($old_gateway_wp_option_name); |
|
108 | + } else {// it must be one of the ones we mostly leave alone |
|
109 | + global $wpdb; |
|
110 | + // yeah we could do this all in one query... and if you're reading this and would like to, go ahead. Although you'll |
|
111 | + // only be saving users 50 milliseconds the one time this runs... |
|
112 | + $wpdb->query( |
|
113 | + $wpdb->prepare( |
|
114 | + "UPDATE " . $wpdb->options . " SET autoload='no' WHERE option_name=%s", |
|
115 | + $old_gateway_wp_option_name |
|
116 | + ) |
|
117 | + ); |
|
118 | + } |
|
119 | 119 | |
120 | - $items_actually_migrated++; |
|
121 | - } |
|
122 | - // if we can keep going, and it hasn't been done yet, convert active gateways |
|
123 | - if ($items_actually_migrated < $num_items_to_migrate && ! $this->_converted_active_gateways) { |
|
124 | - $this->_convert_active_gateways(); |
|
125 | - $this->_converted_active_gateways = true; |
|
126 | - $items_actually_migrated++; |
|
127 | - } |
|
120 | + $items_actually_migrated++; |
|
121 | + } |
|
122 | + // if we can keep going, and it hasn't been done yet, convert active gateways |
|
123 | + if ($items_actually_migrated < $num_items_to_migrate && ! $this->_converted_active_gateways) { |
|
124 | + $this->_convert_active_gateways(); |
|
125 | + $this->_converted_active_gateways = true; |
|
126 | + $items_actually_migrated++; |
|
127 | + } |
|
128 | 128 | |
129 | - EE_Config::instance()->update_espresso_config(false, false); |
|
130 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
131 | - $this->set_completed(); |
|
132 | - } |
|
133 | - return $items_actually_migrated; |
|
134 | - } |
|
129 | + EE_Config::instance()->update_espresso_config(false, false); |
|
130 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
131 | + $this->set_completed(); |
|
132 | + } |
|
133 | + return $items_actually_migrated; |
|
134 | + } |
|
135 | 135 | |
136 | 136 | |
137 | - public function _count_records_to_migrate(): int |
|
138 | - { |
|
139 | - $count_of_gateways_to_convert = (int) count($this->_gateways_we_know_how_to_migrate); |
|
140 | - $step_of_setting_active_gateways = 1; |
|
141 | - $count_of_gateways_to_leave_alone = (int) count($this->_gateways_we_leave_alone); |
|
142 | - // $button_images_to_update = |
|
143 | - return $count_of_gateways_to_convert + $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone; |
|
144 | - } |
|
137 | + public function _count_records_to_migrate(): int |
|
138 | + { |
|
139 | + $count_of_gateways_to_convert = (int) count($this->_gateways_we_know_how_to_migrate); |
|
140 | + $step_of_setting_active_gateways = 1; |
|
141 | + $count_of_gateways_to_leave_alone = (int) count($this->_gateways_we_leave_alone); |
|
142 | + // $button_images_to_update = |
|
143 | + return $count_of_gateways_to_convert + $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone; |
|
144 | + } |
|
145 | 145 | |
146 | 146 | |
147 | - /** |
|
148 | - * Takes the old array of 3.1 gateway settings for this gateway and converts it |
|
149 | - * into an array with all the 4.1 gateway setting array keys (often the keys were |
|
150 | - * changed from 3.1 to 4.1) |
|
151 | - * |
|
152 | - * @param array $old_gateway_settings |
|
153 | - * @param string $new_gateway_slug |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - private function _convert_gateway_settings(array $old_gateway_settings, string $new_gateway_slug): array |
|
157 | - { |
|
158 | - $new_gateway_settings = $old_gateway_settings; |
|
159 | - switch ($new_gateway_slug) { |
|
160 | - case 'Bank': |
|
161 | - $new_gateway_settings['account_number'] = $old_gateway_settings['bank_account']; |
|
162 | - $new_gateway_settings['page_title'] = $old_gateway_settings['bank_title']; |
|
163 | - break; |
|
164 | - case 'Invoice': |
|
165 | - $new_gateway_settings['invoice_logo_url'] = $old_gateway_settings['image_url']; |
|
166 | - // Dont' migrate the old invoice payee address. It was usually given dummy data. And in EE4 |
|
167 | - // it gets used in the receipts which are available to everyone. So usually it's best to not |
|
168 | - // migrate this. |
|
169 | - unset($new_gateway_settings['payment_address']); |
|
170 | - break; |
|
171 | - case 'Paypal_Pro': |
|
172 | - $new_gateway_settings['email'] = $old_gateway_settings['paypal_pro_email']; |
|
173 | - $new_gateway_settings['username'] = $old_gateway_settings['paypal_api_username']; |
|
174 | - $new_gateway_settings['password'] = $old_gateway_settings['paypal_api_password']; |
|
175 | - $new_gateway_settings['signature'] = $old_gateway_settings['paypal_api_signature']; |
|
176 | - $new_gateway_settings['credit_cards'] = explode(",", $old_gateway_settings['paypal_api_credit_cards']); |
|
177 | - $new_gateway_settings['use_sandbox'] = $old_gateway_settings['paypal_pro_use_sandbox']; |
|
178 | - break; |
|
179 | - } |
|
180 | - return $new_gateway_settings; |
|
181 | - } |
|
147 | + /** |
|
148 | + * Takes the old array of 3.1 gateway settings for this gateway and converts it |
|
149 | + * into an array with all the 4.1 gateway setting array keys (often the keys were |
|
150 | + * changed from 3.1 to 4.1) |
|
151 | + * |
|
152 | + * @param array $old_gateway_settings |
|
153 | + * @param string $new_gateway_slug |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + private function _convert_gateway_settings(array $old_gateway_settings, string $new_gateway_slug): array |
|
157 | + { |
|
158 | + $new_gateway_settings = $old_gateway_settings; |
|
159 | + switch ($new_gateway_slug) { |
|
160 | + case 'Bank': |
|
161 | + $new_gateway_settings['account_number'] = $old_gateway_settings['bank_account']; |
|
162 | + $new_gateway_settings['page_title'] = $old_gateway_settings['bank_title']; |
|
163 | + break; |
|
164 | + case 'Invoice': |
|
165 | + $new_gateway_settings['invoice_logo_url'] = $old_gateway_settings['image_url']; |
|
166 | + // Dont' migrate the old invoice payee address. It was usually given dummy data. And in EE4 |
|
167 | + // it gets used in the receipts which are available to everyone. So usually it's best to not |
|
168 | + // migrate this. |
|
169 | + unset($new_gateway_settings['payment_address']); |
|
170 | + break; |
|
171 | + case 'Paypal_Pro': |
|
172 | + $new_gateway_settings['email'] = $old_gateway_settings['paypal_pro_email']; |
|
173 | + $new_gateway_settings['username'] = $old_gateway_settings['paypal_api_username']; |
|
174 | + $new_gateway_settings['password'] = $old_gateway_settings['paypal_api_password']; |
|
175 | + $new_gateway_settings['signature'] = $old_gateway_settings['paypal_api_signature']; |
|
176 | + $new_gateway_settings['credit_cards'] = explode(",", $old_gateway_settings['paypal_api_credit_cards']); |
|
177 | + $new_gateway_settings['use_sandbox'] = $old_gateway_settings['paypal_pro_use_sandbox']; |
|
178 | + break; |
|
179 | + } |
|
180 | + return $new_gateway_settings; |
|
181 | + } |
|
182 | 182 | |
183 | 183 | |
184 | - /** |
|
185 | - * Figures out the correct 3.1 gateway settings option name for the given 4.1 gateway |
|
186 | - * |
|
187 | - * @param string $new_gateway_slug |
|
188 | - * @return string |
|
189 | - */ |
|
190 | - private function _get_old_gateway_option(string $new_gateway_slug): string |
|
191 | - { |
|
192 | - return get_option( |
|
193 | - $this->_get_old_gateway_option_name($new_gateway_slug), |
|
194 | - null |
|
195 | - ); |
|
196 | - } |
|
184 | + /** |
|
185 | + * Figures out the correct 3.1 gateway settings option name for the given 4.1 gateway |
|
186 | + * |
|
187 | + * @param string $new_gateway_slug |
|
188 | + * @return string |
|
189 | + */ |
|
190 | + private function _get_old_gateway_option(string $new_gateway_slug): string |
|
191 | + { |
|
192 | + return get_option( |
|
193 | + $this->_get_old_gateway_option_name($new_gateway_slug), |
|
194 | + null |
|
195 | + ); |
|
196 | + } |
|
197 | 197 | |
198 | 198 | |
199 | - /** |
|
200 | - * Just gets the old gateways slug |
|
201 | - * |
|
202 | - * @param string $new_gateway_slug |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - private function _get_old_gateway_option_name(string $new_gateway_slug): string |
|
206 | - { |
|
207 | - $new_gateway_slugs_to_new = array_flip( |
|
208 | - array_merge( |
|
209 | - $this->_gateways_we_know_how_to_migrate, |
|
210 | - $this->_gateways_we_leave_alone |
|
211 | - ) |
|
212 | - ); |
|
213 | - $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ]; |
|
214 | - $normal_option_prefix = 'event_espresso_'; |
|
215 | - $normal_option_postfix = '_settings'; |
|
216 | - switch ($new_gateway_slug) { |
|
217 | - case 'Bank': |
|
218 | - $option_name = $normal_option_prefix . 'bank_deposit' . $normal_option_postfix; |
|
219 | - break; |
|
220 | - case 'Aim': |
|
221 | - $option_name = $normal_option_prefix . 'authnet_aim' . $normal_option_postfix; |
|
222 | - break; |
|
223 | - case 'Check': |
|
224 | - $option_name = $normal_option_prefix . 'check_payment' . $normal_option_postfix; |
|
225 | - break; |
|
226 | - case 'Ideal': |
|
227 | - $option_name = $normal_option_prefix . 'ideal_mollie' . $normal_option_postfix; |
|
228 | - break; |
|
229 | - case 'Invoice': |
|
230 | - $option_name = $normal_option_prefix . 'invoice_payment' . $normal_option_postfix; |
|
231 | - break; |
|
232 | - case 'Purchase_Order': |
|
233 | - $option_name = $normal_option_prefix . 'purchase_order_payment' . $normal_option_postfix; |
|
234 | - break; |
|
235 | - case 'USAePay_Offsite': |
|
236 | - $option_name = 'espresso_usaepay_offsite' . $normal_option_postfix; |
|
237 | - break; |
|
238 | - case 'USAePay_Onsite': |
|
239 | - $option_name = 'espresso_usaepay_onsite' . $normal_option_postfix; |
|
240 | - break; |
|
241 | - default: |
|
242 | - $option_name = apply_filters( |
|
243 | - 'FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', |
|
244 | - $normal_option_prefix . $old_gateway_slug . $normal_option_postfix |
|
245 | - ); |
|
246 | - } |
|
247 | - return $option_name; |
|
248 | - } |
|
199 | + /** |
|
200 | + * Just gets the old gateways slug |
|
201 | + * |
|
202 | + * @param string $new_gateway_slug |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + private function _get_old_gateway_option_name(string $new_gateway_slug): string |
|
206 | + { |
|
207 | + $new_gateway_slugs_to_new = array_flip( |
|
208 | + array_merge( |
|
209 | + $this->_gateways_we_know_how_to_migrate, |
|
210 | + $this->_gateways_we_leave_alone |
|
211 | + ) |
|
212 | + ); |
|
213 | + $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ]; |
|
214 | + $normal_option_prefix = 'event_espresso_'; |
|
215 | + $normal_option_postfix = '_settings'; |
|
216 | + switch ($new_gateway_slug) { |
|
217 | + case 'Bank': |
|
218 | + $option_name = $normal_option_prefix . 'bank_deposit' . $normal_option_postfix; |
|
219 | + break; |
|
220 | + case 'Aim': |
|
221 | + $option_name = $normal_option_prefix . 'authnet_aim' . $normal_option_postfix; |
|
222 | + break; |
|
223 | + case 'Check': |
|
224 | + $option_name = $normal_option_prefix . 'check_payment' . $normal_option_postfix; |
|
225 | + break; |
|
226 | + case 'Ideal': |
|
227 | + $option_name = $normal_option_prefix . 'ideal_mollie' . $normal_option_postfix; |
|
228 | + break; |
|
229 | + case 'Invoice': |
|
230 | + $option_name = $normal_option_prefix . 'invoice_payment' . $normal_option_postfix; |
|
231 | + break; |
|
232 | + case 'Purchase_Order': |
|
233 | + $option_name = $normal_option_prefix . 'purchase_order_payment' . $normal_option_postfix; |
|
234 | + break; |
|
235 | + case 'USAePay_Offsite': |
|
236 | + $option_name = 'espresso_usaepay_offsite' . $normal_option_postfix; |
|
237 | + break; |
|
238 | + case 'USAePay_Onsite': |
|
239 | + $option_name = 'espresso_usaepay_onsite' . $normal_option_postfix; |
|
240 | + break; |
|
241 | + default: |
|
242 | + $option_name = apply_filters( |
|
243 | + 'FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', |
|
244 | + $normal_option_prefix . $old_gateway_slug . $normal_option_postfix |
|
245 | + ); |
|
246 | + } |
|
247 | + return $option_name; |
|
248 | + } |
|
249 | 249 | |
250 | 250 | |
251 | - private function _convert_active_gateways() |
|
252 | - { |
|
253 | - // just does it all one big swoop |
|
254 | - $old_active_gateways = get_option('event_espresso_active_gateways'); |
|
255 | - $new_active_gateways = EE_Config::instance()->gateway->active_gateways; |
|
256 | - foreach ($old_active_gateways as $old_gateway_slug => $filepath) { |
|
257 | - if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
258 | - $this->add_error( |
|
259 | - sprintf(esc_html__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug) |
|
260 | - ); |
|
261 | - continue; |
|
262 | - } |
|
263 | - $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ]; |
|
251 | + private function _convert_active_gateways() |
|
252 | + { |
|
253 | + // just does it all one big swoop |
|
254 | + $old_active_gateways = get_option('event_espresso_active_gateways'); |
|
255 | + $new_active_gateways = EE_Config::instance()->gateway->active_gateways; |
|
256 | + foreach ($old_active_gateways as $old_gateway_slug => $filepath) { |
|
257 | + if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
258 | + $this->add_error( |
|
259 | + sprintf(esc_html__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug) |
|
260 | + ); |
|
261 | + continue; |
|
262 | + } |
|
263 | + $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ]; |
|
264 | 264 | |
265 | - // in the new format we can also upload gateways to the uploads directory and |
|
266 | - $new_active_gateways[ $new_gateway_slug ] = false; |
|
267 | - } |
|
268 | - EE_Config::instance()->gateway->active_gateways = $new_active_gateways; |
|
269 | - } |
|
265 | + // in the new format we can also upload gateways to the uploads directory and |
|
266 | + $new_active_gateways[ $new_gateway_slug ] = false; |
|
267 | + } |
|
268 | + EE_Config::instance()->gateway->active_gateways = $new_active_gateways; |
|
269 | + } |
|
270 | 270 | } |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | $gateways_to_deal_with, |
85 | 85 | $this->count_records_migrated(), |
86 | 86 | $num_items_to_migrate |
87 | - );// $this->_gateways_we_know_how_to_migrate; |
|
87 | + ); // $this->_gateways_we_know_how_to_migrate; |
|
88 | 88 | foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) { |
89 | 89 | $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
90 | - if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
90 | + if (isset($this->_gateways_we_know_how_to_migrate[$old_gateway_slug])) { |
|
91 | 91 | // determine the old option's name |
92 | 92 | $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug); |
93 | - if (! $old_gateway_settings) { |
|
93 | + if ( ! $old_gateway_settings) { |
|
94 | 94 | // no settings existed for this gateway anyways... weird... |
95 | 95 | $items_actually_migrated++; |
96 | 96 | continue; |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | $new_gateway_slug |
102 | 102 | ); |
103 | 103 | |
104 | - $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings; |
|
104 | + $new_gateway_config_obj->payment_settings[$new_gateway_slug] = $new_gateway_settings; |
|
105 | 105 | // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but |
106 | 106 | // I think it's ok to do right away this time (we wont need gateway settings elsewhere) |
107 | 107 | delete_option($old_gateway_wp_option_name); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | // only be saving users 50 milliseconds the one time this runs... |
112 | 112 | $wpdb->query( |
113 | 113 | $wpdb->prepare( |
114 | - "UPDATE " . $wpdb->options . " SET autoload='no' WHERE option_name=%s", |
|
114 | + "UPDATE ".$wpdb->options." SET autoload='no' WHERE option_name=%s", |
|
115 | 115 | $old_gateway_wp_option_name |
116 | 116 | ) |
117 | 117 | ); |
@@ -210,38 +210,38 @@ discard block |
||
210 | 210 | $this->_gateways_we_leave_alone |
211 | 211 | ) |
212 | 212 | ); |
213 | - $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ]; |
|
213 | + $old_gateway_slug = $new_gateway_slugs_to_new[$new_gateway_slug]; |
|
214 | 214 | $normal_option_prefix = 'event_espresso_'; |
215 | 215 | $normal_option_postfix = '_settings'; |
216 | 216 | switch ($new_gateway_slug) { |
217 | 217 | case 'Bank': |
218 | - $option_name = $normal_option_prefix . 'bank_deposit' . $normal_option_postfix; |
|
218 | + $option_name = $normal_option_prefix.'bank_deposit'.$normal_option_postfix; |
|
219 | 219 | break; |
220 | 220 | case 'Aim': |
221 | - $option_name = $normal_option_prefix . 'authnet_aim' . $normal_option_postfix; |
|
221 | + $option_name = $normal_option_prefix.'authnet_aim'.$normal_option_postfix; |
|
222 | 222 | break; |
223 | 223 | case 'Check': |
224 | - $option_name = $normal_option_prefix . 'check_payment' . $normal_option_postfix; |
|
224 | + $option_name = $normal_option_prefix.'check_payment'.$normal_option_postfix; |
|
225 | 225 | break; |
226 | 226 | case 'Ideal': |
227 | - $option_name = $normal_option_prefix . 'ideal_mollie' . $normal_option_postfix; |
|
227 | + $option_name = $normal_option_prefix.'ideal_mollie'.$normal_option_postfix; |
|
228 | 228 | break; |
229 | 229 | case 'Invoice': |
230 | - $option_name = $normal_option_prefix . 'invoice_payment' . $normal_option_postfix; |
|
230 | + $option_name = $normal_option_prefix.'invoice_payment'.$normal_option_postfix; |
|
231 | 231 | break; |
232 | 232 | case 'Purchase_Order': |
233 | - $option_name = $normal_option_prefix . 'purchase_order_payment' . $normal_option_postfix; |
|
233 | + $option_name = $normal_option_prefix.'purchase_order_payment'.$normal_option_postfix; |
|
234 | 234 | break; |
235 | 235 | case 'USAePay_Offsite': |
236 | - $option_name = 'espresso_usaepay_offsite' . $normal_option_postfix; |
|
236 | + $option_name = 'espresso_usaepay_offsite'.$normal_option_postfix; |
|
237 | 237 | break; |
238 | 238 | case 'USAePay_Onsite': |
239 | - $option_name = 'espresso_usaepay_onsite' . $normal_option_postfix; |
|
239 | + $option_name = 'espresso_usaepay_onsite'.$normal_option_postfix; |
|
240 | 240 | break; |
241 | 241 | default: |
242 | 242 | $option_name = apply_filters( |
243 | 243 | 'FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', |
244 | - $normal_option_prefix . $old_gateway_slug . $normal_option_postfix |
|
244 | + $normal_option_prefix.$old_gateway_slug.$normal_option_postfix |
|
245 | 245 | ); |
246 | 246 | } |
247 | 247 | return $option_name; |
@@ -254,16 +254,16 @@ discard block |
||
254 | 254 | $old_active_gateways = get_option('event_espresso_active_gateways'); |
255 | 255 | $new_active_gateways = EE_Config::instance()->gateway->active_gateways; |
256 | 256 | foreach ($old_active_gateways as $old_gateway_slug => $filepath) { |
257 | - if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
257 | + if ( ! isset($this->_gateways_we_know_how_to_migrate[$old_gateway_slug])) { |
|
258 | 258 | $this->add_error( |
259 | 259 | sprintf(esc_html__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug) |
260 | 260 | ); |
261 | 261 | continue; |
262 | 262 | } |
263 | - $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ]; |
|
263 | + $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[$old_gateway_slug]; |
|
264 | 264 | |
265 | 265 | // in the new format we can also upload gateways to the uploads directory and |
266 | - $new_active_gateways[ $new_gateway_slug ] = false; |
|
266 | + $new_active_gateways[$new_gateway_slug] = false; |
|
267 | 267 | } |
268 | 268 | EE_Config::instance()->gateway->active_gateways = $new_active_gateways; |
269 | 269 | } |
@@ -8,86 +8,86 @@ |
||
8 | 8 | class EE_DMS_4_1_0_category_details extends EE_Data_Migration_Script_Stage |
9 | 9 | { |
10 | 10 | |
11 | - private string $_new_term_table; |
|
11 | + private string $_new_term_table; |
|
12 | 12 | |
13 | 13 | |
14 | - /** |
|
15 | - * @throws EE_Error |
|
16 | - */ |
|
17 | - public function _migration_step($num_items_to_migrate = 50) |
|
18 | - { |
|
19 | - global $wpdb; |
|
20 | - $start_at_record = $this->count_records_migrated(); |
|
21 | - $rows = |
|
22 | - $wpdb->get_results( |
|
23 | - $wpdb->prepare( |
|
24 | - "SELECT * FROM $this->_old_table LIMIT %d,%d", |
|
25 | - $start_at_record, |
|
26 | - $num_items_to_migrate |
|
27 | - ), |
|
28 | - ARRAY_A |
|
29 | - ); |
|
30 | - $items_actually_migrated = 0; |
|
31 | - foreach ($rows as $category_detail_row) { |
|
32 | - $term_and_taxonomy_ids = wp_insert_term( |
|
33 | - stripslashes($category_detail_row['category_name']), |
|
34 | - 'espresso_event_categories', |
|
35 | - [ |
|
36 | - 'description' => stripslashes($category_detail_row['category_desc']), |
|
37 | - 'slug' => $category_detail_row['category_identifier'], |
|
38 | - ] |
|
39 | - ); |
|
40 | - if ($term_and_taxonomy_ids instanceof WP_Error) { |
|
41 | - $this->add_error( |
|
42 | - sprintf( |
|
43 | - esc_html__( |
|
44 | - "Could not create WP Term_Taxonomy from old category: %s. The Error was: %s", |
|
45 | - "event_espresso" |
|
46 | - ), |
|
47 | - $this->_json_encode($category_detail_row), |
|
48 | - $term_and_taxonomy_ids->get_error_message() |
|
49 | - ) |
|
50 | - ); |
|
51 | - $items_actually_migrated++; |
|
52 | - continue; |
|
53 | - } |
|
54 | - $term_id = $term_and_taxonomy_ids['term_id']; |
|
55 | - $term_taxonomy_id = $term_and_taxonomy_ids['term_taxonomy_id']; |
|
56 | - $this->get_migration_script()->set_mapping( |
|
57 | - $this->_old_table, |
|
58 | - $category_detail_row['id'], |
|
59 | - $this->_new_term_table, |
|
60 | - $term_id |
|
61 | - ); |
|
62 | - $this->get_migration_script()->set_mapping( |
|
63 | - $this->_old_table, |
|
64 | - $category_detail_row['id'], |
|
65 | - $this->_new_table, |
|
66 | - $term_taxonomy_id |
|
67 | - ); |
|
68 | - $items_actually_migrated++; |
|
69 | - } |
|
70 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
71 | - $this->set_completed(); |
|
72 | - } |
|
73 | - return $items_actually_migrated; |
|
74 | - } |
|
14 | + /** |
|
15 | + * @throws EE_Error |
|
16 | + */ |
|
17 | + public function _migration_step($num_items_to_migrate = 50) |
|
18 | + { |
|
19 | + global $wpdb; |
|
20 | + $start_at_record = $this->count_records_migrated(); |
|
21 | + $rows = |
|
22 | + $wpdb->get_results( |
|
23 | + $wpdb->prepare( |
|
24 | + "SELECT * FROM $this->_old_table LIMIT %d,%d", |
|
25 | + $start_at_record, |
|
26 | + $num_items_to_migrate |
|
27 | + ), |
|
28 | + ARRAY_A |
|
29 | + ); |
|
30 | + $items_actually_migrated = 0; |
|
31 | + foreach ($rows as $category_detail_row) { |
|
32 | + $term_and_taxonomy_ids = wp_insert_term( |
|
33 | + stripslashes($category_detail_row['category_name']), |
|
34 | + 'espresso_event_categories', |
|
35 | + [ |
|
36 | + 'description' => stripslashes($category_detail_row['category_desc']), |
|
37 | + 'slug' => $category_detail_row['category_identifier'], |
|
38 | + ] |
|
39 | + ); |
|
40 | + if ($term_and_taxonomy_ids instanceof WP_Error) { |
|
41 | + $this->add_error( |
|
42 | + sprintf( |
|
43 | + esc_html__( |
|
44 | + "Could not create WP Term_Taxonomy from old category: %s. The Error was: %s", |
|
45 | + "event_espresso" |
|
46 | + ), |
|
47 | + $this->_json_encode($category_detail_row), |
|
48 | + $term_and_taxonomy_ids->get_error_message() |
|
49 | + ) |
|
50 | + ); |
|
51 | + $items_actually_migrated++; |
|
52 | + continue; |
|
53 | + } |
|
54 | + $term_id = $term_and_taxonomy_ids['term_id']; |
|
55 | + $term_taxonomy_id = $term_and_taxonomy_ids['term_taxonomy_id']; |
|
56 | + $this->get_migration_script()->set_mapping( |
|
57 | + $this->_old_table, |
|
58 | + $category_detail_row['id'], |
|
59 | + $this->_new_term_table, |
|
60 | + $term_id |
|
61 | + ); |
|
62 | + $this->get_migration_script()->set_mapping( |
|
63 | + $this->_old_table, |
|
64 | + $category_detail_row['id'], |
|
65 | + $this->_new_table, |
|
66 | + $term_taxonomy_id |
|
67 | + ); |
|
68 | + $items_actually_migrated++; |
|
69 | + } |
|
70 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
71 | + $this->set_completed(); |
|
72 | + } |
|
73 | + return $items_actually_migrated; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - public function _count_records_to_migrate() |
|
78 | - { |
|
79 | - global $wpdb; |
|
80 | - return $wpdb->get_var("SELECT COUNT(id) FROM $this->_old_table"); |
|
81 | - } |
|
77 | + public function _count_records_to_migrate() |
|
78 | + { |
|
79 | + global $wpdb; |
|
80 | + return $wpdb->get_var("SELECT COUNT(id) FROM $this->_old_table"); |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - public function __construct() |
|
85 | - { |
|
86 | - $this->_pretty_name = esc_html__("Category Details", "event_espresso"); |
|
87 | - global $wpdb; |
|
88 | - $this->_old_table = $wpdb->prefix . "events_category_detail"; |
|
89 | - $this->_new_table = $wpdb->prefix . "term_taxonomy"; |
|
90 | - $this->_new_term_table = $wpdb->prefix . "terms"; |
|
91 | - parent::__construct(); |
|
92 | - } |
|
84 | + public function __construct() |
|
85 | + { |
|
86 | + $this->_pretty_name = esc_html__("Category Details", "event_espresso"); |
|
87 | + global $wpdb; |
|
88 | + $this->_old_table = $wpdb->prefix . "events_category_detail"; |
|
89 | + $this->_new_table = $wpdb->prefix . "term_taxonomy"; |
|
90 | + $this->_new_term_table = $wpdb->prefix . "terms"; |
|
91 | + parent::__construct(); |
|
92 | + } |
|
93 | 93 | } |
@@ -85,9 +85,9 @@ |
||
85 | 85 | { |
86 | 86 | $this->_pretty_name = esc_html__("Category Details", "event_espresso"); |
87 | 87 | global $wpdb; |
88 | - $this->_old_table = $wpdb->prefix . "events_category_detail"; |
|
89 | - $this->_new_table = $wpdb->prefix . "term_taxonomy"; |
|
90 | - $this->_new_term_table = $wpdb->prefix . "terms"; |
|
88 | + $this->_old_table = $wpdb->prefix."events_category_detail"; |
|
89 | + $this->_new_table = $wpdb->prefix."term_taxonomy"; |
|
90 | + $this->_new_term_table = $wpdb->prefix."terms"; |
|
91 | 91 | parent::__construct(); |
92 | 92 | } |
93 | 93 | } |
@@ -45,251 +45,251 @@ |
||
45 | 45 | class EE_DMS_4_1_0_line_items extends EE_Data_Migration_Script_Stage_Table |
46 | 46 | { |
47 | 47 | |
48 | - private string $_new_line_table; |
|
48 | + private string $_new_line_table; |
|
49 | 49 | |
50 | - private string $_new_transaction_table; |
|
50 | + private string $_new_transaction_table; |
|
51 | 51 | |
52 | - private string $_new_reg_table; |
|
52 | + private string $_new_reg_table; |
|
53 | 53 | |
54 | 54 | |
55 | - public function __construct() |
|
56 | - { |
|
57 | - global $wpdb; |
|
58 | - $this->_pretty_name = esc_html__("Line Items", "event_espresso"); |
|
59 | - $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
60 | - $this->select_expression = 'att.*, e.event_status'; |
|
61 | - $this->_extra_where_sql = ' AS att |
|
55 | + public function __construct() |
|
56 | + { |
|
57 | + global $wpdb; |
|
58 | + $this->_pretty_name = esc_html__("Line Items", "event_espresso"); |
|
59 | + $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
60 | + $this->select_expression = 'att.*, e.event_status'; |
|
61 | + $this->_extra_where_sql = ' AS att |
|
62 | 62 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
63 | 63 | WHERE e.event_status!="D"'; |
64 | - $this->_new_transaction_table = $wpdb->prefix . "esp_transaction"; |
|
65 | - $this->_new_line_table = $wpdb->prefix . "esp_line_item"; |
|
66 | - $this->_new_reg_table = $wpdb->prefix . "esp_registration"; |
|
67 | - parent::__construct(); |
|
68 | - } |
|
64 | + $this->_new_transaction_table = $wpdb->prefix . "esp_transaction"; |
|
65 | + $this->_new_line_table = $wpdb->prefix . "esp_line_item"; |
|
66 | + $this->_new_reg_table = $wpdb->prefix . "esp_registration"; |
|
67 | + parent::__construct(); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * @throws EE_Error |
|
73 | - */ |
|
74 | - protected function _migrate_old_row($old_row) |
|
75 | - { |
|
76 | - // insert line items if its a primary id |
|
77 | - if ((int) $old_row['is_primary']) { |
|
78 | - $txn_id = (int) $this->get_migration_script()->get_mapping_new_pk( |
|
79 | - $this->_old_table, |
|
80 | - $old_row['id'], |
|
81 | - $this->_new_transaction_table |
|
82 | - ); |
|
83 | - if (! $txn_id) { |
|
84 | - $this->add_error( |
|
85 | - sprintf( |
|
86 | - esc_html__( |
|
87 | - "Could not find the transaction for the 3.1 attendee %d from row %s", |
|
88 | - "event_espresso" |
|
89 | - ), |
|
90 | - $old_row['id'], |
|
91 | - $this->_json_encode($old_row) |
|
92 | - ) |
|
93 | - ); |
|
94 | - return; |
|
95 | - } |
|
96 | - $txn = $this->_get_txn($txn_id); |
|
97 | - $new_line_items = $this->_insert_new_line_items($txn, $old_row); |
|
98 | - $this->get_migration_script()->set_mapping( |
|
99 | - $this->_old_table, |
|
100 | - $old_row['id'], |
|
101 | - $this->_new_line_table, |
|
102 | - $new_line_items |
|
103 | - ); |
|
104 | - } |
|
105 | - } |
|
71 | + /** |
|
72 | + * @throws EE_Error |
|
73 | + */ |
|
74 | + protected function _migrate_old_row($old_row) |
|
75 | + { |
|
76 | + // insert line items if its a primary id |
|
77 | + if ((int) $old_row['is_primary']) { |
|
78 | + $txn_id = (int) $this->get_migration_script()->get_mapping_new_pk( |
|
79 | + $this->_old_table, |
|
80 | + $old_row['id'], |
|
81 | + $this->_new_transaction_table |
|
82 | + ); |
|
83 | + if (! $txn_id) { |
|
84 | + $this->add_error( |
|
85 | + sprintf( |
|
86 | + esc_html__( |
|
87 | + "Could not find the transaction for the 3.1 attendee %d from row %s", |
|
88 | + "event_espresso" |
|
89 | + ), |
|
90 | + $old_row['id'], |
|
91 | + $this->_json_encode($old_row) |
|
92 | + ) |
|
93 | + ); |
|
94 | + return; |
|
95 | + } |
|
96 | + $txn = $this->_get_txn($txn_id); |
|
97 | + $new_line_items = $this->_insert_new_line_items($txn, $old_row); |
|
98 | + $this->get_migration_script()->set_mapping( |
|
99 | + $this->_old_table, |
|
100 | + $old_row['id'], |
|
101 | + $this->_new_line_table, |
|
102 | + $new_line_items |
|
103 | + ); |
|
104 | + } |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | - private function _get_txn(int $txn_id) |
|
109 | - { |
|
110 | - global $wpdb; |
|
111 | - return $wpdb->get_row( |
|
112 | - $wpdb->prepare( |
|
113 | - "SELECT * FROM $this->_new_transaction_table WHERE TXN_ID=%d", |
|
114 | - $txn_id |
|
115 | - ), |
|
116 | - ARRAY_A |
|
117 | - ); |
|
118 | - } |
|
108 | + private function _get_txn(int $txn_id) |
|
109 | + { |
|
110 | + global $wpdb; |
|
111 | + return $wpdb->get_row( |
|
112 | + $wpdb->prepare( |
|
113 | + "SELECT * FROM $this->_new_transaction_table WHERE TXN_ID=%d", |
|
114 | + $txn_id |
|
115 | + ), |
|
116 | + ARRAY_A |
|
117 | + ); |
|
118 | + } |
|
119 | 119 | |
120 | 120 | |
121 | - /** |
|
122 | - * In 4.1, we'd normally need more info than just the registrations to make the line items. Ie, we'd need |
|
123 | - * the transaction, and tax prices at the time of registration. (And probably promotions and other price factors). |
|
124 | - * But seeing how these are REGs created from 3.1 attendee data, which have |
|
125 | - * |
|
126 | - * @param array $transaction |
|
127 | - * @param array $old_attendee |
|
128 | - * @return array new line item ids |
|
129 | - */ |
|
130 | - private function _insert_new_line_items(array $transaction, array $old_attendee): array |
|
131 | - { |
|
132 | - global $wpdb; |
|
133 | - $regs_on_this_transaction = $wpdb->get_results( |
|
134 | - $wpdb->prepare( |
|
135 | - "SELECT * FROM $this->_new_reg_table WHERE TXN_ID=%d", |
|
136 | - $transaction['TXN_ID'] |
|
137 | - ), |
|
138 | - ARRAY_A |
|
139 | - ); |
|
140 | - $new_line_item_ids = []; |
|
141 | - // create a total ine item |
|
142 | - $total_line_item_id = $this->_insert_new_line_item( |
|
143 | - [ |
|
144 | - 'LIN_code' => 'total', |
|
145 | - 'TXN_ID' => $transaction['TXN_ID'], |
|
146 | - 'LIN_name' => esc_html__( |
|
147 | - "Total", |
|
148 | - "event_espresso" |
|
149 | - ), |
|
150 | - 'LIN_total' => $transaction['TXN_total'], |
|
151 | - 'LIN_type' => 'total', |
|
152 | - 'OBJ_ID' => $transaction['TXN_ID'], |
|
153 | - 'OBJ_type' => 'Transaction', |
|
154 | - ], |
|
155 | - $old_attendee |
|
156 | - ); |
|
157 | - $new_line_item_ids[] = $total_line_item_id; |
|
158 | - // create a subtotal line item |
|
159 | - $reg_total = 0; |
|
160 | - foreach ($regs_on_this_transaction as $new_reg) { |
|
161 | - $reg_total += floatval($new_reg['REG_final_price']); |
|
162 | - } |
|
163 | - $subtotal_line_item_id = $this->_insert_new_line_item( |
|
164 | - [ |
|
165 | - 'LIN_code' => 'sub-total', |
|
166 | - 'TXN_ID' => $transaction['TXN_ID'], |
|
167 | - 'LIN_name' => esc_html__( |
|
168 | - "Subtotal", |
|
169 | - "event_espresso" |
|
170 | - ), |
|
171 | - 'LIN_total' => $reg_total, |
|
172 | - 'LIN_parent' => $total_line_item_id, |
|
173 | - 'LIN_type' => 'sub-total', |
|
174 | - ], |
|
175 | - $old_attendee |
|
176 | - ); |
|
177 | - $new_line_item_ids[] = $subtotal_line_item_id; |
|
178 | - // group REGs by TKT_ID |
|
179 | - $regs_by_tkt = []; |
|
180 | - foreach ($regs_on_this_transaction as $new_reg) { |
|
181 | - $regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg; |
|
182 | - } |
|
121 | + /** |
|
122 | + * In 4.1, we'd normally need more info than just the registrations to make the line items. Ie, we'd need |
|
123 | + * the transaction, and tax prices at the time of registration. (And probably promotions and other price factors). |
|
124 | + * But seeing how these are REGs created from 3.1 attendee data, which have |
|
125 | + * |
|
126 | + * @param array $transaction |
|
127 | + * @param array $old_attendee |
|
128 | + * @return array new line item ids |
|
129 | + */ |
|
130 | + private function _insert_new_line_items(array $transaction, array $old_attendee): array |
|
131 | + { |
|
132 | + global $wpdb; |
|
133 | + $regs_on_this_transaction = $wpdb->get_results( |
|
134 | + $wpdb->prepare( |
|
135 | + "SELECT * FROM $this->_new_reg_table WHERE TXN_ID=%d", |
|
136 | + $transaction['TXN_ID'] |
|
137 | + ), |
|
138 | + ARRAY_A |
|
139 | + ); |
|
140 | + $new_line_item_ids = []; |
|
141 | + // create a total ine item |
|
142 | + $total_line_item_id = $this->_insert_new_line_item( |
|
143 | + [ |
|
144 | + 'LIN_code' => 'total', |
|
145 | + 'TXN_ID' => $transaction['TXN_ID'], |
|
146 | + 'LIN_name' => esc_html__( |
|
147 | + "Total", |
|
148 | + "event_espresso" |
|
149 | + ), |
|
150 | + 'LIN_total' => $transaction['TXN_total'], |
|
151 | + 'LIN_type' => 'total', |
|
152 | + 'OBJ_ID' => $transaction['TXN_ID'], |
|
153 | + 'OBJ_type' => 'Transaction', |
|
154 | + ], |
|
155 | + $old_attendee |
|
156 | + ); |
|
157 | + $new_line_item_ids[] = $total_line_item_id; |
|
158 | + // create a subtotal line item |
|
159 | + $reg_total = 0; |
|
160 | + foreach ($regs_on_this_transaction as $new_reg) { |
|
161 | + $reg_total += floatval($new_reg['REG_final_price']); |
|
162 | + } |
|
163 | + $subtotal_line_item_id = $this->_insert_new_line_item( |
|
164 | + [ |
|
165 | + 'LIN_code' => 'sub-total', |
|
166 | + 'TXN_ID' => $transaction['TXN_ID'], |
|
167 | + 'LIN_name' => esc_html__( |
|
168 | + "Subtotal", |
|
169 | + "event_espresso" |
|
170 | + ), |
|
171 | + 'LIN_total' => $reg_total, |
|
172 | + 'LIN_parent' => $total_line_item_id, |
|
173 | + 'LIN_type' => 'sub-total', |
|
174 | + ], |
|
175 | + $old_attendee |
|
176 | + ); |
|
177 | + $new_line_item_ids[] = $subtotal_line_item_id; |
|
178 | + // group REGs by TKT_ID |
|
179 | + $regs_by_tkt = []; |
|
180 | + foreach ($regs_on_this_transaction as $new_reg) { |
|
181 | + $regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg; |
|
182 | + } |
|
183 | 183 | |
184 | - // create individual line items |
|
184 | + // create individual line items |
|
185 | 185 | |
186 | - foreach ($regs_by_tkt as $ticket_id => $regs) { |
|
187 | - $count = count($regs); |
|
188 | - $line_total = 0; |
|
189 | - foreach ($regs as $new_reg) { |
|
190 | - $line_total += $new_reg['REG_final_price']; |
|
191 | - } |
|
192 | - $a_reg = reset($regs); |
|
193 | - $new_ticket = $this->_get_new_ticket_row($a_reg['TKT_ID']); |
|
194 | - $reg_line_item_id = $this->_insert_new_line_item( |
|
195 | - [ |
|
196 | - 'LIN_code' => md5( |
|
197 | - 'Ticket' . $ticket_id . time() |
|
198 | - ), |
|
199 | - 'TXN_ID' => $transaction['TXN_ID'], |
|
200 | - 'LIN_name' => $new_ticket['TKT_name'], |
|
201 | - 'LIN_unit_price' => $a_reg['REG_final_price'], |
|
202 | - 'LIN_is_taxable' => false, |
|
203 | - 'LIN_total' => $line_total, |
|
204 | - 'LIN_quantity' => $count, |
|
205 | - 'LIN_parent' => $subtotal_line_item_id, |
|
206 | - 'OBJ_ID' => $ticket_id, |
|
207 | - 'OBJ_type' => 'Ticket', |
|
208 | - ], |
|
209 | - $old_attendee |
|
210 | - ); |
|
211 | - $new_line_item_ids[] = $reg_line_item_id; |
|
212 | - } |
|
186 | + foreach ($regs_by_tkt as $ticket_id => $regs) { |
|
187 | + $count = count($regs); |
|
188 | + $line_total = 0; |
|
189 | + foreach ($regs as $new_reg) { |
|
190 | + $line_total += $new_reg['REG_final_price']; |
|
191 | + } |
|
192 | + $a_reg = reset($regs); |
|
193 | + $new_ticket = $this->_get_new_ticket_row($a_reg['TKT_ID']); |
|
194 | + $reg_line_item_id = $this->_insert_new_line_item( |
|
195 | + [ |
|
196 | + 'LIN_code' => md5( |
|
197 | + 'Ticket' . $ticket_id . time() |
|
198 | + ), |
|
199 | + 'TXN_ID' => $transaction['TXN_ID'], |
|
200 | + 'LIN_name' => $new_ticket['TKT_name'], |
|
201 | + 'LIN_unit_price' => $a_reg['REG_final_price'], |
|
202 | + 'LIN_is_taxable' => false, |
|
203 | + 'LIN_total' => $line_total, |
|
204 | + 'LIN_quantity' => $count, |
|
205 | + 'LIN_parent' => $subtotal_line_item_id, |
|
206 | + 'OBJ_ID' => $ticket_id, |
|
207 | + 'OBJ_type' => 'Ticket', |
|
208 | + ], |
|
209 | + $old_attendee |
|
210 | + ); |
|
211 | + $new_line_item_ids[] = $reg_line_item_id; |
|
212 | + } |
|
213 | 213 | |
214 | 214 | |
215 | - return $new_line_item_ids; |
|
216 | - } |
|
215 | + return $new_line_item_ids; |
|
216 | + } |
|
217 | 217 | |
218 | 218 | |
219 | - /** |
|
220 | - * Gets the full ticket by ID |
|
221 | - * |
|
222 | - * @param int $new_ticket_id |
|
223 | - * @return array |
|
224 | - * @global wpdb $wpdb |
|
225 | - */ |
|
226 | - private function _get_new_ticket_row(int $new_ticket_id): array |
|
227 | - { |
|
228 | - global $wpdb; |
|
229 | - return $wpdb->get_row( |
|
230 | - $wpdb->prepare( |
|
231 | - "SELECT * FROM {$wpdb->prefix}esp_ticket WHERE TKT_ID=%d", |
|
232 | - $new_ticket_id |
|
233 | - ), |
|
234 | - ARRAY_A |
|
235 | - ); |
|
236 | - } |
|
219 | + /** |
|
220 | + * Gets the full ticket by ID |
|
221 | + * |
|
222 | + * @param int $new_ticket_id |
|
223 | + * @return array |
|
224 | + * @global wpdb $wpdb |
|
225 | + */ |
|
226 | + private function _get_new_ticket_row(int $new_ticket_id): array |
|
227 | + { |
|
228 | + global $wpdb; |
|
229 | + return $wpdb->get_row( |
|
230 | + $wpdb->prepare( |
|
231 | + "SELECT * FROM {$wpdb->prefix}esp_ticket WHERE TKT_ID=%d", |
|
232 | + $new_ticket_id |
|
233 | + ), |
|
234 | + ARRAY_A |
|
235 | + ); |
|
236 | + } |
|
237 | 237 | |
238 | 238 | |
239 | - private function _insert_new_line_item(array $cols_n_values, array $old_attendee): int |
|
240 | - { |
|
241 | - global $wpdb; |
|
242 | - $default_cols_n_values = [ |
|
243 | - 'LIN_code' => '', |
|
244 | - 'TXN_ID' => 0, |
|
245 | - 'LIN_name' => '', |
|
246 | - 'LIN_desc' => '', |
|
247 | - 'LIN_unit_price' => 0, |
|
248 | - 'LIN_percent' => 0, |
|
249 | - 'LIN_is_taxable' => false, |
|
250 | - 'LIN_order' => 0, |
|
251 | - 'LIN_total' => 0, |
|
252 | - 'LIN_quantity' => null, |
|
253 | - 'LIN_parent' => 0, |
|
254 | - 'LIN_type' => 'line-item', |
|
255 | - 'OBJ_ID' => null, |
|
256 | - 'OBJ_type' => null, |
|
257 | - ]; |
|
258 | - $cols_n_values = array_merge($default_cols_n_values, $cols_n_values); |
|
259 | - $data_types = [ |
|
260 | - '%s',// LIN_code |
|
261 | - '%d',// TXN_ID |
|
262 | - '%s',// LIN_name |
|
263 | - '%s',// LIN_desc |
|
264 | - '%f',// LIN_unit_price |
|
265 | - '%f',// LIN_percent |
|
266 | - '%d',// LIN_is_taxable |
|
267 | - '%d',// LIN_order |
|
268 | - '%f',// LIN_total |
|
269 | - '%d',// LIN_quantity |
|
270 | - '%d',// LIN_parent |
|
271 | - '%s',// LIN_type |
|
272 | - '%d',// OBJ_ID |
|
273 | - '%s',// OBJ_type |
|
274 | - ]; |
|
239 | + private function _insert_new_line_item(array $cols_n_values, array $old_attendee): int |
|
240 | + { |
|
241 | + global $wpdb; |
|
242 | + $default_cols_n_values = [ |
|
243 | + 'LIN_code' => '', |
|
244 | + 'TXN_ID' => 0, |
|
245 | + 'LIN_name' => '', |
|
246 | + 'LIN_desc' => '', |
|
247 | + 'LIN_unit_price' => 0, |
|
248 | + 'LIN_percent' => 0, |
|
249 | + 'LIN_is_taxable' => false, |
|
250 | + 'LIN_order' => 0, |
|
251 | + 'LIN_total' => 0, |
|
252 | + 'LIN_quantity' => null, |
|
253 | + 'LIN_parent' => 0, |
|
254 | + 'LIN_type' => 'line-item', |
|
255 | + 'OBJ_ID' => null, |
|
256 | + 'OBJ_type' => null, |
|
257 | + ]; |
|
258 | + $cols_n_values = array_merge($default_cols_n_values, $cols_n_values); |
|
259 | + $data_types = [ |
|
260 | + '%s',// LIN_code |
|
261 | + '%d',// TXN_ID |
|
262 | + '%s',// LIN_name |
|
263 | + '%s',// LIN_desc |
|
264 | + '%f',// LIN_unit_price |
|
265 | + '%f',// LIN_percent |
|
266 | + '%d',// LIN_is_taxable |
|
267 | + '%d',// LIN_order |
|
268 | + '%f',// LIN_total |
|
269 | + '%d',// LIN_quantity |
|
270 | + '%d',// LIN_parent |
|
271 | + '%s',// LIN_type |
|
272 | + '%d',// OBJ_ID |
|
273 | + '%s',// OBJ_type |
|
274 | + ]; |
|
275 | 275 | |
276 | - $success = $wpdb->insert( |
|
277 | - $this->_new_line_table, |
|
278 | - $cols_n_values, |
|
279 | - $data_types |
|
280 | - ); |
|
281 | - if (! $success) { |
|
282 | - $this->add_error( |
|
283 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
284 | - $this->_old_table, |
|
285 | - $old_attendee, |
|
286 | - $this->_new_reg_table, |
|
287 | - $cols_n_values, |
|
288 | - $data_types |
|
289 | - ) |
|
290 | - ); |
|
291 | - return 0; |
|
292 | - } |
|
293 | - return $wpdb->insert_id; |
|
294 | - } |
|
276 | + $success = $wpdb->insert( |
|
277 | + $this->_new_line_table, |
|
278 | + $cols_n_values, |
|
279 | + $data_types |
|
280 | + ); |
|
281 | + if (! $success) { |
|
282 | + $this->add_error( |
|
283 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
284 | + $this->_old_table, |
|
285 | + $old_attendee, |
|
286 | + $this->_new_reg_table, |
|
287 | + $cols_n_values, |
|
288 | + $data_types |
|
289 | + ) |
|
290 | + ); |
|
291 | + return 0; |
|
292 | + } |
|
293 | + return $wpdb->insert_id; |
|
294 | + } |
|
295 | 295 | } |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | { |
57 | 57 | global $wpdb; |
58 | 58 | $this->_pretty_name = esc_html__("Line Items", "event_espresso"); |
59 | - $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
59 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
60 | 60 | $this->select_expression = 'att.*, e.event_status'; |
61 | 61 | $this->_extra_where_sql = ' AS att |
62 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
62 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
63 | 63 | WHERE e.event_status!="D"'; |
64 | - $this->_new_transaction_table = $wpdb->prefix . "esp_transaction"; |
|
65 | - $this->_new_line_table = $wpdb->prefix . "esp_line_item"; |
|
66 | - $this->_new_reg_table = $wpdb->prefix . "esp_registration"; |
|
64 | + $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
|
65 | + $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
|
66 | + $this->_new_reg_table = $wpdb->prefix."esp_registration"; |
|
67 | 67 | parent::__construct(); |
68 | 68 | } |
69 | 69 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $old_row['id'], |
81 | 81 | $this->_new_transaction_table |
82 | 82 | ); |
83 | - if (! $txn_id) { |
|
83 | + if ( ! $txn_id) { |
|
84 | 84 | $this->add_error( |
85 | 85 | sprintf( |
86 | 86 | esc_html__( |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | ), |
138 | 138 | ARRAY_A |
139 | 139 | ); |
140 | - $new_line_item_ids = []; |
|
140 | + $new_line_item_ids = []; |
|
141 | 141 | // create a total ine item |
142 | - $total_line_item_id = $this->_insert_new_line_item( |
|
142 | + $total_line_item_id = $this->_insert_new_line_item( |
|
143 | 143 | [ |
144 | 144 | 'LIN_code' => 'total', |
145 | 145 | 'TXN_ID' => $transaction['TXN_ID'], |
@@ -174,11 +174,11 @@ discard block |
||
174 | 174 | ], |
175 | 175 | $old_attendee |
176 | 176 | ); |
177 | - $new_line_item_ids[] = $subtotal_line_item_id; |
|
177 | + $new_line_item_ids[] = $subtotal_line_item_id; |
|
178 | 178 | // group REGs by TKT_ID |
179 | 179 | $regs_by_tkt = []; |
180 | 180 | foreach ($regs_on_this_transaction as $new_reg) { |
181 | - $regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg; |
|
181 | + $regs_by_tkt[$new_reg['TKT_ID']][] = $new_reg; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | // create individual line items |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $reg_line_item_id = $this->_insert_new_line_item( |
195 | 195 | [ |
196 | 196 | 'LIN_code' => md5( |
197 | - 'Ticket' . $ticket_id . time() |
|
197 | + 'Ticket'.$ticket_id.time() |
|
198 | 198 | ), |
199 | 199 | 'TXN_ID' => $transaction['TXN_ID'], |
200 | 200 | 'LIN_name' => $new_ticket['TKT_name'], |
@@ -257,20 +257,20 @@ discard block |
||
257 | 257 | ]; |
258 | 258 | $cols_n_values = array_merge($default_cols_n_values, $cols_n_values); |
259 | 259 | $data_types = [ |
260 | - '%s',// LIN_code |
|
261 | - '%d',// TXN_ID |
|
262 | - '%s',// LIN_name |
|
263 | - '%s',// LIN_desc |
|
264 | - '%f',// LIN_unit_price |
|
265 | - '%f',// LIN_percent |
|
266 | - '%d',// LIN_is_taxable |
|
267 | - '%d',// LIN_order |
|
268 | - '%f',// LIN_total |
|
269 | - '%d',// LIN_quantity |
|
270 | - '%d',// LIN_parent |
|
271 | - '%s',// LIN_type |
|
272 | - '%d',// OBJ_ID |
|
273 | - '%s',// OBJ_type |
|
260 | + '%s', // LIN_code |
|
261 | + '%d', // TXN_ID |
|
262 | + '%s', // LIN_name |
|
263 | + '%s', // LIN_desc |
|
264 | + '%f', // LIN_unit_price |
|
265 | + '%f', // LIN_percent |
|
266 | + '%d', // LIN_is_taxable |
|
267 | + '%d', // LIN_order |
|
268 | + '%f', // LIN_total |
|
269 | + '%d', // LIN_quantity |
|
270 | + '%d', // LIN_parent |
|
271 | + '%s', // LIN_type |
|
272 | + '%d', // OBJ_ID |
|
273 | + '%s', // OBJ_type |
|
274 | 274 | ]; |
275 | 275 | |
276 | 276 | $success = $wpdb->insert( |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | $cols_n_values, |
279 | 279 | $data_types |
280 | 280 | ); |
281 | - if (! $success) { |
|
281 | + if ( ! $success) { |
|
282 | 282 | $this->add_error( |
283 | 283 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
284 | 284 | $this->_old_table, |
@@ -46,155 +46,155 @@ |
||
46 | 46 | class EE_DMS_4_1_0_question_groups extends EE_Data_Migration_Script_Stage |
47 | 47 | { |
48 | 48 | |
49 | - public function __construct() |
|
50 | - { |
|
51 | - global $wpdb; |
|
52 | - $this->_old_table = $wpdb->prefix . "events_qst_group"; |
|
53 | - $this->_new_table = $wpdb->prefix . "esp_question_group"; |
|
54 | - $this->_pretty_name = esc_html__("Question Groups", "event_espresso"); |
|
55 | - parent::__construct(); |
|
56 | - } |
|
49 | + public function __construct() |
|
50 | + { |
|
51 | + global $wpdb; |
|
52 | + $this->_old_table = $wpdb->prefix . "events_qst_group"; |
|
53 | + $this->_new_table = $wpdb->prefix . "esp_question_group"; |
|
54 | + $this->_pretty_name = esc_html__("Question Groups", "event_espresso"); |
|
55 | + parent::__construct(); |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Keeps track of whether we've already added a system question group, |
|
61 | - * in order to avoid adding more than 1 (basically, in 3.1 this would happen |
|
62 | - * with the Roles & Permissions addon, because each user had their own set of |
|
63 | - * question groups and questions), |
|
64 | - * |
|
65 | - * @var boolean |
|
66 | - */ |
|
67 | - private bool $_already_got_system_question_group_1 = false; |
|
59 | + /** |
|
60 | + * Keeps track of whether we've already added a system question group, |
|
61 | + * in order to avoid adding more than 1 (basically, in 3.1 this would happen |
|
62 | + * with the Roles & Permissions addon, because each user had their own set of |
|
63 | + * question groups and questions), |
|
64 | + * |
|
65 | + * @var boolean |
|
66 | + */ |
|
67 | + private bool $_already_got_system_question_group_1 = false; |
|
68 | 68 | |
69 | 69 | |
70 | - /** |
|
71 | - * @throws EE_Error |
|
72 | - */ |
|
73 | - public function _migration_step($num_items_to_migrate = 50) |
|
74 | - { |
|
75 | - global $wpdb; |
|
76 | - $start_at_record = $this->count_records_migrated(); |
|
77 | - $rows = $wpdb->get_results( |
|
78 | - $wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items_to_migrate), |
|
79 | - ARRAY_A |
|
80 | - ); |
|
81 | - $items_actually_migrated = 0; |
|
82 | - foreach ($rows as $question_group) { |
|
83 | - $new_id = $this->_insert_new_question_group($question_group); |
|
70 | + /** |
|
71 | + * @throws EE_Error |
|
72 | + */ |
|
73 | + public function _migration_step($num_items_to_migrate = 50) |
|
74 | + { |
|
75 | + global $wpdb; |
|
76 | + $start_at_record = $this->count_records_migrated(); |
|
77 | + $rows = $wpdb->get_results( |
|
78 | + $wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items_to_migrate), |
|
79 | + ARRAY_A |
|
80 | + ); |
|
81 | + $items_actually_migrated = 0; |
|
82 | + foreach ($rows as $question_group) { |
|
83 | + $new_id = $this->_insert_new_question_group($question_group); |
|
84 | 84 | |
85 | - $this->get_migration_script()->set_mapping( |
|
86 | - $this->_old_table, |
|
87 | - $question_group['id'], |
|
88 | - $this->_new_table, |
|
89 | - $new_id |
|
90 | - ); |
|
91 | - $items_actually_migrated++; |
|
92 | - } |
|
93 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
94 | - $this->set_completed(); |
|
95 | - } |
|
96 | - return $items_actually_migrated; |
|
97 | - } |
|
85 | + $this->get_migration_script()->set_mapping( |
|
86 | + $this->_old_table, |
|
87 | + $question_group['id'], |
|
88 | + $this->_new_table, |
|
89 | + $new_id |
|
90 | + ); |
|
91 | + $items_actually_migrated++; |
|
92 | + } |
|
93 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
94 | + $this->set_completed(); |
|
95 | + } |
|
96 | + return $items_actually_migrated; |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | - public function _count_records_to_migrate() |
|
101 | - { |
|
102 | - global $wpdb; |
|
103 | - return $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
104 | - } |
|
100 | + public function _count_records_to_migrate() |
|
101 | + { |
|
102 | + global $wpdb; |
|
103 | + return $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
104 | + } |
|
105 | 105 | |
106 | 106 | |
107 | - /** |
|
108 | - * Attempts to insert a new question group in the new format given an old one |
|
109 | - * |
|
110 | - * @param array $old_question_group |
|
111 | - * @return int |
|
112 | - * @global wpdb $wpdb |
|
113 | - */ |
|
114 | - private function _insert_new_question_group(array $old_question_group): int |
|
115 | - { |
|
116 | - global $wpdb; |
|
117 | - // try to guess what the QST_system int should be... |
|
118 | - // finding the Personal info system question group is quite easy. |
|
119 | - // But in 3.1 address info WASN'T a system group, |
|
120 | - // it just existed by default but could be easily removed. |
|
121 | - if ( |
|
122 | - $old_question_group['system_group'] && ! $this->_already_got_system_question_group_1() |
|
123 | - ) { |
|
124 | - $guess_at_system_number = 1; |
|
125 | - } elseif ( |
|
126 | - $old_question_group['id'] == '2' && strpos($old_question_group['group_name'], 'Address') !== false |
|
127 | - ) { |
|
128 | - $guess_at_system_number = 2; |
|
129 | - } else { |
|
130 | - $guess_at_system_number = 0; |
|
131 | - } |
|
132 | - // if the question group wasn't made by the normal admin, |
|
133 | - // we'd like to keep track of who made it |
|
134 | - if ((int) $old_question_group['wp_user'] !== 1) { |
|
135 | - $username = $wpdb->get_var( |
|
136 | - $wpdb->prepare( |
|
137 | - "SELECT user_nicename FROM " . $wpdb->users . " WHERE ID = %d", |
|
138 | - $old_question_group['wp_user'] |
|
139 | - ) |
|
140 | - ); |
|
141 | - $identifier = $old_question_group['group_identifier'] . "-by-" . $username; |
|
142 | - } else { |
|
143 | - $identifier = $old_question_group['group_identifier']; |
|
144 | - } |
|
145 | - $cols_n_values = [ |
|
146 | - 'QSG_name' => stripslashes($old_question_group['group_name']), |
|
147 | - 'QSG_identifier' => $identifier, |
|
148 | - 'QSG_desc' => stripslashes($old_question_group['group_description']), |
|
149 | - 'QSG_order' => $old_question_group['group_order'], |
|
150 | - 'QSG_show_group_name' => $old_question_group['show_group_name'], |
|
151 | - 'QSG_show_group_desc' => $old_question_group['show_group_description'], |
|
152 | - 'QSG_system' => $guess_at_system_number, |
|
153 | - 'QSG_deleted' => false, |
|
154 | - ]; |
|
155 | - $data_types = [ |
|
156 | - '%s',// QSG_name |
|
157 | - '%s',// QSG_identifier |
|
158 | - '%s',// QSG_desc |
|
159 | - '%d',// QSG_order |
|
160 | - '%d',// QSG_show_group_name |
|
161 | - '%d',// QSG_show_group_desc |
|
162 | - '%d',// QSG_system |
|
163 | - '%d',// QSG_deleted |
|
164 | - ]; |
|
165 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
166 | - if (! $success) { |
|
167 | - $this->add_error( |
|
168 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
169 | - $this->_old_table, |
|
170 | - $old_question_group, |
|
171 | - $this->_new_table, |
|
172 | - $cols_n_values, |
|
173 | - $data_types |
|
174 | - ) |
|
175 | - ); |
|
176 | - return 0; |
|
177 | - } |
|
178 | - return $wpdb->insert_id; |
|
179 | - } |
|
107 | + /** |
|
108 | + * Attempts to insert a new question group in the new format given an old one |
|
109 | + * |
|
110 | + * @param array $old_question_group |
|
111 | + * @return int |
|
112 | + * @global wpdb $wpdb |
|
113 | + */ |
|
114 | + private function _insert_new_question_group(array $old_question_group): int |
|
115 | + { |
|
116 | + global $wpdb; |
|
117 | + // try to guess what the QST_system int should be... |
|
118 | + // finding the Personal info system question group is quite easy. |
|
119 | + // But in 3.1 address info WASN'T a system group, |
|
120 | + // it just existed by default but could be easily removed. |
|
121 | + if ( |
|
122 | + $old_question_group['system_group'] && ! $this->_already_got_system_question_group_1() |
|
123 | + ) { |
|
124 | + $guess_at_system_number = 1; |
|
125 | + } elseif ( |
|
126 | + $old_question_group['id'] == '2' && strpos($old_question_group['group_name'], 'Address') !== false |
|
127 | + ) { |
|
128 | + $guess_at_system_number = 2; |
|
129 | + } else { |
|
130 | + $guess_at_system_number = 0; |
|
131 | + } |
|
132 | + // if the question group wasn't made by the normal admin, |
|
133 | + // we'd like to keep track of who made it |
|
134 | + if ((int) $old_question_group['wp_user'] !== 1) { |
|
135 | + $username = $wpdb->get_var( |
|
136 | + $wpdb->prepare( |
|
137 | + "SELECT user_nicename FROM " . $wpdb->users . " WHERE ID = %d", |
|
138 | + $old_question_group['wp_user'] |
|
139 | + ) |
|
140 | + ); |
|
141 | + $identifier = $old_question_group['group_identifier'] . "-by-" . $username; |
|
142 | + } else { |
|
143 | + $identifier = $old_question_group['group_identifier']; |
|
144 | + } |
|
145 | + $cols_n_values = [ |
|
146 | + 'QSG_name' => stripslashes($old_question_group['group_name']), |
|
147 | + 'QSG_identifier' => $identifier, |
|
148 | + 'QSG_desc' => stripslashes($old_question_group['group_description']), |
|
149 | + 'QSG_order' => $old_question_group['group_order'], |
|
150 | + 'QSG_show_group_name' => $old_question_group['show_group_name'], |
|
151 | + 'QSG_show_group_desc' => $old_question_group['show_group_description'], |
|
152 | + 'QSG_system' => $guess_at_system_number, |
|
153 | + 'QSG_deleted' => false, |
|
154 | + ]; |
|
155 | + $data_types = [ |
|
156 | + '%s',// QSG_name |
|
157 | + '%s',// QSG_identifier |
|
158 | + '%s',// QSG_desc |
|
159 | + '%d',// QSG_order |
|
160 | + '%d',// QSG_show_group_name |
|
161 | + '%d',// QSG_show_group_desc |
|
162 | + '%d',// QSG_system |
|
163 | + '%d',// QSG_deleted |
|
164 | + ]; |
|
165 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
166 | + if (! $success) { |
|
167 | + $this->add_error( |
|
168 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
169 | + $this->_old_table, |
|
170 | + $old_question_group, |
|
171 | + $this->_new_table, |
|
172 | + $cols_n_values, |
|
173 | + $data_types |
|
174 | + ) |
|
175 | + ); |
|
176 | + return 0; |
|
177 | + } |
|
178 | + return $wpdb->insert_id; |
|
179 | + } |
|
180 | 180 | |
181 | 181 | |
182 | - /** |
|
183 | - * Checks if we've already added a system question 1 to the new question groups table |
|
184 | - * |
|
185 | - * @return boolean |
|
186 | - * @global wpdb $wpdb |
|
187 | - */ |
|
188 | - private function _already_got_system_question_group_1(): bool |
|
189 | - { |
|
190 | - if (! $this->_already_got_system_question_group_1) { |
|
191 | - // check the db |
|
192 | - global $wpdb; |
|
193 | - $exists = $wpdb->get_var("SELECT COUNT(*) FROM $this->_new_table WHERE QSG_system=1"); |
|
194 | - if (intval($exists) > 0) { |
|
195 | - $this->_already_got_system_question_group_1 = true; |
|
196 | - } |
|
197 | - } |
|
198 | - return $this->_already_got_system_question_group_1; |
|
199 | - } |
|
182 | + /** |
|
183 | + * Checks if we've already added a system question 1 to the new question groups table |
|
184 | + * |
|
185 | + * @return boolean |
|
186 | + * @global wpdb $wpdb |
|
187 | + */ |
|
188 | + private function _already_got_system_question_group_1(): bool |
|
189 | + { |
|
190 | + if (! $this->_already_got_system_question_group_1) { |
|
191 | + // check the db |
|
192 | + global $wpdb; |
|
193 | + $exists = $wpdb->get_var("SELECT COUNT(*) FROM $this->_new_table WHERE QSG_system=1"); |
|
194 | + if (intval($exists) > 0) { |
|
195 | + $this->_already_got_system_question_group_1 = true; |
|
196 | + } |
|
197 | + } |
|
198 | + return $this->_already_got_system_question_group_1; |
|
199 | + } |
|
200 | 200 | } |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | public function __construct() |
50 | 50 | { |
51 | 51 | global $wpdb; |
52 | - $this->_old_table = $wpdb->prefix . "events_qst_group"; |
|
53 | - $this->_new_table = $wpdb->prefix . "esp_question_group"; |
|
52 | + $this->_old_table = $wpdb->prefix."events_qst_group"; |
|
53 | + $this->_new_table = $wpdb->prefix."esp_question_group"; |
|
54 | 54 | $this->_pretty_name = esc_html__("Question Groups", "event_espresso"); |
55 | 55 | parent::__construct(); |
56 | 56 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | public function _count_records_to_migrate() |
101 | 101 | { |
102 | 102 | global $wpdb; |
103 | - return $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
103 | + return $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | |
@@ -132,13 +132,13 @@ discard block |
||
132 | 132 | // if the question group wasn't made by the normal admin, |
133 | 133 | // we'd like to keep track of who made it |
134 | 134 | if ((int) $old_question_group['wp_user'] !== 1) { |
135 | - $username = $wpdb->get_var( |
|
135 | + $username = $wpdb->get_var( |
|
136 | 136 | $wpdb->prepare( |
137 | - "SELECT user_nicename FROM " . $wpdb->users . " WHERE ID = %d", |
|
137 | + "SELECT user_nicename FROM ".$wpdb->users." WHERE ID = %d", |
|
138 | 138 | $old_question_group['wp_user'] |
139 | 139 | ) |
140 | 140 | ); |
141 | - $identifier = $old_question_group['group_identifier'] . "-by-" . $username; |
|
141 | + $identifier = $old_question_group['group_identifier']."-by-".$username; |
|
142 | 142 | } else { |
143 | 143 | $identifier = $old_question_group['group_identifier']; |
144 | 144 | } |
@@ -152,18 +152,18 @@ discard block |
||
152 | 152 | 'QSG_system' => $guess_at_system_number, |
153 | 153 | 'QSG_deleted' => false, |
154 | 154 | ]; |
155 | - $data_types = [ |
|
156 | - '%s',// QSG_name |
|
157 | - '%s',// QSG_identifier |
|
158 | - '%s',// QSG_desc |
|
159 | - '%d',// QSG_order |
|
160 | - '%d',// QSG_show_group_name |
|
161 | - '%d',// QSG_show_group_desc |
|
162 | - '%d',// QSG_system |
|
163 | - '%d',// QSG_deleted |
|
155 | + $data_types = [ |
|
156 | + '%s', // QSG_name |
|
157 | + '%s', // QSG_identifier |
|
158 | + '%s', // QSG_desc |
|
159 | + '%d', // QSG_order |
|
160 | + '%d', // QSG_show_group_name |
|
161 | + '%d', // QSG_show_group_desc |
|
162 | + '%d', // QSG_system |
|
163 | + '%d', // QSG_deleted |
|
164 | 164 | ]; |
165 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
166 | - if (! $success) { |
|
165 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
166 | + if ( ! $success) { |
|
167 | 167 | $this->add_error( |
168 | 168 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
169 | 169 | $this->_old_table, |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | private function _already_got_system_question_group_1(): bool |
189 | 189 | { |
190 | - if (! $this->_already_got_system_question_group_1) { |
|
190 | + if ( ! $this->_already_got_system_question_group_1) { |
|
191 | 191 | // check the db |
192 | 192 | global $wpdb; |
193 | 193 | $exists = $wpdb->get_var("SELECT COUNT(*) FROM $this->_new_table WHERE QSG_system=1"); |
@@ -90,322 +90,322 @@ |
||
90 | 90 | class EE_DMS_4_1_0_org_options extends EE_Data_Migration_Script_Stage |
91 | 91 | { |
92 | 92 | |
93 | - public function __construct() |
|
94 | - { |
|
95 | - $this->_pretty_name = esc_html__("Organization Options/Config", "event_espresso"); |
|
96 | - $this->_org_options_we_know_how_to_migrate = apply_filters( |
|
97 | - 'FHEE__EE_DMS_4_1_0_org_options__org_options_we_know_how_to_migrate', |
|
98 | - $this->_org_options_we_know_how_to_migrate |
|
99 | - ); |
|
100 | - parent::__construct(); |
|
101 | - } |
|
93 | + public function __construct() |
|
94 | + { |
|
95 | + $this->_pretty_name = esc_html__("Organization Options/Config", "event_espresso"); |
|
96 | + $this->_org_options_we_know_how_to_migrate = apply_filters( |
|
97 | + 'FHEE__EE_DMS_4_1_0_org_options__org_options_we_know_how_to_migrate', |
|
98 | + $this->_org_options_we_know_how_to_migrate |
|
99 | + ); |
|
100 | + parent::__construct(); |
|
101 | + } |
|
102 | 102 | |
103 | 103 | |
104 | - public function _migration_step($num_items_to_migrate = 50) |
|
105 | - { |
|
106 | - $items_actually_migrated = 0; |
|
107 | - $old_org_options = get_option('events_organization_settings'); |
|
108 | - foreach ($this->_org_options_we_know_how_to_migrate as $option_name) { |
|
109 | - // only bother migrating if there's a setting to migrate. Otherwise we'll just use the default |
|
110 | - if (isset($old_org_options[ $option_name ])) { |
|
111 | - $this->_handle_org_option($option_name, $old_org_options[ $option_name ]); |
|
112 | - } |
|
113 | - if ($option_name == 'surcharge') { |
|
114 | - $this->_insert_new_global_surcharge_price($old_org_options); |
|
115 | - } |
|
116 | - $items_actually_migrated++; |
|
117 | - } |
|
104 | + public function _migration_step($num_items_to_migrate = 50) |
|
105 | + { |
|
106 | + $items_actually_migrated = 0; |
|
107 | + $old_org_options = get_option('events_organization_settings'); |
|
108 | + foreach ($this->_org_options_we_know_how_to_migrate as $option_name) { |
|
109 | + // only bother migrating if there's a setting to migrate. Otherwise we'll just use the default |
|
110 | + if (isset($old_org_options[ $option_name ])) { |
|
111 | + $this->_handle_org_option($option_name, $old_org_options[ $option_name ]); |
|
112 | + } |
|
113 | + if ($option_name == 'surcharge') { |
|
114 | + $this->_insert_new_global_surcharge_price($old_org_options); |
|
115 | + } |
|
116 | + $items_actually_migrated++; |
|
117 | + } |
|
118 | 118 | |
119 | - $success = EE_Config::instance()->update_espresso_config(); |
|
120 | - if (! $success) { |
|
121 | - $this->add_error( |
|
122 | - sprintf( |
|
123 | - esc_html__('Could not save EE Config during org options stage. Reason: %s', 'event_espresso'), |
|
124 | - EE_Error::get_notices(false) |
|
125 | - ) |
|
126 | - ); |
|
127 | - EE_Error::overwrite_errors(); |
|
128 | - } |
|
129 | - EE_Network_Config::instance()->update_config(false, false); |
|
130 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
131 | - // we may have added new pages and this might be necessary |
|
132 | - flush_rewrite_rules(); |
|
133 | - $this->set_completed(); |
|
134 | - } |
|
135 | - return $items_actually_migrated; |
|
136 | - } |
|
119 | + $success = EE_Config::instance()->update_espresso_config(); |
|
120 | + if (! $success) { |
|
121 | + $this->add_error( |
|
122 | + sprintf( |
|
123 | + esc_html__('Could not save EE Config during org options stage. Reason: %s', 'event_espresso'), |
|
124 | + EE_Error::get_notices(false) |
|
125 | + ) |
|
126 | + ); |
|
127 | + EE_Error::overwrite_errors(); |
|
128 | + } |
|
129 | + EE_Network_Config::instance()->update_config(false, false); |
|
130 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
131 | + // we may have added new pages and this might be necessary |
|
132 | + flush_rewrite_rules(); |
|
133 | + $this->set_completed(); |
|
134 | + } |
|
135 | + return $items_actually_migrated; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | |
139 | - public function _count_records_to_migrate(): int |
|
140 | - { |
|
141 | - return (int) count($this->_org_options_we_know_how_to_migrate); |
|
142 | - } |
|
139 | + public function _count_records_to_migrate(): int |
|
140 | + { |
|
141 | + return (int) count($this->_org_options_we_know_how_to_migrate); |
|
142 | + } |
|
143 | 143 | |
144 | 144 | |
145 | - private function _handle_org_option($option_name, $value) |
|
146 | - { |
|
147 | - $c = EE_Config::instance(); |
|
148 | - $cn = EE_Network_Config::instance(); |
|
149 | - switch ($option_name) { |
|
150 | - case 'organization': |
|
151 | - $c->organization->name = $value; |
|
152 | - break; |
|
153 | - case 'organization_street1': |
|
154 | - $c->organization->address_1 = $value; |
|
155 | - break; |
|
156 | - case 'organization_street2': |
|
157 | - $c->organization->address_2 = $value; |
|
158 | - break; |
|
159 | - case 'organization_city': |
|
160 | - $c->organization->city = $value; |
|
161 | - break; |
|
162 | - case 'organization_state': |
|
163 | - try { |
|
164 | - $state = $this->get_migration_script()->get_or_create_state($value); |
|
165 | - $state_id = $state['STA_ID']; |
|
166 | - $c->organization->STA_ID = $state_id; |
|
167 | - } catch (EE_Error $e) { |
|
168 | - } |
|
169 | - break; |
|
170 | - case 'organization_zip': |
|
171 | - $c->organization->zip = $value; |
|
172 | - break; |
|
173 | - case 'contact_email': |
|
174 | - $c->organization->email = $value; |
|
175 | - break; |
|
176 | - case 'default_payment_status': |
|
177 | - $c->registration->default_STS_ID = |
|
178 | - $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID($value); |
|
179 | - break; |
|
180 | - case 'organization_country': |
|
181 | - $iso = $this->get_migration_script()->get_iso_from_3_1_country_id($value); |
|
182 | - $c->organization->CNT_ISO = $iso; |
|
183 | - $country_row = $this->get_migration_script()->get_or_create_country($iso); |
|
184 | - if (! $country_row) { |
|
185 | - $this->add_error( |
|
186 | - sprintf( |
|
187 | - esc_html__( |
|
188 | - "Could not set country's currency config because no country exists for ISO %s", |
|
189 | - "event_espresso" |
|
190 | - ), |
|
191 | - $iso |
|
192 | - ) |
|
193 | - ); |
|
194 | - } |
|
195 | - // can't use EE_Currency_Config's handy constructor because the models are off-limits right now (and it uses them) |
|
196 | - $c->currency->code = $country_row['CNT_cur_code']; // currency code: USD, CAD, EUR |
|
197 | - $c->currency->name = $country_row['CNT_cur_single']; // Dollar |
|
198 | - $c->currency->plural = $country_row['CNT_cur_plural']; // Dollars |
|
199 | - $c->currency->sign = $country_row['CNT_cur_sign']; // currency sign: $ |
|
200 | - $c->currency->sign_b4 = filter_var( |
|
201 | - $country_row['CNT_cur_sign_b4'], |
|
202 | - FILTER_VALIDATE_BOOLEAN |
|
203 | - ); // currency sign before or after: $TRUE or FALSE$ |
|
204 | - $c->currency->dec_plc = (int) $country_row['CNT_cur_dec_plc']; // decimal places: 2 = 0.00 3 = 0.000 |
|
205 | - $c->currency->dec_mrk = |
|
206 | - $country_row['CNT_cur_dec_mrk']; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
207 | - $c->currency->thsnds = $country_row['CNT_cur_thsnds']; |
|
208 | - break; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
209 | - // $c->currency = new EE_Currency_Config($c->organization->CNT_ISO);break; |
|
210 | - // case 'currency_symbol': ignore the currency symbol. we'll just go by their country. |
|
211 | - // $c->currency->sign = $value;break; |
|
212 | - case 'show_pending_payment_options': |
|
213 | - $c->registration->show_pending_payment_options = ($value == 'Y'); |
|
214 | - break; |
|
215 | - case 'display_address_in_regform': |
|
216 | - $c->template_settings->display_address_in_regform = ($value == 'Y'); |
|
217 | - break; |
|
218 | - case 'default_logo_url': |
|
219 | - $c->organization->logo_url = $value; |
|
220 | - break; |
|
221 | - case 'event_page_id': |
|
222 | - // also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS |
|
223 | - // to ESPRESSO_THANK_YOU |
|
224 | - $reg_page_post = get_post($value); |
|
225 | - $reg_page_post->post_content = str_replace( |
|
226 | - "[ESPRESSO_EVENTS]", |
|
227 | - "[ESPRESSO_CHECKOUT]", |
|
228 | - $reg_page_post->post_content |
|
229 | - ); |
|
230 | - wp_update_post($reg_page_post); |
|
231 | - $c->core->reg_page_id = $value; |
|
232 | - break; |
|
233 | - case 'return_url': |
|
234 | - // also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS |
|
235 | - // to ESPRESSO_THANK_YOU |
|
236 | - $thank_you_page_post = get_post($value); |
|
237 | - $thank_you_page_post->post_content = str_replace( |
|
238 | - "[ESPRESSO_PAYMENTS]", |
|
239 | - "[ESPRESSO_THANK_YOU]", |
|
240 | - $thank_you_page_post->post_content |
|
241 | - ); |
|
242 | - wp_update_post($thank_you_page_post); |
|
243 | - $c->core->thank_you_page_id = $value; |
|
244 | - break; |
|
245 | - case 'cancel_return': |
|
246 | - $c->core->cancel_page_id = $value; |
|
145 | + private function _handle_org_option($option_name, $value) |
|
146 | + { |
|
147 | + $c = EE_Config::instance(); |
|
148 | + $cn = EE_Network_Config::instance(); |
|
149 | + switch ($option_name) { |
|
150 | + case 'organization': |
|
151 | + $c->organization->name = $value; |
|
152 | + break; |
|
153 | + case 'organization_street1': |
|
154 | + $c->organization->address_1 = $value; |
|
155 | + break; |
|
156 | + case 'organization_street2': |
|
157 | + $c->organization->address_2 = $value; |
|
158 | + break; |
|
159 | + case 'organization_city': |
|
160 | + $c->organization->city = $value; |
|
161 | + break; |
|
162 | + case 'organization_state': |
|
163 | + try { |
|
164 | + $state = $this->get_migration_script()->get_or_create_state($value); |
|
165 | + $state_id = $state['STA_ID']; |
|
166 | + $c->organization->STA_ID = $state_id; |
|
167 | + } catch (EE_Error $e) { |
|
168 | + } |
|
169 | + break; |
|
170 | + case 'organization_zip': |
|
171 | + $c->organization->zip = $value; |
|
172 | + break; |
|
173 | + case 'contact_email': |
|
174 | + $c->organization->email = $value; |
|
175 | + break; |
|
176 | + case 'default_payment_status': |
|
177 | + $c->registration->default_STS_ID = |
|
178 | + $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID($value); |
|
179 | + break; |
|
180 | + case 'organization_country': |
|
181 | + $iso = $this->get_migration_script()->get_iso_from_3_1_country_id($value); |
|
182 | + $c->organization->CNT_ISO = $iso; |
|
183 | + $country_row = $this->get_migration_script()->get_or_create_country($iso); |
|
184 | + if (! $country_row) { |
|
185 | + $this->add_error( |
|
186 | + sprintf( |
|
187 | + esc_html__( |
|
188 | + "Could not set country's currency config because no country exists for ISO %s", |
|
189 | + "event_espresso" |
|
190 | + ), |
|
191 | + $iso |
|
192 | + ) |
|
193 | + ); |
|
194 | + } |
|
195 | + // can't use EE_Currency_Config's handy constructor because the models are off-limits right now (and it uses them) |
|
196 | + $c->currency->code = $country_row['CNT_cur_code']; // currency code: USD, CAD, EUR |
|
197 | + $c->currency->name = $country_row['CNT_cur_single']; // Dollar |
|
198 | + $c->currency->plural = $country_row['CNT_cur_plural']; // Dollars |
|
199 | + $c->currency->sign = $country_row['CNT_cur_sign']; // currency sign: $ |
|
200 | + $c->currency->sign_b4 = filter_var( |
|
201 | + $country_row['CNT_cur_sign_b4'], |
|
202 | + FILTER_VALIDATE_BOOLEAN |
|
203 | + ); // currency sign before or after: $TRUE or FALSE$ |
|
204 | + $c->currency->dec_plc = (int) $country_row['CNT_cur_dec_plc']; // decimal places: 2 = 0.00 3 = 0.000 |
|
205 | + $c->currency->dec_mrk = |
|
206 | + $country_row['CNT_cur_dec_mrk']; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
207 | + $c->currency->thsnds = $country_row['CNT_cur_thsnds']; |
|
208 | + break; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
209 | + // $c->currency = new EE_Currency_Config($c->organization->CNT_ISO);break; |
|
210 | + // case 'currency_symbol': ignore the currency symbol. we'll just go by their country. |
|
211 | + // $c->currency->sign = $value;break; |
|
212 | + case 'show_pending_payment_options': |
|
213 | + $c->registration->show_pending_payment_options = ($value == 'Y'); |
|
214 | + break; |
|
215 | + case 'display_address_in_regform': |
|
216 | + $c->template_settings->display_address_in_regform = ($value == 'Y'); |
|
217 | + break; |
|
218 | + case 'default_logo_url': |
|
219 | + $c->organization->logo_url = $value; |
|
220 | + break; |
|
221 | + case 'event_page_id': |
|
222 | + // also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS |
|
223 | + // to ESPRESSO_THANK_YOU |
|
224 | + $reg_page_post = get_post($value); |
|
225 | + $reg_page_post->post_content = str_replace( |
|
226 | + "[ESPRESSO_EVENTS]", |
|
227 | + "[ESPRESSO_CHECKOUT]", |
|
228 | + $reg_page_post->post_content |
|
229 | + ); |
|
230 | + wp_update_post($reg_page_post); |
|
231 | + $c->core->reg_page_id = $value; |
|
232 | + break; |
|
233 | + case 'return_url': |
|
234 | + // also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS |
|
235 | + // to ESPRESSO_THANK_YOU |
|
236 | + $thank_you_page_post = get_post($value); |
|
237 | + $thank_you_page_post->post_content = str_replace( |
|
238 | + "[ESPRESSO_PAYMENTS]", |
|
239 | + "[ESPRESSO_THANK_YOU]", |
|
240 | + $thank_you_page_post->post_content |
|
241 | + ); |
|
242 | + wp_update_post($thank_you_page_post); |
|
243 | + $c->core->thank_you_page_id = $value; |
|
244 | + break; |
|
245 | + case 'cancel_return': |
|
246 | + $c->core->cancel_page_id = $value; |
|
247 | 247 | |
248 | - break; |
|
249 | - case 'notify_url': |
|
250 | - $c->core->txn_page_id = $value; |
|
251 | - break; |
|
252 | - case 'use_captcha': |
|
253 | - $c->registration->use_captcha = ($value == 'Y'); |
|
254 | - break; |
|
255 | - case 'recaptcha_publickey': |
|
256 | - $c->registration->recaptcha_publickey = $value; |
|
257 | - break; |
|
258 | - case 'recaptcha_privatekey': |
|
259 | - $c->registration->recaptcha_privatekey = $value; |
|
260 | - break; |
|
261 | - case 'recaptcha_theme': |
|
262 | - $c->registration->recaptcha_theme = $value; |
|
263 | - break; |
|
264 | - case 'recaptcha_width': |
|
265 | - $c->registration->recaptcha_width = $value; |
|
266 | - break; |
|
267 | - case 'recaptcha_language': |
|
268 | - $c->registration->recaptcha_language = $value; |
|
269 | - break; |
|
270 | - case 'espresso_dashboard_widget': |
|
271 | - $c->admin->use_dashboard_widget = ($value == 'Y'); |
|
272 | - break; |
|
273 | - case 'use_personnel_manager': |
|
274 | - $c->admin->use_personnel_manager = ($value == 'Y'); |
|
275 | - break; |
|
276 | - case 'use_event_timezones': |
|
277 | - $c->admin->use_event_timezones = ($value == 'Y'); |
|
278 | - break; |
|
279 | - case 'affiliate_id': |
|
280 | - $c->admin->affiliate_id = $value; |
|
281 | - break; |
|
282 | - case 'site_license_key': |
|
283 | - $cn->core->site_license_key = $value; |
|
284 | - break; |
|
285 | - default: |
|
286 | - do_action('AHEE__EE_DMS_4_1_0__handle_org_option', $option_name, $value); |
|
287 | - } |
|
288 | - } |
|
248 | + break; |
|
249 | + case 'notify_url': |
|
250 | + $c->core->txn_page_id = $value; |
|
251 | + break; |
|
252 | + case 'use_captcha': |
|
253 | + $c->registration->use_captcha = ($value == 'Y'); |
|
254 | + break; |
|
255 | + case 'recaptcha_publickey': |
|
256 | + $c->registration->recaptcha_publickey = $value; |
|
257 | + break; |
|
258 | + case 'recaptcha_privatekey': |
|
259 | + $c->registration->recaptcha_privatekey = $value; |
|
260 | + break; |
|
261 | + case 'recaptcha_theme': |
|
262 | + $c->registration->recaptcha_theme = $value; |
|
263 | + break; |
|
264 | + case 'recaptcha_width': |
|
265 | + $c->registration->recaptcha_width = $value; |
|
266 | + break; |
|
267 | + case 'recaptcha_language': |
|
268 | + $c->registration->recaptcha_language = $value; |
|
269 | + break; |
|
270 | + case 'espresso_dashboard_widget': |
|
271 | + $c->admin->use_dashboard_widget = ($value == 'Y'); |
|
272 | + break; |
|
273 | + case 'use_personnel_manager': |
|
274 | + $c->admin->use_personnel_manager = ($value == 'Y'); |
|
275 | + break; |
|
276 | + case 'use_event_timezones': |
|
277 | + $c->admin->use_event_timezones = ($value == 'Y'); |
|
278 | + break; |
|
279 | + case 'affiliate_id': |
|
280 | + $c->admin->affiliate_id = $value; |
|
281 | + break; |
|
282 | + case 'site_license_key': |
|
283 | + $cn->core->site_license_key = $value; |
|
284 | + break; |
|
285 | + default: |
|
286 | + do_action('AHEE__EE_DMS_4_1_0__handle_org_option', $option_name, $value); |
|
287 | + } |
|
288 | + } |
|
289 | 289 | |
290 | 290 | |
291 | - /** |
|
292 | - * Creates a 4.1 member price discount |
|
293 | - * |
|
294 | - * @param array $org_options |
|
295 | - * @return void |
|
296 | - * @global wpdb $wpdb |
|
297 | - */ |
|
298 | - private function _insert_new_global_surcharge_price(array $org_options): void |
|
299 | - { |
|
300 | - $amount = (float) $org_options['surcharge']; |
|
301 | - // dont create a price if the surcharge is 0 |
|
302 | - if ($amount <= .01) { |
|
303 | - return; |
|
304 | - } |
|
305 | - if ($org_options['surcharge_type'] == 'flat_rate') { |
|
306 | - $price_type = EE_DMS_4_1_0_prices::price_type_flat_surcharge; |
|
307 | - } else { |
|
308 | - $price_type = EE_DMS_4_1_0_prices::price_type_percent_surcharge; |
|
309 | - } |
|
310 | - global $wpdb; |
|
311 | - $cols_n_values = [ |
|
312 | - 'PRT_ID' => $price_type, |
|
313 | - 'PRC_amount' => $amount, |
|
314 | - 'PRC_name' => $org_options['surcharge_text'], |
|
315 | - 'PRC_is_default' => true, |
|
316 | - 'PRC_overrides' => false, |
|
317 | - 'PRC_order' => 100, |
|
318 | - 'PRC_deleted' => false, |
|
319 | - 'PRC_parent' => null, |
|
291 | + /** |
|
292 | + * Creates a 4.1 member price discount |
|
293 | + * |
|
294 | + * @param array $org_options |
|
295 | + * @return void |
|
296 | + * @global wpdb $wpdb |
|
297 | + */ |
|
298 | + private function _insert_new_global_surcharge_price(array $org_options): void |
|
299 | + { |
|
300 | + $amount = (float) $org_options['surcharge']; |
|
301 | + // dont create a price if the surcharge is 0 |
|
302 | + if ($amount <= .01) { |
|
303 | + return; |
|
304 | + } |
|
305 | + if ($org_options['surcharge_type'] == 'flat_rate') { |
|
306 | + $price_type = EE_DMS_4_1_0_prices::price_type_flat_surcharge; |
|
307 | + } else { |
|
308 | + $price_type = EE_DMS_4_1_0_prices::price_type_percent_surcharge; |
|
309 | + } |
|
310 | + global $wpdb; |
|
311 | + $cols_n_values = [ |
|
312 | + 'PRT_ID' => $price_type, |
|
313 | + 'PRC_amount' => $amount, |
|
314 | + 'PRC_name' => $org_options['surcharge_text'], |
|
315 | + 'PRC_is_default' => true, |
|
316 | + 'PRC_overrides' => false, |
|
317 | + 'PRC_order' => 100, |
|
318 | + 'PRC_deleted' => false, |
|
319 | + 'PRC_parent' => null, |
|
320 | 320 | |
321 | - ]; |
|
322 | - $data_types = [ |
|
323 | - '%d',// PRT_ID |
|
324 | - '%f',// PRT_amount |
|
325 | - '%s',// PRC_name |
|
326 | - '%d',// PRC_is_default |
|
327 | - '%d',// PRC_overrides |
|
328 | - '%d',// PRC_order |
|
329 | - '%d',// PRC_deleted |
|
330 | - '%d',// PRC_parent |
|
331 | - ]; |
|
332 | - $price_table = $wpdb->prefix . "esp_price"; |
|
333 | - $success = $wpdb->insert($price_table, $cols_n_values, $data_types); |
|
334 | - if (! $success) { |
|
335 | - $this->add_error( |
|
336 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
337 | - 'org_options', |
|
338 | - [ |
|
339 | - 'surcharge' => $org_options['surcharge'], |
|
340 | - 'surcharge_type' => $org_options['surcharge_type'], |
|
341 | - 'surcharge_text' => $org_options['surcharge_text'], |
|
342 | - ], |
|
343 | - $price_table, |
|
344 | - $cols_n_values, |
|
345 | - $data_types |
|
346 | - ) |
|
347 | - ); |
|
348 | - } |
|
349 | - } |
|
321 | + ]; |
|
322 | + $data_types = [ |
|
323 | + '%d',// PRT_ID |
|
324 | + '%f',// PRT_amount |
|
325 | + '%s',// PRC_name |
|
326 | + '%d',// PRC_is_default |
|
327 | + '%d',// PRC_overrides |
|
328 | + '%d',// PRC_order |
|
329 | + '%d',// PRC_deleted |
|
330 | + '%d',// PRC_parent |
|
331 | + ]; |
|
332 | + $price_table = $wpdb->prefix . "esp_price"; |
|
333 | + $success = $wpdb->insert($price_table, $cols_n_values, $data_types); |
|
334 | + if (! $success) { |
|
335 | + $this->add_error( |
|
336 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
337 | + 'org_options', |
|
338 | + [ |
|
339 | + 'surcharge' => $org_options['surcharge'], |
|
340 | + 'surcharge_type' => $org_options['surcharge_type'], |
|
341 | + 'surcharge_text' => $org_options['surcharge_text'], |
|
342 | + ], |
|
343 | + $price_table, |
|
344 | + $cols_n_values, |
|
345 | + $data_types |
|
346 | + ) |
|
347 | + ); |
|
348 | + } |
|
349 | + } |
|
350 | 350 | |
351 | 351 | |
352 | - protected $_org_options_we_know_how_to_migrate = [ |
|
353 | - 'organization', |
|
354 | - 'organization_street1', |
|
355 | - 'organization_street2', |
|
356 | - 'organization_city', |
|
357 | - 'organization_state', |
|
358 | - 'organization_zip', |
|
359 | - 'contact_email', |
|
360 | - 'default_mail', |
|
361 | - 'payment_subject', |
|
362 | - 'payment_message', |
|
363 | - 'message', |
|
364 | - 'default_payment_status', |
|
365 | - 'surcharge',// unused? |
|
366 | - 'country_id',// unused? |
|
367 | - 'organization_country', |
|
368 | - // 'currency_symbol', |
|
369 | - 'expire_on_registration_end', |
|
370 | - 'email_before_payment', |
|
371 | - 'email_fancy_headers', |
|
372 | - 'enable_default_style', |
|
373 | - 'event_ssl_active', |
|
374 | - 'selected_style', |
|
375 | - 'show_pending_payment_options', |
|
376 | - 'show_reg_footer', |
|
377 | - 'skip_confirmation_page', |
|
378 | - 'allow_mer_discounts',// no equiv |
|
379 | - 'allow_mer_vouchers',// no equiv |
|
380 | - 'display_short_description_in_event_list', |
|
381 | - 'display_description_on_multi_reg_page', |
|
382 | - 'display_address_in_event_list', |
|
383 | - 'display_address_in_regform', |
|
384 | - 'use_custom_post_types',// no equiv |
|
385 | - 'display_ical_download', |
|
386 | - 'display_featured_image', |
|
387 | - 'themeroller', |
|
388 | - 'default_logo_url', |
|
389 | - 'event_page_id', |
|
390 | - 'return_url', |
|
391 | - 'cancel_return', |
|
392 | - 'notify_url', |
|
393 | - 'events_in_dashboard', |
|
394 | - 'use_captcha', |
|
395 | - 'recaptcha_publickey', |
|
396 | - 'recaptcha_privatekey', |
|
397 | - 'recaptcha_theme', |
|
398 | - 'recaptcha_width', |
|
399 | - 'recaptcha_language', |
|
400 | - 'espresso_dashboard_widget', |
|
401 | - 'time_reg_limit', |
|
402 | - // 'use_attendee_pre_approval', removed in 4.1- instead this is factored into the default reg status |
|
403 | - 'use_personnel_manager',// no equiv |
|
404 | - 'use_event_timezones', |
|
405 | - 'full_logging', |
|
406 | - 'surcharge_type',// unused |
|
407 | - 'surcharge_text',// unused |
|
408 | - 'affiliate_id', |
|
409 | - 'site_license_key', |
|
410 | - ]; |
|
352 | + protected $_org_options_we_know_how_to_migrate = [ |
|
353 | + 'organization', |
|
354 | + 'organization_street1', |
|
355 | + 'organization_street2', |
|
356 | + 'organization_city', |
|
357 | + 'organization_state', |
|
358 | + 'organization_zip', |
|
359 | + 'contact_email', |
|
360 | + 'default_mail', |
|
361 | + 'payment_subject', |
|
362 | + 'payment_message', |
|
363 | + 'message', |
|
364 | + 'default_payment_status', |
|
365 | + 'surcharge',// unused? |
|
366 | + 'country_id',// unused? |
|
367 | + 'organization_country', |
|
368 | + // 'currency_symbol', |
|
369 | + 'expire_on_registration_end', |
|
370 | + 'email_before_payment', |
|
371 | + 'email_fancy_headers', |
|
372 | + 'enable_default_style', |
|
373 | + 'event_ssl_active', |
|
374 | + 'selected_style', |
|
375 | + 'show_pending_payment_options', |
|
376 | + 'show_reg_footer', |
|
377 | + 'skip_confirmation_page', |
|
378 | + 'allow_mer_discounts',// no equiv |
|
379 | + 'allow_mer_vouchers',// no equiv |
|
380 | + 'display_short_description_in_event_list', |
|
381 | + 'display_description_on_multi_reg_page', |
|
382 | + 'display_address_in_event_list', |
|
383 | + 'display_address_in_regform', |
|
384 | + 'use_custom_post_types',// no equiv |
|
385 | + 'display_ical_download', |
|
386 | + 'display_featured_image', |
|
387 | + 'themeroller', |
|
388 | + 'default_logo_url', |
|
389 | + 'event_page_id', |
|
390 | + 'return_url', |
|
391 | + 'cancel_return', |
|
392 | + 'notify_url', |
|
393 | + 'events_in_dashboard', |
|
394 | + 'use_captcha', |
|
395 | + 'recaptcha_publickey', |
|
396 | + 'recaptcha_privatekey', |
|
397 | + 'recaptcha_theme', |
|
398 | + 'recaptcha_width', |
|
399 | + 'recaptcha_language', |
|
400 | + 'espresso_dashboard_widget', |
|
401 | + 'time_reg_limit', |
|
402 | + // 'use_attendee_pre_approval', removed in 4.1- instead this is factored into the default reg status |
|
403 | + 'use_personnel_manager',// no equiv |
|
404 | + 'use_event_timezones', |
|
405 | + 'full_logging', |
|
406 | + 'surcharge_type',// unused |
|
407 | + 'surcharge_text',// unused |
|
408 | + 'affiliate_id', |
|
409 | + 'site_license_key', |
|
410 | + ]; |
|
411 | 411 | } |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | $old_org_options = get_option('events_organization_settings'); |
108 | 108 | foreach ($this->_org_options_we_know_how_to_migrate as $option_name) { |
109 | 109 | // only bother migrating if there's a setting to migrate. Otherwise we'll just use the default |
110 | - if (isset($old_org_options[ $option_name ])) { |
|
111 | - $this->_handle_org_option($option_name, $old_org_options[ $option_name ]); |
|
110 | + if (isset($old_org_options[$option_name])) { |
|
111 | + $this->_handle_org_option($option_name, $old_org_options[$option_name]); |
|
112 | 112 | } |
113 | 113 | if ($option_name == 'surcharge') { |
114 | 114 | $this->_insert_new_global_surcharge_price($old_org_options); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | $success = EE_Config::instance()->update_espresso_config(); |
120 | - if (! $success) { |
|
120 | + if ( ! $success) { |
|
121 | 121 | $this->add_error( |
122 | 122 | sprintf( |
123 | 123 | esc_html__('Could not save EE Config during org options stage. Reason: %s', 'event_espresso'), |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | $iso = $this->get_migration_script()->get_iso_from_3_1_country_id($value); |
182 | 182 | $c->organization->CNT_ISO = $iso; |
183 | 183 | $country_row = $this->get_migration_script()->get_or_create_country($iso); |
184 | - if (! $country_row) { |
|
184 | + if ( ! $country_row) { |
|
185 | 185 | $this->add_error( |
186 | 186 | sprintf( |
187 | 187 | esc_html__( |
@@ -193,19 +193,19 @@ discard block |
||
193 | 193 | ); |
194 | 194 | } |
195 | 195 | // can't use EE_Currency_Config's handy constructor because the models are off-limits right now (and it uses them) |
196 | - $c->currency->code = $country_row['CNT_cur_code']; // currency code: USD, CAD, EUR |
|
197 | - $c->currency->name = $country_row['CNT_cur_single']; // Dollar |
|
198 | - $c->currency->plural = $country_row['CNT_cur_plural']; // Dollars |
|
199 | - $c->currency->sign = $country_row['CNT_cur_sign']; // currency sign: $ |
|
196 | + $c->currency->code = $country_row['CNT_cur_code']; // currency code: USD, CAD, EUR |
|
197 | + $c->currency->name = $country_row['CNT_cur_single']; // Dollar |
|
198 | + $c->currency->plural = $country_row['CNT_cur_plural']; // Dollars |
|
199 | + $c->currency->sign = $country_row['CNT_cur_sign']; // currency sign: $ |
|
200 | 200 | $c->currency->sign_b4 = filter_var( |
201 | 201 | $country_row['CNT_cur_sign_b4'], |
202 | 202 | FILTER_VALIDATE_BOOLEAN |
203 | - ); // currency sign before or after: $TRUE or FALSE$ |
|
204 | - $c->currency->dec_plc = (int) $country_row['CNT_cur_dec_plc']; // decimal places: 2 = 0.00 3 = 0.000 |
|
203 | + ); // currency sign before or after: $TRUE or FALSE$ |
|
204 | + $c->currency->dec_plc = (int) $country_row['CNT_cur_dec_plc']; // decimal places: 2 = 0.00 3 = 0.000 |
|
205 | 205 | $c->currency->dec_mrk = |
206 | - $country_row['CNT_cur_dec_mrk']; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
206 | + $country_row['CNT_cur_dec_mrk']; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
207 | 207 | $c->currency->thsnds = $country_row['CNT_cur_thsnds']; |
208 | - break; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
208 | + break; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
209 | 209 | // $c->currency = new EE_Currency_Config($c->organization->CNT_ISO);break; |
210 | 210 | // case 'currency_symbol': ignore the currency symbol. we'll just go by their country. |
211 | 211 | // $c->currency->sign = $value;break; |
@@ -319,19 +319,19 @@ discard block |
||
319 | 319 | 'PRC_parent' => null, |
320 | 320 | |
321 | 321 | ]; |
322 | - $data_types = [ |
|
323 | - '%d',// PRT_ID |
|
324 | - '%f',// PRT_amount |
|
325 | - '%s',// PRC_name |
|
326 | - '%d',// PRC_is_default |
|
327 | - '%d',// PRC_overrides |
|
328 | - '%d',// PRC_order |
|
329 | - '%d',// PRC_deleted |
|
330 | - '%d',// PRC_parent |
|
322 | + $data_types = [ |
|
323 | + '%d', // PRT_ID |
|
324 | + '%f', // PRT_amount |
|
325 | + '%s', // PRC_name |
|
326 | + '%d', // PRC_is_default |
|
327 | + '%d', // PRC_overrides |
|
328 | + '%d', // PRC_order |
|
329 | + '%d', // PRC_deleted |
|
330 | + '%d', // PRC_parent |
|
331 | 331 | ]; |
332 | - $price_table = $wpdb->prefix . "esp_price"; |
|
332 | + $price_table = $wpdb->prefix."esp_price"; |
|
333 | 333 | $success = $wpdb->insert($price_table, $cols_n_values, $data_types); |
334 | - if (! $success) { |
|
334 | + if ( ! $success) { |
|
335 | 335 | $this->add_error( |
336 | 336 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
337 | 337 | 'org_options', |
@@ -362,8 +362,8 @@ discard block |
||
362 | 362 | 'payment_message', |
363 | 363 | 'message', |
364 | 364 | 'default_payment_status', |
365 | - 'surcharge',// unused? |
|
366 | - 'country_id',// unused? |
|
365 | + 'surcharge', // unused? |
|
366 | + 'country_id', // unused? |
|
367 | 367 | 'organization_country', |
368 | 368 | // 'currency_symbol', |
369 | 369 | 'expire_on_registration_end', |
@@ -375,13 +375,13 @@ discard block |
||
375 | 375 | 'show_pending_payment_options', |
376 | 376 | 'show_reg_footer', |
377 | 377 | 'skip_confirmation_page', |
378 | - 'allow_mer_discounts',// no equiv |
|
379 | - 'allow_mer_vouchers',// no equiv |
|
378 | + 'allow_mer_discounts', // no equiv |
|
379 | + 'allow_mer_vouchers', // no equiv |
|
380 | 380 | 'display_short_description_in_event_list', |
381 | 381 | 'display_description_on_multi_reg_page', |
382 | 382 | 'display_address_in_event_list', |
383 | 383 | 'display_address_in_regform', |
384 | - 'use_custom_post_types',// no equiv |
|
384 | + 'use_custom_post_types', // no equiv |
|
385 | 385 | 'display_ical_download', |
386 | 386 | 'display_featured_image', |
387 | 387 | 'themeroller', |
@@ -400,11 +400,11 @@ discard block |
||
400 | 400 | 'espresso_dashboard_widget', |
401 | 401 | 'time_reg_limit', |
402 | 402 | // 'use_attendee_pre_approval', removed in 4.1- instead this is factored into the default reg status |
403 | - 'use_personnel_manager',// no equiv |
|
403 | + 'use_personnel_manager', // no equiv |
|
404 | 404 | 'use_event_timezones', |
405 | 405 | 'full_logging', |
406 | - 'surcharge_type',// unused |
|
407 | - 'surcharge_text',// unused |
|
406 | + 'surcharge_type', // unused |
|
407 | + 'surcharge_text', // unused |
|
408 | 408 | 'affiliate_id', |
409 | 409 | 'site_license_key', |
410 | 410 | ]; |
@@ -7,74 +7,74 @@ |
||
7 | 7 | class EE_DMS_4_1_0_shortcodes extends EE_Data_Migration_Script_Stage |
8 | 8 | { |
9 | 9 | |
10 | - public function __construct() |
|
11 | - { |
|
12 | - global $wpdb; |
|
13 | - $this->_pretty_name = esc_html__("Shortcodes", "event_espresso"); |
|
14 | - $this->_old_table = $wpdb->posts; |
|
15 | - parent::__construct(); |
|
16 | - } |
|
10 | + public function __construct() |
|
11 | + { |
|
12 | + global $wpdb; |
|
13 | + $this->_pretty_name = esc_html__("Shortcodes", "event_espresso"); |
|
14 | + $this->_old_table = $wpdb->posts; |
|
15 | + parent::__construct(); |
|
16 | + } |
|
17 | 17 | |
18 | 18 | |
19 | - protected function _migrate_old_row($old_row) |
|
20 | - { |
|
21 | - $new_post_content = $this->_change_event_list_shortcode($old_row['post_content']); |
|
22 | - global $wpdb; |
|
23 | - $wpdb->query( |
|
24 | - $wpdb->prepare( |
|
25 | - "UPDATE " . $this->_old_table . " SET post_content=%s WHERE ID=%d", |
|
26 | - $new_post_content, |
|
27 | - $old_row['ID'] |
|
28 | - ) |
|
29 | - ); |
|
30 | - } |
|
19 | + protected function _migrate_old_row($old_row) |
|
20 | + { |
|
21 | + $new_post_content = $this->_change_event_list_shortcode($old_row['post_content']); |
|
22 | + global $wpdb; |
|
23 | + $wpdb->query( |
|
24 | + $wpdb->prepare( |
|
25 | + "UPDATE " . $this->_old_table . " SET post_content=%s WHERE ID=%d", |
|
26 | + $new_post_content, |
|
27 | + $old_row['ID'] |
|
28 | + ) |
|
29 | + ); |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * replaces [EVENT_LIST... with [ESPRESSO_EVENTS...] |
|
35 | - * |
|
36 | - * @param string $old_content |
|
37 | - * @return array|string|string[] |
|
38 | - */ |
|
39 | - private function _change_event_list_shortcode(string $old_content) |
|
40 | - { |
|
41 | - return str_replace("[EVENT_LIST", "[ESPRESSO_EVENTS", $old_content); |
|
42 | - } |
|
33 | + /** |
|
34 | + * replaces [EVENT_LIST... with [ESPRESSO_EVENTS...] |
|
35 | + * |
|
36 | + * @param string $old_content |
|
37 | + * @return array|string|string[] |
|
38 | + */ |
|
39 | + private function _change_event_list_shortcode(string $old_content) |
|
40 | + { |
|
41 | + return str_replace("[EVENT_LIST", "[ESPRESSO_EVENTS", $old_content); |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - public function _migration_step($num_items_to_migrate = 50) |
|
46 | - { |
|
47 | - global $wpdb; |
|
48 | - $start_at_record = $this->count_records_migrated(); |
|
49 | - $rows = $wpdb->get_results( |
|
50 | - $wpdb->prepare( |
|
51 | - "SELECT * FROM $this->_old_table {$this->_sql_to_only_select_non_drafts()} LIMIT %d,%d", |
|
52 | - $start_at_record, |
|
53 | - $num_items_to_migrate |
|
54 | - ), |
|
55 | - ARRAY_A |
|
56 | - ); |
|
57 | - $items_actually_migrated = 0; |
|
58 | - foreach ($rows as $old_row) { |
|
59 | - $this->_migrate_old_row($old_row); |
|
60 | - $items_actually_migrated++; |
|
61 | - } |
|
62 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
63 | - $this->set_completed(); |
|
64 | - } |
|
65 | - return $items_actually_migrated; |
|
66 | - } |
|
45 | + public function _migration_step($num_items_to_migrate = 50) |
|
46 | + { |
|
47 | + global $wpdb; |
|
48 | + $start_at_record = $this->count_records_migrated(); |
|
49 | + $rows = $wpdb->get_results( |
|
50 | + $wpdb->prepare( |
|
51 | + "SELECT * FROM $this->_old_table {$this->_sql_to_only_select_non_drafts()} LIMIT %d,%d", |
|
52 | + $start_at_record, |
|
53 | + $num_items_to_migrate |
|
54 | + ), |
|
55 | + ARRAY_A |
|
56 | + ); |
|
57 | + $items_actually_migrated = 0; |
|
58 | + foreach ($rows as $old_row) { |
|
59 | + $this->_migrate_old_row($old_row); |
|
60 | + $items_actually_migrated++; |
|
61 | + } |
|
62 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
63 | + $this->set_completed(); |
|
64 | + } |
|
65 | + return $items_actually_migrated; |
|
66 | + } |
|
67 | 67 | |
68 | 68 | |
69 | - public function _count_records_to_migrate() |
|
70 | - { |
|
71 | - global $wpdb; |
|
72 | - return $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table . $this->_sql_to_only_select_non_drafts()); |
|
73 | - } |
|
69 | + public function _count_records_to_migrate() |
|
70 | + { |
|
71 | + global $wpdb; |
|
72 | + return $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table . $this->_sql_to_only_select_non_drafts()); |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - private function _sql_to_only_select_non_drafts(): string |
|
77 | - { |
|
78 | - return " WHERE post_type NOT IN ('revision','auto-draft','attachment','nav_menu_item') "; |
|
79 | - } |
|
76 | + private function _sql_to_only_select_non_drafts(): string |
|
77 | + { |
|
78 | + return " WHERE post_type NOT IN ('revision','auto-draft','attachment','nav_menu_item') "; |
|
79 | + } |
|
80 | 80 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | global $wpdb; |
23 | 23 | $wpdb->query( |
24 | 24 | $wpdb->prepare( |
25 | - "UPDATE " . $this->_old_table . " SET post_content=%s WHERE ID=%d", |
|
25 | + "UPDATE ".$this->_old_table." SET post_content=%s WHERE ID=%d", |
|
26 | 26 | $new_post_content, |
27 | 27 | $old_row['ID'] |
28 | 28 | ) |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | public function _count_records_to_migrate() |
70 | 70 | { |
71 | 71 | global $wpdb; |
72 | - return $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table . $this->_sql_to_only_select_non_drafts()); |
|
72 | + return $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table.$this->_sql_to_only_select_non_drafts()); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 |
@@ -86,287 +86,287 @@ |
||
86 | 86 | */ |
87 | 87 | class EE_DMS_4_1_0_venues extends EE_Data_Migration_Script_Stage |
88 | 88 | { |
89 | - private string $_new_meta_table; |
|
89 | + private string $_new_meta_table; |
|
90 | 90 | |
91 | 91 | |
92 | - public function __construct() |
|
93 | - { |
|
94 | - $this->_pretty_name = esc_html__("Venues", "event_espresso"); |
|
95 | - global $wpdb; |
|
96 | - $this->_old_table = $wpdb->prefix . "events_venue"; |
|
97 | - $this->_new_table = $wpdb->posts; |
|
98 | - $this->_new_meta_table = $wpdb->prefix . "esp_venue_meta"; |
|
99 | - parent::__construct(); |
|
100 | - } |
|
92 | + public function __construct() |
|
93 | + { |
|
94 | + $this->_pretty_name = esc_html__("Venues", "event_espresso"); |
|
95 | + global $wpdb; |
|
96 | + $this->_old_table = $wpdb->prefix . "events_venue"; |
|
97 | + $this->_new_table = $wpdb->posts; |
|
98 | + $this->_new_meta_table = $wpdb->prefix . "esp_venue_meta"; |
|
99 | + parent::__construct(); |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * @throws EE_Error |
|
105 | - */ |
|
106 | - public function _migration_step($num_items_to_migrate = 50) |
|
107 | - { |
|
108 | - global $wpdb; |
|
109 | - $start_at_record = $this->count_records_migrated(); |
|
110 | - $rows = $wpdb->get_results( |
|
111 | - $wpdb->prepare( |
|
112 | - "SELECT * FROM " . $this->_old_table . " LIMIT %d,%d", |
|
113 | - $start_at_record, |
|
114 | - $num_items_to_migrate |
|
115 | - ), |
|
116 | - ARRAY_A |
|
117 | - ); |
|
118 | - $items_actually_migrated = 0; |
|
119 | - foreach ($rows as $old_venue) { |
|
120 | - if (! $new_id = $this->_insert_into_posts($old_venue)) { |
|
121 | - $items_actually_migrated++; |
|
122 | - continue; |
|
123 | - } |
|
124 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id); |
|
125 | - if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) { |
|
126 | - $items_actually_migrated++; |
|
127 | - continue; |
|
128 | - } |
|
129 | - $this->get_migration_script()->set_mapping( |
|
130 | - $this->_old_table, |
|
131 | - $old_venue['id'], |
|
132 | - $this->_new_meta_table, |
|
133 | - $new_meta_id |
|
134 | - ); |
|
135 | - // lastly, save the 'contact' as post meta, because it doesn't exist anywhere else but someone may still want it |
|
136 | - $venue_meta = maybe_unserialize($old_venue['meta']); |
|
137 | - if (isset($venue_meta['contact']) && $venue_meta['contact']) { |
|
138 | - add_post_meta($new_id, 'contact', $venue_meta['contact']); |
|
139 | - } |
|
140 | - // is there an image on this venue? |
|
141 | - $guid = isset($venue_meta['image']) && $venue_meta['image'] ? $venue_meta['image'] : null; |
|
142 | - if ($guid) { |
|
143 | - $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post( |
|
144 | - $guid, |
|
145 | - $new_id, |
|
146 | - $this |
|
147 | - ); |
|
148 | - } |
|
149 | - $items_actually_migrated++; |
|
150 | - if ($guid) { |
|
151 | - // if there was an image, we may have had to download it etc and it may have taken |
|
152 | - // longer, then let's not bother migrating anymore on this step |
|
153 | - break; |
|
154 | - } |
|
155 | - } |
|
156 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
157 | - $this->set_completed(); |
|
158 | - } |
|
159 | - return $items_actually_migrated; |
|
160 | - } |
|
103 | + /** |
|
104 | + * @throws EE_Error |
|
105 | + */ |
|
106 | + public function _migration_step($num_items_to_migrate = 50) |
|
107 | + { |
|
108 | + global $wpdb; |
|
109 | + $start_at_record = $this->count_records_migrated(); |
|
110 | + $rows = $wpdb->get_results( |
|
111 | + $wpdb->prepare( |
|
112 | + "SELECT * FROM " . $this->_old_table . " LIMIT %d,%d", |
|
113 | + $start_at_record, |
|
114 | + $num_items_to_migrate |
|
115 | + ), |
|
116 | + ARRAY_A |
|
117 | + ); |
|
118 | + $items_actually_migrated = 0; |
|
119 | + foreach ($rows as $old_venue) { |
|
120 | + if (! $new_id = $this->_insert_into_posts($old_venue)) { |
|
121 | + $items_actually_migrated++; |
|
122 | + continue; |
|
123 | + } |
|
124 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id); |
|
125 | + if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) { |
|
126 | + $items_actually_migrated++; |
|
127 | + continue; |
|
128 | + } |
|
129 | + $this->get_migration_script()->set_mapping( |
|
130 | + $this->_old_table, |
|
131 | + $old_venue['id'], |
|
132 | + $this->_new_meta_table, |
|
133 | + $new_meta_id |
|
134 | + ); |
|
135 | + // lastly, save the 'contact' as post meta, because it doesn't exist anywhere else but someone may still want it |
|
136 | + $venue_meta = maybe_unserialize($old_venue['meta']); |
|
137 | + if (isset($venue_meta['contact']) && $venue_meta['contact']) { |
|
138 | + add_post_meta($new_id, 'contact', $venue_meta['contact']); |
|
139 | + } |
|
140 | + // is there an image on this venue? |
|
141 | + $guid = isset($venue_meta['image']) && $venue_meta['image'] ? $venue_meta['image'] : null; |
|
142 | + if ($guid) { |
|
143 | + $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post( |
|
144 | + $guid, |
|
145 | + $new_id, |
|
146 | + $this |
|
147 | + ); |
|
148 | + } |
|
149 | + $items_actually_migrated++; |
|
150 | + if ($guid) { |
|
151 | + // if there was an image, we may have had to download it etc and it may have taken |
|
152 | + // longer, then let's not bother migrating anymore on this step |
|
153 | + break; |
|
154 | + } |
|
155 | + } |
|
156 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
157 | + $this->set_completed(); |
|
158 | + } |
|
159 | + return $items_actually_migrated; |
|
160 | + } |
|
161 | 161 | |
162 | 162 | |
163 | - public function _count_records_to_migrate() |
|
164 | - { |
|
165 | - global $wpdb; |
|
166 | - return $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
167 | - } |
|
163 | + public function _count_records_to_migrate() |
|
164 | + { |
|
165 | + global $wpdb; |
|
166 | + return $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
167 | + } |
|
168 | 168 | |
169 | 169 | |
170 | - /** |
|
171 | - * Inserts the CPT |
|
172 | - * |
|
173 | - * @param array $old_venue keys are cols, values are col values |
|
174 | - * @return int |
|
175 | - */ |
|
176 | - private function _insert_into_posts(array $old_venue): int |
|
177 | - { |
|
178 | - global $wpdb; |
|
179 | - $meta = maybe_unserialize($old_venue['meta']); |
|
180 | - $slug = $this->_find_unique_slug($old_venue['name'], $old_venue['identifier']); |
|
181 | - $insertion_array = [ |
|
182 | - 'post_title' => stripslashes($old_venue['name']), |
|
183 | - // VNU_name |
|
184 | - 'post_content' => isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '', |
|
185 | - // VNU_desc |
|
186 | - 'post_name' => $slug, |
|
187 | - // VNU_identifier |
|
188 | - 'post_date' => current_time('mysql'), |
|
189 | - // VNU_created |
|
190 | - 'post_date_gmt' => current_time('mysql', true), |
|
191 | - 'post_excerpt' => '', |
|
192 | - // wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitrary only 50 characters |
|
193 | - 'post_modified' => current_time('mysql'), |
|
194 | - // VNU_modified |
|
195 | - 'post_modified_gmt' => current_time('mysql', true), |
|
196 | - 'post_author' => $old_venue['wp_user'], |
|
197 | - // VNU_wp_user |
|
198 | - 'post_parent' => 0, |
|
199 | - // parent |
|
200 | - 'menu_order' => 0, |
|
201 | - // VNU_order |
|
202 | - 'post_type' => 'espresso_venues', |
|
203 | - // post_type |
|
204 | - ]; |
|
205 | - $data_types_array = [ |
|
206 | - '%s',// VNU_name |
|
207 | - '%s',// VNU_desc |
|
208 | - '%s',// VNU_identifier |
|
209 | - '%s',// VNU_created |
|
210 | - '%s', |
|
211 | - '%s',// VNU_short_desc |
|
212 | - '%s',// VNU_modified |
|
213 | - '%s', |
|
214 | - '%d',// VNU_wp_user |
|
215 | - '%d',// parent |
|
216 | - '%d',// VNU_order |
|
217 | - '%s',// post_type |
|
218 | - ]; |
|
219 | - $success = $wpdb->insert( |
|
220 | - $this->_new_table, |
|
221 | - $insertion_array, |
|
222 | - $data_types_array |
|
223 | - ); |
|
224 | - if (! $success) { |
|
225 | - $this->add_error( |
|
226 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
227 | - $this->_old_table, |
|
228 | - $old_venue, |
|
229 | - $this->_new_table, |
|
230 | - $insertion_array, |
|
231 | - $data_types_array |
|
232 | - ) |
|
233 | - ); |
|
234 | - return 0; |
|
235 | - } |
|
236 | - return $wpdb->insert_id; |
|
237 | - } |
|
170 | + /** |
|
171 | + * Inserts the CPT |
|
172 | + * |
|
173 | + * @param array $old_venue keys are cols, values are col values |
|
174 | + * @return int |
|
175 | + */ |
|
176 | + private function _insert_into_posts(array $old_venue): int |
|
177 | + { |
|
178 | + global $wpdb; |
|
179 | + $meta = maybe_unserialize($old_venue['meta']); |
|
180 | + $slug = $this->_find_unique_slug($old_venue['name'], $old_venue['identifier']); |
|
181 | + $insertion_array = [ |
|
182 | + 'post_title' => stripslashes($old_venue['name']), |
|
183 | + // VNU_name |
|
184 | + 'post_content' => isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '', |
|
185 | + // VNU_desc |
|
186 | + 'post_name' => $slug, |
|
187 | + // VNU_identifier |
|
188 | + 'post_date' => current_time('mysql'), |
|
189 | + // VNU_created |
|
190 | + 'post_date_gmt' => current_time('mysql', true), |
|
191 | + 'post_excerpt' => '', |
|
192 | + // wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitrary only 50 characters |
|
193 | + 'post_modified' => current_time('mysql'), |
|
194 | + // VNU_modified |
|
195 | + 'post_modified_gmt' => current_time('mysql', true), |
|
196 | + 'post_author' => $old_venue['wp_user'], |
|
197 | + // VNU_wp_user |
|
198 | + 'post_parent' => 0, |
|
199 | + // parent |
|
200 | + 'menu_order' => 0, |
|
201 | + // VNU_order |
|
202 | + 'post_type' => 'espresso_venues', |
|
203 | + // post_type |
|
204 | + ]; |
|
205 | + $data_types_array = [ |
|
206 | + '%s',// VNU_name |
|
207 | + '%s',// VNU_desc |
|
208 | + '%s',// VNU_identifier |
|
209 | + '%s',// VNU_created |
|
210 | + '%s', |
|
211 | + '%s',// VNU_short_desc |
|
212 | + '%s',// VNU_modified |
|
213 | + '%s', |
|
214 | + '%d',// VNU_wp_user |
|
215 | + '%d',// parent |
|
216 | + '%d',// VNU_order |
|
217 | + '%s',// post_type |
|
218 | + ]; |
|
219 | + $success = $wpdb->insert( |
|
220 | + $this->_new_table, |
|
221 | + $insertion_array, |
|
222 | + $data_types_array |
|
223 | + ); |
|
224 | + if (! $success) { |
|
225 | + $this->add_error( |
|
226 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
227 | + $this->_old_table, |
|
228 | + $old_venue, |
|
229 | + $this->_new_table, |
|
230 | + $insertion_array, |
|
231 | + $data_types_array |
|
232 | + ) |
|
233 | + ); |
|
234 | + return 0; |
|
235 | + } |
|
236 | + return $wpdb->insert_id; |
|
237 | + } |
|
238 | 238 | |
239 | 239 | |
240 | - /** |
|
241 | - * Finds a unique slug for this venue, given its name (we could have simply used |
|
242 | - * the old unique_identifier column, but it added a long string of seemingly random characters onto the end |
|
243 | - * and really wasn't that pretty for a slug, so we decided we'd make our own slug again) |
|
244 | - * |
|
245 | - * @param string $post_name |
|
246 | - * @param string $old_identifier |
|
247 | - * @return string |
|
248 | - */ |
|
249 | - private function _find_unique_slug(string $post_name, string $old_identifier = ''): string |
|
250 | - { |
|
251 | - $count = 0; |
|
252 | - $original_name = $post_name ? sanitize_title($post_name) : $old_identifier; |
|
253 | - $event_slug = $original_name; |
|
254 | - while ($this->_other_post_exists_with_that_slug($event_slug) && $count < 50) { |
|
255 | - $event_slug = sanitize_title($original_name . "-" . ++$count); |
|
256 | - } |
|
257 | - return $event_slug; |
|
258 | - } |
|
240 | + /** |
|
241 | + * Finds a unique slug for this venue, given its name (we could have simply used |
|
242 | + * the old unique_identifier column, but it added a long string of seemingly random characters onto the end |
|
243 | + * and really wasn't that pretty for a slug, so we decided we'd make our own slug again) |
|
244 | + * |
|
245 | + * @param string $post_name |
|
246 | + * @param string $old_identifier |
|
247 | + * @return string |
|
248 | + */ |
|
249 | + private function _find_unique_slug(string $post_name, string $old_identifier = ''): string |
|
250 | + { |
|
251 | + $count = 0; |
|
252 | + $original_name = $post_name ? sanitize_title($post_name) : $old_identifier; |
|
253 | + $event_slug = $original_name; |
|
254 | + while ($this->_other_post_exists_with_that_slug($event_slug) && $count < 50) { |
|
255 | + $event_slug = sanitize_title($original_name . "-" . ++$count); |
|
256 | + } |
|
257 | + return $event_slug; |
|
258 | + } |
|
259 | 259 | |
260 | 260 | |
261 | - /** |
|
262 | - * returns whether there is a post that has this same slug (post_title) |
|
263 | - * |
|
264 | - * @param string $slug |
|
265 | - * @return boolean |
|
266 | - * @global wpdb $wpdb |
|
267 | - */ |
|
268 | - private function _other_post_exists_with_that_slug(string $slug): bool |
|
269 | - { |
|
270 | - global $wpdb; |
|
271 | - return (bool) $wpdb->get_var( |
|
272 | - $wpdb->prepare( |
|
273 | - "SELECT COUNT(ID) FROM " . $this->_new_table . " WHERE post_name = %s", |
|
274 | - $slug |
|
275 | - ) |
|
276 | - ); |
|
277 | - } |
|
261 | + /** |
|
262 | + * returns whether there is a post that has this same slug (post_title) |
|
263 | + * |
|
264 | + * @param string $slug |
|
265 | + * @return boolean |
|
266 | + * @global wpdb $wpdb |
|
267 | + */ |
|
268 | + private function _other_post_exists_with_that_slug(string $slug): bool |
|
269 | + { |
|
270 | + global $wpdb; |
|
271 | + return (bool) $wpdb->get_var( |
|
272 | + $wpdb->prepare( |
|
273 | + "SELECT COUNT(ID) FROM " . $this->_new_table . " WHERE post_name = %s", |
|
274 | + $slug |
|
275 | + ) |
|
276 | + ); |
|
277 | + } |
|
278 | 278 | |
279 | 279 | |
280 | - /** |
|
281 | - * Inserts into the venue_meta table |
|
282 | - * |
|
283 | - * @param int $VNU_ID |
|
284 | - * @param array $old_venue |
|
285 | - * @return int |
|
286 | - */ |
|
287 | - private function _insert_into_meta_table(int $VNU_ID, array $old_venue): int |
|
288 | - { |
|
289 | - global $wpdb; |
|
290 | - // get a country with the same name, or insert one |
|
291 | - try { |
|
292 | - $country = $this->get_migration_script()->get_or_create_country( |
|
293 | - stripslashes($old_venue['country']) |
|
294 | - ); |
|
295 | - $country_iso = $country['CNT_ISO']; |
|
296 | - } catch (EE_Error $e) { |
|
297 | - $this->add_error( |
|
298 | - sprintf( |
|
299 | - esc_html__("%s for venue %s", "event_espresso"), |
|
300 | - $e->getMessage(), |
|
301 | - $this->_json_encode($old_venue) |
|
302 | - ) |
|
303 | - ); |
|
304 | - $country_iso = null; |
|
305 | - } |
|
306 | - // get a state with the same name, if possible |
|
307 | - try { |
|
308 | - $state = $this->get_migration_script()->get_or_create_state( |
|
309 | - stripslashes($old_venue['state']), |
|
310 | - $country['CNT_name'] ?? strip_tags((string) $old_venue['country']) |
|
311 | - ); |
|
312 | - $state_id = $state['STA_ID']; |
|
313 | - } catch (EE_Error $e) { |
|
314 | - $this->add_error( |
|
315 | - sprintf( |
|
316 | - esc_html__("%s for venue %s", "event_espresso"), |
|
317 | - $e->getMessage(), |
|
318 | - $this->_json_encode($old_venue) |
|
319 | - ) |
|
320 | - ); |
|
321 | - $state_id = 0; |
|
322 | - } |
|
323 | - $meta = maybe_unserialize($old_venue['meta']); |
|
324 | - // now insert into meta table |
|
325 | - $insertion_array = [ |
|
326 | - 'VNU_ID' => $VNU_ID,// VNU_ID_fk |
|
327 | - 'VNU_address' => stripslashes($old_venue['address']),// VNU_address |
|
328 | - 'VNU_address2' => stripslashes($old_venue['address2']),// VNU_address2 |
|
329 | - 'VNU_city' => stripslashes($old_venue['city']),// VNU_city |
|
330 | - 'STA_ID' => $state_id,// STA_ID |
|
331 | - 'CNT_ISO' => $country_iso,// CNT_ISO |
|
332 | - 'VNU_zip' => stripslashes($old_venue['zip']),// VNU_zip |
|
333 | - 'VNU_phone' => isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone |
|
334 | - 'VNU_capacity' => -1,// VNU_capacity |
|
335 | - 'VNU_url' => isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url |
|
336 | - 'VNU_virtual_phone' => '',// VNU_virtual_phone |
|
337 | - 'VNU_virtual_url' => '',// VNU_virtual_url |
|
338 | - 'VNU_google_map_link' => '',// VNU_google_map_link |
|
339 | - 'VNU_enable_for_gmap' => true, // VNU_enable_for_gmap |
|
340 | - ]; |
|
341 | - $data_types = [ |
|
342 | - '%d',// VNU_ID_fk |
|
343 | - '%s',// VNU_address |
|
344 | - '%s',// VNU_address2 |
|
345 | - '%s',// VNU_city |
|
346 | - '%d',// STA_ID |
|
347 | - '%s',// CNT_ISO |
|
348 | - '%s',// VNU_zip |
|
349 | - '%s',// VNU_phone |
|
350 | - '%d',// VNU_capacity |
|
351 | - '%s',// VNU_url |
|
352 | - '%s',// VNU_virtual_phone |
|
353 | - '%s',// VNU_virtual_url |
|
354 | - '%s',// VNU_google_map_link |
|
355 | - '%d',// VNU_enable_for_gmap |
|
356 | - ]; |
|
357 | - $success = $wpdb->insert($this->_new_meta_table, $insertion_array, $data_types); |
|
358 | - if (! $success) { |
|
359 | - $this->add_error( |
|
360 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
361 | - $this->_old_table, |
|
362 | - $old_venue, |
|
363 | - $this->_new_meta_table, |
|
364 | - $insertion_array, |
|
365 | - $data_types |
|
366 | - ) |
|
367 | - ); |
|
368 | - return 0; |
|
369 | - } |
|
370 | - return $wpdb->insert_id; |
|
371 | - } |
|
280 | + /** |
|
281 | + * Inserts into the venue_meta table |
|
282 | + * |
|
283 | + * @param int $VNU_ID |
|
284 | + * @param array $old_venue |
|
285 | + * @return int |
|
286 | + */ |
|
287 | + private function _insert_into_meta_table(int $VNU_ID, array $old_venue): int |
|
288 | + { |
|
289 | + global $wpdb; |
|
290 | + // get a country with the same name, or insert one |
|
291 | + try { |
|
292 | + $country = $this->get_migration_script()->get_or_create_country( |
|
293 | + stripslashes($old_venue['country']) |
|
294 | + ); |
|
295 | + $country_iso = $country['CNT_ISO']; |
|
296 | + } catch (EE_Error $e) { |
|
297 | + $this->add_error( |
|
298 | + sprintf( |
|
299 | + esc_html__("%s for venue %s", "event_espresso"), |
|
300 | + $e->getMessage(), |
|
301 | + $this->_json_encode($old_venue) |
|
302 | + ) |
|
303 | + ); |
|
304 | + $country_iso = null; |
|
305 | + } |
|
306 | + // get a state with the same name, if possible |
|
307 | + try { |
|
308 | + $state = $this->get_migration_script()->get_or_create_state( |
|
309 | + stripslashes($old_venue['state']), |
|
310 | + $country['CNT_name'] ?? strip_tags((string) $old_venue['country']) |
|
311 | + ); |
|
312 | + $state_id = $state['STA_ID']; |
|
313 | + } catch (EE_Error $e) { |
|
314 | + $this->add_error( |
|
315 | + sprintf( |
|
316 | + esc_html__("%s for venue %s", "event_espresso"), |
|
317 | + $e->getMessage(), |
|
318 | + $this->_json_encode($old_venue) |
|
319 | + ) |
|
320 | + ); |
|
321 | + $state_id = 0; |
|
322 | + } |
|
323 | + $meta = maybe_unserialize($old_venue['meta']); |
|
324 | + // now insert into meta table |
|
325 | + $insertion_array = [ |
|
326 | + 'VNU_ID' => $VNU_ID,// VNU_ID_fk |
|
327 | + 'VNU_address' => stripslashes($old_venue['address']),// VNU_address |
|
328 | + 'VNU_address2' => stripslashes($old_venue['address2']),// VNU_address2 |
|
329 | + 'VNU_city' => stripslashes($old_venue['city']),// VNU_city |
|
330 | + 'STA_ID' => $state_id,// STA_ID |
|
331 | + 'CNT_ISO' => $country_iso,// CNT_ISO |
|
332 | + 'VNU_zip' => stripslashes($old_venue['zip']),// VNU_zip |
|
333 | + 'VNU_phone' => isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone |
|
334 | + 'VNU_capacity' => -1,// VNU_capacity |
|
335 | + 'VNU_url' => isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url |
|
336 | + 'VNU_virtual_phone' => '',// VNU_virtual_phone |
|
337 | + 'VNU_virtual_url' => '',// VNU_virtual_url |
|
338 | + 'VNU_google_map_link' => '',// VNU_google_map_link |
|
339 | + 'VNU_enable_for_gmap' => true, // VNU_enable_for_gmap |
|
340 | + ]; |
|
341 | + $data_types = [ |
|
342 | + '%d',// VNU_ID_fk |
|
343 | + '%s',// VNU_address |
|
344 | + '%s',// VNU_address2 |
|
345 | + '%s',// VNU_city |
|
346 | + '%d',// STA_ID |
|
347 | + '%s',// CNT_ISO |
|
348 | + '%s',// VNU_zip |
|
349 | + '%s',// VNU_phone |
|
350 | + '%d',// VNU_capacity |
|
351 | + '%s',// VNU_url |
|
352 | + '%s',// VNU_virtual_phone |
|
353 | + '%s',// VNU_virtual_url |
|
354 | + '%s',// VNU_google_map_link |
|
355 | + '%d',// VNU_enable_for_gmap |
|
356 | + ]; |
|
357 | + $success = $wpdb->insert($this->_new_meta_table, $insertion_array, $data_types); |
|
358 | + if (! $success) { |
|
359 | + $this->add_error( |
|
360 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
361 | + $this->_old_table, |
|
362 | + $old_venue, |
|
363 | + $this->_new_meta_table, |
|
364 | + $insertion_array, |
|
365 | + $data_types |
|
366 | + ) |
|
367 | + ); |
|
368 | + return 0; |
|
369 | + } |
|
370 | + return $wpdb->insert_id; |
|
371 | + } |
|
372 | 372 | } |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | { |
94 | 94 | $this->_pretty_name = esc_html__("Venues", "event_espresso"); |
95 | 95 | global $wpdb; |
96 | - $this->_old_table = $wpdb->prefix . "events_venue"; |
|
96 | + $this->_old_table = $wpdb->prefix."events_venue"; |
|
97 | 97 | $this->_new_table = $wpdb->posts; |
98 | - $this->_new_meta_table = $wpdb->prefix . "esp_venue_meta"; |
|
98 | + $this->_new_meta_table = $wpdb->prefix."esp_venue_meta"; |
|
99 | 99 | parent::__construct(); |
100 | 100 | } |
101 | 101 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $start_at_record = $this->count_records_migrated(); |
110 | 110 | $rows = $wpdb->get_results( |
111 | 111 | $wpdb->prepare( |
112 | - "SELECT * FROM " . $this->_old_table . " LIMIT %d,%d", |
|
112 | + "SELECT * FROM ".$this->_old_table." LIMIT %d,%d", |
|
113 | 113 | $start_at_record, |
114 | 114 | $num_items_to_migrate |
115 | 115 | ), |
@@ -117,12 +117,12 @@ discard block |
||
117 | 117 | ); |
118 | 118 | $items_actually_migrated = 0; |
119 | 119 | foreach ($rows as $old_venue) { |
120 | - if (! $new_id = $this->_insert_into_posts($old_venue)) { |
|
120 | + if ( ! $new_id = $this->_insert_into_posts($old_venue)) { |
|
121 | 121 | $items_actually_migrated++; |
122 | 122 | continue; |
123 | 123 | } |
124 | 124 | $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id); |
125 | - if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) { |
|
125 | + if ( ! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) { |
|
126 | 126 | $items_actually_migrated++; |
127 | 127 | continue; |
128 | 128 | } |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | public function _count_records_to_migrate() |
164 | 164 | { |
165 | 165 | global $wpdb; |
166 | - return $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
166 | + return $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | |
@@ -203,25 +203,25 @@ discard block |
||
203 | 203 | // post_type |
204 | 204 | ]; |
205 | 205 | $data_types_array = [ |
206 | - '%s',// VNU_name |
|
207 | - '%s',// VNU_desc |
|
208 | - '%s',// VNU_identifier |
|
209 | - '%s',// VNU_created |
|
206 | + '%s', // VNU_name |
|
207 | + '%s', // VNU_desc |
|
208 | + '%s', // VNU_identifier |
|
209 | + '%s', // VNU_created |
|
210 | 210 | '%s', |
211 | - '%s',// VNU_short_desc |
|
212 | - '%s',// VNU_modified |
|
211 | + '%s', // VNU_short_desc |
|
212 | + '%s', // VNU_modified |
|
213 | 213 | '%s', |
214 | - '%d',// VNU_wp_user |
|
215 | - '%d',// parent |
|
216 | - '%d',// VNU_order |
|
217 | - '%s',// post_type |
|
214 | + '%d', // VNU_wp_user |
|
215 | + '%d', // parent |
|
216 | + '%d', // VNU_order |
|
217 | + '%s', // post_type |
|
218 | 218 | ]; |
219 | - $success = $wpdb->insert( |
|
219 | + $success = $wpdb->insert( |
|
220 | 220 | $this->_new_table, |
221 | 221 | $insertion_array, |
222 | 222 | $data_types_array |
223 | 223 | ); |
224 | - if (! $success) { |
|
224 | + if ( ! $success) { |
|
225 | 225 | $this->add_error( |
226 | 226 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
227 | 227 | $this->_old_table, |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | $original_name = $post_name ? sanitize_title($post_name) : $old_identifier; |
253 | 253 | $event_slug = $original_name; |
254 | 254 | while ($this->_other_post_exists_with_that_slug($event_slug) && $count < 50) { |
255 | - $event_slug = sanitize_title($original_name . "-" . ++$count); |
|
255 | + $event_slug = sanitize_title($original_name."-".++$count); |
|
256 | 256 | } |
257 | 257 | return $event_slug; |
258 | 258 | } |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | global $wpdb; |
271 | 271 | return (bool) $wpdb->get_var( |
272 | 272 | $wpdb->prepare( |
273 | - "SELECT COUNT(ID) FROM " . $this->_new_table . " WHERE post_name = %s", |
|
273 | + "SELECT COUNT(ID) FROM ".$this->_new_table." WHERE post_name = %s", |
|
274 | 274 | $slug |
275 | 275 | ) |
276 | 276 | ); |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | } |
306 | 306 | // get a state with the same name, if possible |
307 | 307 | try { |
308 | - $state = $this->get_migration_script()->get_or_create_state( |
|
308 | + $state = $this->get_migration_script()->get_or_create_state( |
|
309 | 309 | stripslashes($old_venue['state']), |
310 | 310 | $country['CNT_name'] ?? strip_tags((string) $old_venue['country']) |
311 | 311 | ); |
@@ -323,39 +323,39 @@ discard block |
||
323 | 323 | $meta = maybe_unserialize($old_venue['meta']); |
324 | 324 | // now insert into meta table |
325 | 325 | $insertion_array = [ |
326 | - 'VNU_ID' => $VNU_ID,// VNU_ID_fk |
|
327 | - 'VNU_address' => stripslashes($old_venue['address']),// VNU_address |
|
328 | - 'VNU_address2' => stripslashes($old_venue['address2']),// VNU_address2 |
|
329 | - 'VNU_city' => stripslashes($old_venue['city']),// VNU_city |
|
330 | - 'STA_ID' => $state_id,// STA_ID |
|
331 | - 'CNT_ISO' => $country_iso,// CNT_ISO |
|
332 | - 'VNU_zip' => stripslashes($old_venue['zip']),// VNU_zip |
|
333 | - 'VNU_phone' => isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone |
|
334 | - 'VNU_capacity' => -1,// VNU_capacity |
|
335 | - 'VNU_url' => isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url |
|
336 | - 'VNU_virtual_phone' => '',// VNU_virtual_phone |
|
337 | - 'VNU_virtual_url' => '',// VNU_virtual_url |
|
338 | - 'VNU_google_map_link' => '',// VNU_google_map_link |
|
326 | + 'VNU_ID' => $VNU_ID, // VNU_ID_fk |
|
327 | + 'VNU_address' => stripslashes($old_venue['address']), // VNU_address |
|
328 | + 'VNU_address2' => stripslashes($old_venue['address2']), // VNU_address2 |
|
329 | + 'VNU_city' => stripslashes($old_venue['city']), // VNU_city |
|
330 | + 'STA_ID' => $state_id, // STA_ID |
|
331 | + 'CNT_ISO' => $country_iso, // CNT_ISO |
|
332 | + 'VNU_zip' => stripslashes($old_venue['zip']), // VNU_zip |
|
333 | + 'VNU_phone' => isset($meta['phone']) ? stripslashes($meta['phone']) : '', // VNU_phone |
|
334 | + 'VNU_capacity' => -1, // VNU_capacity |
|
335 | + 'VNU_url' => isset($meta['website']) ? stripslashes($meta['website']) : '', // VNU_url |
|
336 | + 'VNU_virtual_phone' => '', // VNU_virtual_phone |
|
337 | + 'VNU_virtual_url' => '', // VNU_virtual_url |
|
338 | + 'VNU_google_map_link' => '', // VNU_google_map_link |
|
339 | 339 | 'VNU_enable_for_gmap' => true, // VNU_enable_for_gmap |
340 | 340 | ]; |
341 | - $data_types = [ |
|
342 | - '%d',// VNU_ID_fk |
|
343 | - '%s',// VNU_address |
|
344 | - '%s',// VNU_address2 |
|
345 | - '%s',// VNU_city |
|
346 | - '%d',// STA_ID |
|
347 | - '%s',// CNT_ISO |
|
348 | - '%s',// VNU_zip |
|
349 | - '%s',// VNU_phone |
|
350 | - '%d',// VNU_capacity |
|
351 | - '%s',// VNU_url |
|
352 | - '%s',// VNU_virtual_phone |
|
353 | - '%s',// VNU_virtual_url |
|
354 | - '%s',// VNU_google_map_link |
|
355 | - '%d',// VNU_enable_for_gmap |
|
341 | + $data_types = [ |
|
342 | + '%d', // VNU_ID_fk |
|
343 | + '%s', // VNU_address |
|
344 | + '%s', // VNU_address2 |
|
345 | + '%s', // VNU_city |
|
346 | + '%d', // STA_ID |
|
347 | + '%s', // CNT_ISO |
|
348 | + '%s', // VNU_zip |
|
349 | + '%s', // VNU_phone |
|
350 | + '%d', // VNU_capacity |
|
351 | + '%s', // VNU_url |
|
352 | + '%s', // VNU_virtual_phone |
|
353 | + '%s', // VNU_virtual_url |
|
354 | + '%s', // VNU_google_map_link |
|
355 | + '%d', // VNU_enable_for_gmap |
|
356 | 356 | ]; |
357 | - $success = $wpdb->insert($this->_new_meta_table, $insertion_array, $data_types); |
|
358 | - if (! $success) { |
|
357 | + $success = $wpdb->insert($this->_new_meta_table, $insertion_array, $data_types); |
|
358 | + if ( ! $success) { |
|
359 | 359 | $this->add_error( |
360 | 360 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
361 | 361 | $this->_old_table, |
@@ -27,186 +27,186 @@ |
||
27 | 27 | class EE_DMS_4_1_0_checkins extends EE_Data_Migration_Script_Stage_Table |
28 | 28 | { |
29 | 29 | |
30 | - public function __construct() |
|
31 | - { |
|
32 | - global $wpdb; |
|
33 | - $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
|
34 | - $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
35 | - $this->select_expression = 'att.*, e.event_status'; |
|
36 | - $this->_extra_where_sql = 'AS att |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + global $wpdb; |
|
33 | + $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
|
34 | + $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
35 | + $this->select_expression = 'att.*, e.event_status'; |
|
36 | + $this->_extra_where_sql = 'AS att |
|
37 | 37 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
38 | 38 | WHERE e.event_status!="D"'; |
39 | - $this->_new_table = $wpdb->prefix . "esp_checkin"; |
|
40 | - parent::__construct(); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @throws EE_Error |
|
46 | - */ |
|
47 | - protected function _migrate_old_row($old_row) |
|
48 | - { |
|
49 | - global $wpdb; |
|
50 | - $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
51 | - |
|
52 | - $num_to_checkin_at_this_time = max([intval($old_row['checked_in_quantity']), intval($old_row['checked_in'])]); |
|
53 | - |
|
54 | - $new_registrations_for_attendee = |
|
55 | - $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
56 | - if (! $new_registrations_for_attendee) { |
|
57 | - $new_registrations_for_attendee = []; |
|
58 | - } |
|
59 | - $new_datetime = $this->_try_to_find_datetime($old_row); |
|
60 | - |
|
61 | - // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
62 | - $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
63 | - $new_checkin_ids = []; |
|
64 | - for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
|
65 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
66 | - if (! $new_reg_id) { |
|
67 | - $this->add_error( |
|
68 | - sprintf( |
|
69 | - esc_html__( |
|
70 | - /* translators: %1$s database row represented in JSON, %2$s number of registrations to check in |
|
39 | + $this->_new_table = $wpdb->prefix . "esp_checkin"; |
|
40 | + parent::__construct(); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @throws EE_Error |
|
46 | + */ |
|
47 | + protected function _migrate_old_row($old_row) |
|
48 | + { |
|
49 | + global $wpdb; |
|
50 | + $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
51 | + |
|
52 | + $num_to_checkin_at_this_time = max([intval($old_row['checked_in_quantity']), intval($old_row['checked_in'])]); |
|
53 | + |
|
54 | + $new_registrations_for_attendee = |
|
55 | + $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
56 | + if (! $new_registrations_for_attendee) { |
|
57 | + $new_registrations_for_attendee = []; |
|
58 | + } |
|
59 | + $new_datetime = $this->_try_to_find_datetime($old_row); |
|
60 | + |
|
61 | + // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
62 | + $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
63 | + $new_checkin_ids = []; |
|
64 | + for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
|
65 | + $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
66 | + if (! $new_reg_id) { |
|
67 | + $this->add_error( |
|
68 | + sprintf( |
|
69 | + esc_html__( |
|
70 | + /* translators: %1$s database row represented in JSON, %2$s number of registrations to check in |
|
71 | 71 | * %3$s number of registrations for the attendee, %4$s new registration rows represented in JSON |
72 | 72 | */ |
73 | - // @codingStandardsIgnoreStart |
|
74 | - 'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', |
|
75 | - // @codingStandardsIgnoreEnd |
|
76 | - 'event_espresso' |
|
77 | - ), |
|
78 | - $this->_json_encode($old_row), |
|
79 | - abs($num_to_checkin_at_this_time), |
|
80 | - count($new_registrations_for_attendee), |
|
81 | - $this->_json_encode($new_registrations_for_attendee) |
|
82 | - ) |
|
83 | - ); |
|
84 | - break; |
|
85 | - } |
|
86 | - $existing_checkin_record = $wpdb->get_var( |
|
87 | - $wpdb->prepare( |
|
88 | - "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
89 | - $new_reg_id |
|
90 | - ) |
|
91 | - ); |
|
92 | - if (! $existing_checkin_record) { |
|
93 | - $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
94 | - if ($new_id) { |
|
95 | - $new_checkin_ids[] = $new_id; |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
99 | - if ($new_checkin_ids) { |
|
100 | - $this->get_migration_script()->set_mapping( |
|
101 | - $this->_old_table, |
|
102 | - $old_row['id'], |
|
103 | - $this->_new_table, |
|
104 | - $new_checkin_ids |
|
105 | - ); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
112 | - * (because we know the attendee was for an event as a specific time, and we know |
|
113 | - * the event's OLD ID...) |
|
114 | - * |
|
115 | - * @param array $old_attendee |
|
116 | - * @return array row of datetime from DB |
|
117 | - * @throws EE_Error |
|
118 | - * @global wpdb $wpdb |
|
119 | - */ |
|
120 | - private function _try_to_find_datetime(array $old_attendee): array |
|
121 | - { |
|
122 | - global $wpdb; |
|
123 | - |
|
124 | - $new_event_id = |
|
125 | - $this->get_migration_script()->get_mapping_new_pk( |
|
126 | - $wpdb->prefix . "events_detail", |
|
127 | - $old_attendee['event_id'], |
|
128 | - $wpdb->posts |
|
129 | - ); |
|
130 | - if (! $new_event_id) { |
|
131 | - $this->add_error( |
|
132 | - sprintf( |
|
133 | - esc_html__( |
|
134 | - /* translators: 1: original event ID, 2: original attendee database row */ |
|
135 | - // @codingStandardsIgnoreStart |
|
136 | - 'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in', |
|
137 | - // @codingStandardsIgnoreEnd |
|
138 | - 'event_espresso' |
|
139 | - ), |
|
140 | - $old_attendee['event_id'], |
|
141 | - $this->_json_encode($old_attendee) |
|
142 | - ) |
|
143 | - ); |
|
144 | - return []; |
|
145 | - } |
|
146 | - $old_att_start_date = $old_attendee['start_date']; |
|
147 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
148 | - $old_att_datetime = |
|
149 | - $this->get_migration_script()->convert_date_string_to_utc( |
|
150 | - $this, |
|
151 | - $old_attendee, |
|
152 | - "$old_att_start_date $old_att_start_time:00" |
|
153 | - ); |
|
154 | - |
|
155 | - $datetime_table = $wpdb->prefix . "esp_datetime"; |
|
156 | - // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
157 | - // the most important condition should be last, as it will be array_shift'ed off last |
|
158 | - $conditions = [ |
|
159 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
160 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
161 | - ]; |
|
162 | - // start running queries, widening search each time by removing a condition |
|
163 | - do { |
|
164 | - $full_query = "SELECT * FROM $datetime_table WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
165 | - $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
166 | - array_shift($conditions); |
|
167 | - } while (! $datetime_found && $conditions); |
|
168 | - return $datetime_found; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * Adds a new Check-in/checkout record according to $new_reg_id,$new_datetime_id,$checking_in, and $timestamp |
|
174 | - * |
|
175 | - * @param int $new_reg_id |
|
176 | - * @param array $new_datetime |
|
177 | - * @return int new Check-in id |
|
178 | - */ |
|
179 | - private function _insert_checkin_record(int $new_reg_id, array $new_datetime): int |
|
180 | - { |
|
181 | - global $wpdb; |
|
182 | - |
|
183 | - |
|
184 | - // ok we can actually do what we set out to do: add a checkin/checkout record |
|
185 | - $cols_n_values = [ |
|
186 | - 'REG_ID' => $new_reg_id, |
|
187 | - 'DTT_ID' => $new_datetime['DTT_ID'] ?? 0, |
|
188 | - 'CHK_in' => true, |
|
189 | - 'CHK_timestamp' => $new_datetime['DTT_EVT_start'] ?? null, |
|
190 | - ]; |
|
191 | - $data_types = [ |
|
192 | - '%d',// REG_ID |
|
193 | - '%d',// DTT_ID |
|
194 | - '%d',// CHK_in |
|
195 | - '%s',// CHK_timestamp |
|
196 | - ]; |
|
197 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
198 | - if (! $success) { |
|
199 | - $this->add_error( |
|
200 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
201 | - $this->_old_table, |
|
202 | - [], |
|
203 | - $this->_new_table, |
|
204 | - $cols_n_values, |
|
205 | - $data_types |
|
206 | - ) |
|
207 | - ); |
|
208 | - return 0; |
|
209 | - } |
|
210 | - return $wpdb->insert_id; |
|
211 | - } |
|
73 | + // @codingStandardsIgnoreStart |
|
74 | + 'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', |
|
75 | + // @codingStandardsIgnoreEnd |
|
76 | + 'event_espresso' |
|
77 | + ), |
|
78 | + $this->_json_encode($old_row), |
|
79 | + abs($num_to_checkin_at_this_time), |
|
80 | + count($new_registrations_for_attendee), |
|
81 | + $this->_json_encode($new_registrations_for_attendee) |
|
82 | + ) |
|
83 | + ); |
|
84 | + break; |
|
85 | + } |
|
86 | + $existing_checkin_record = $wpdb->get_var( |
|
87 | + $wpdb->prepare( |
|
88 | + "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
89 | + $new_reg_id |
|
90 | + ) |
|
91 | + ); |
|
92 | + if (! $existing_checkin_record) { |
|
93 | + $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
94 | + if ($new_id) { |
|
95 | + $new_checkin_ids[] = $new_id; |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | + if ($new_checkin_ids) { |
|
100 | + $this->get_migration_script()->set_mapping( |
|
101 | + $this->_old_table, |
|
102 | + $old_row['id'], |
|
103 | + $this->_new_table, |
|
104 | + $new_checkin_ids |
|
105 | + ); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
112 | + * (because we know the attendee was for an event as a specific time, and we know |
|
113 | + * the event's OLD ID...) |
|
114 | + * |
|
115 | + * @param array $old_attendee |
|
116 | + * @return array row of datetime from DB |
|
117 | + * @throws EE_Error |
|
118 | + * @global wpdb $wpdb |
|
119 | + */ |
|
120 | + private function _try_to_find_datetime(array $old_attendee): array |
|
121 | + { |
|
122 | + global $wpdb; |
|
123 | + |
|
124 | + $new_event_id = |
|
125 | + $this->get_migration_script()->get_mapping_new_pk( |
|
126 | + $wpdb->prefix . "events_detail", |
|
127 | + $old_attendee['event_id'], |
|
128 | + $wpdb->posts |
|
129 | + ); |
|
130 | + if (! $new_event_id) { |
|
131 | + $this->add_error( |
|
132 | + sprintf( |
|
133 | + esc_html__( |
|
134 | + /* translators: 1: original event ID, 2: original attendee database row */ |
|
135 | + // @codingStandardsIgnoreStart |
|
136 | + 'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in', |
|
137 | + // @codingStandardsIgnoreEnd |
|
138 | + 'event_espresso' |
|
139 | + ), |
|
140 | + $old_attendee['event_id'], |
|
141 | + $this->_json_encode($old_attendee) |
|
142 | + ) |
|
143 | + ); |
|
144 | + return []; |
|
145 | + } |
|
146 | + $old_att_start_date = $old_attendee['start_date']; |
|
147 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
148 | + $old_att_datetime = |
|
149 | + $this->get_migration_script()->convert_date_string_to_utc( |
|
150 | + $this, |
|
151 | + $old_attendee, |
|
152 | + "$old_att_start_date $old_att_start_time:00" |
|
153 | + ); |
|
154 | + |
|
155 | + $datetime_table = $wpdb->prefix . "esp_datetime"; |
|
156 | + // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
157 | + // the most important condition should be last, as it will be array_shift'ed off last |
|
158 | + $conditions = [ |
|
159 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
160 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
161 | + ]; |
|
162 | + // start running queries, widening search each time by removing a condition |
|
163 | + do { |
|
164 | + $full_query = "SELECT * FROM $datetime_table WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
165 | + $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
166 | + array_shift($conditions); |
|
167 | + } while (! $datetime_found && $conditions); |
|
168 | + return $datetime_found; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * Adds a new Check-in/checkout record according to $new_reg_id,$new_datetime_id,$checking_in, and $timestamp |
|
174 | + * |
|
175 | + * @param int $new_reg_id |
|
176 | + * @param array $new_datetime |
|
177 | + * @return int new Check-in id |
|
178 | + */ |
|
179 | + private function _insert_checkin_record(int $new_reg_id, array $new_datetime): int |
|
180 | + { |
|
181 | + global $wpdb; |
|
182 | + |
|
183 | + |
|
184 | + // ok we can actually do what we set out to do: add a checkin/checkout record |
|
185 | + $cols_n_values = [ |
|
186 | + 'REG_ID' => $new_reg_id, |
|
187 | + 'DTT_ID' => $new_datetime['DTT_ID'] ?? 0, |
|
188 | + 'CHK_in' => true, |
|
189 | + 'CHK_timestamp' => $new_datetime['DTT_EVT_start'] ?? null, |
|
190 | + ]; |
|
191 | + $data_types = [ |
|
192 | + '%d',// REG_ID |
|
193 | + '%d',// DTT_ID |
|
194 | + '%d',// CHK_in |
|
195 | + '%s',// CHK_timestamp |
|
196 | + ]; |
|
197 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
198 | + if (! $success) { |
|
199 | + $this->add_error( |
|
200 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
201 | + $this->_old_table, |
|
202 | + [], |
|
203 | + $this->_new_table, |
|
204 | + $cols_n_values, |
|
205 | + $data_types |
|
206 | + ) |
|
207 | + ); |
|
208 | + return 0; |
|
209 | + } |
|
210 | + return $wpdb->insert_id; |
|
211 | + } |
|
212 | 212 | } |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | { |
32 | 32 | global $wpdb; |
33 | 33 | $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
34 | - $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
34 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
35 | 35 | $this->select_expression = 'att.*, e.event_status'; |
36 | 36 | $this->_extra_where_sql = 'AS att |
37 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
37 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
38 | 38 | WHERE e.event_status!="D"'; |
39 | - $this->_new_table = $wpdb->prefix . "esp_checkin"; |
|
39 | + $this->_new_table = $wpdb->prefix."esp_checkin"; |
|
40 | 40 | parent::__construct(); |
41 | 41 | } |
42 | 42 | |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | protected function _migrate_old_row($old_row) |
48 | 48 | { |
49 | 49 | global $wpdb; |
50 | - $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
50 | + $new_reg_table = $wpdb->prefix."esp_registration"; |
|
51 | 51 | |
52 | 52 | $num_to_checkin_at_this_time = max([intval($old_row['checked_in_quantity']), intval($old_row['checked_in'])]); |
53 | 53 | |
54 | 54 | $new_registrations_for_attendee = |
55 | 55 | $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
56 | - if (! $new_registrations_for_attendee) { |
|
56 | + if ( ! $new_registrations_for_attendee) { |
|
57 | 57 | $new_registrations_for_attendee = []; |
58 | 58 | } |
59 | 59 | $new_datetime = $this->_try_to_find_datetime($old_row); |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
63 | 63 | $new_checkin_ids = []; |
64 | 64 | for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
65 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
66 | - if (! $new_reg_id) { |
|
65 | + $new_reg_id = $new_registrations_for_attendee[$i]; |
|
66 | + if ( ! $new_reg_id) { |
|
67 | 67 | $this->add_error( |
68 | 68 | sprintf( |
69 | 69 | esc_html__( |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $new_reg_id |
90 | 90 | ) |
91 | 91 | ); |
92 | - if (! $existing_checkin_record) { |
|
92 | + if ( ! $existing_checkin_record) { |
|
93 | 93 | $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
94 | 94 | if ($new_id) { |
95 | 95 | $new_checkin_ids[] = $new_id; |
@@ -123,11 +123,11 @@ discard block |
||
123 | 123 | |
124 | 124 | $new_event_id = |
125 | 125 | $this->get_migration_script()->get_mapping_new_pk( |
126 | - $wpdb->prefix . "events_detail", |
|
126 | + $wpdb->prefix."events_detail", |
|
127 | 127 | $old_attendee['event_id'], |
128 | 128 | $wpdb->posts |
129 | 129 | ); |
130 | - if (! $new_event_id) { |
|
130 | + if ( ! $new_event_id) { |
|
131 | 131 | $this->add_error( |
132 | 132 | sprintf( |
133 | 133 | esc_html__( |
@@ -152,19 +152,19 @@ discard block |
||
152 | 152 | "$old_att_start_date $old_att_start_time:00" |
153 | 153 | ); |
154 | 154 | |
155 | - $datetime_table = $wpdb->prefix . "esp_datetime"; |
|
155 | + $datetime_table = $wpdb->prefix."esp_datetime"; |
|
156 | 156 | // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
157 | 157 | // the most important condition should be last, as it will be array_shift'ed off last |
158 | 158 | $conditions = [ |
159 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
160 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
159 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match? |
|
160 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match? |
|
161 | 161 | ]; |
162 | 162 | // start running queries, widening search each time by removing a condition |
163 | 163 | do { |
164 | - $full_query = "SELECT * FROM $datetime_table WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
164 | + $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
165 | 165 | $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
166 | 166 | array_shift($conditions); |
167 | - } while (! $datetime_found && $conditions); |
|
167 | + }while ( ! $datetime_found && $conditions); |
|
168 | 168 | return $datetime_found; |
169 | 169 | } |
170 | 170 | |
@@ -188,14 +188,14 @@ discard block |
||
188 | 188 | 'CHK_in' => true, |
189 | 189 | 'CHK_timestamp' => $new_datetime['DTT_EVT_start'] ?? null, |
190 | 190 | ]; |
191 | - $data_types = [ |
|
192 | - '%d',// REG_ID |
|
193 | - '%d',// DTT_ID |
|
194 | - '%d',// CHK_in |
|
195 | - '%s',// CHK_timestamp |
|
191 | + $data_types = [ |
|
192 | + '%d', // REG_ID |
|
193 | + '%d', // DTT_ID |
|
194 | + '%d', // CHK_in |
|
195 | + '%s', // CHK_timestamp |
|
196 | 196 | ]; |
197 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
198 | - if (! $success) { |
|
197 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
198 | + if ( ! $success) { |
|
199 | 199 | $this->add_error( |
200 | 200 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
201 | 201 | $this->_old_table, |
@@ -28,162 +28,162 @@ |
||
28 | 28 | class EE_DMS_4_1_0_question_group_question extends EE_Data_Migration_Script_Stage |
29 | 29 | { |
30 | 30 | |
31 | - public function __construct() |
|
32 | - { |
|
33 | - global $wpdb; |
|
34 | - $this->_old_table = $wpdb->prefix . "events_qst_group_rel"; |
|
35 | - $this->_new_table = $wpdb->prefix . "esp_question_group_question"; |
|
36 | - $this->_pretty_name = esc_html__("Question Group to Question Relations", "event_espresso"); |
|
37 | - parent::__construct(); |
|
38 | - } |
|
31 | + public function __construct() |
|
32 | + { |
|
33 | + global $wpdb; |
|
34 | + $this->_old_table = $wpdb->prefix . "events_qst_group_rel"; |
|
35 | + $this->_new_table = $wpdb->prefix . "esp_question_group_question"; |
|
36 | + $this->_pretty_name = esc_html__("Question Group to Question Relations", "event_espresso"); |
|
37 | + parent::__construct(); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @throws EE_Error |
|
43 | - */ |
|
44 | - public function _migration_step($num_items_to_migrate = 50) |
|
45 | - { |
|
46 | - global $wpdb; |
|
47 | - $start_at_record = $this->count_records_migrated(); |
|
48 | - $rows = $wpdb->get_results( |
|
49 | - $wpdb->prepare( |
|
50 | - "SELECT * FROM $this->_old_table LIMIT %d,%d", |
|
51 | - $start_at_record, |
|
52 | - $num_items_to_migrate |
|
53 | - ), |
|
54 | - ARRAY_A |
|
55 | - ); |
|
56 | - $items_actually_migrated = 0; |
|
57 | - foreach ($rows as $question_group_question) { |
|
58 | - $this->_insert_new_question_group_question($question_group_question); |
|
59 | - $items_actually_migrated++; |
|
60 | - } |
|
61 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
62 | - $this->set_completed(); |
|
63 | - } |
|
64 | - return $items_actually_migrated; |
|
65 | - } |
|
41 | + /** |
|
42 | + * @throws EE_Error |
|
43 | + */ |
|
44 | + public function _migration_step($num_items_to_migrate = 50) |
|
45 | + { |
|
46 | + global $wpdb; |
|
47 | + $start_at_record = $this->count_records_migrated(); |
|
48 | + $rows = $wpdb->get_results( |
|
49 | + $wpdb->prepare( |
|
50 | + "SELECT * FROM $this->_old_table LIMIT %d,%d", |
|
51 | + $start_at_record, |
|
52 | + $num_items_to_migrate |
|
53 | + ), |
|
54 | + ARRAY_A |
|
55 | + ); |
|
56 | + $items_actually_migrated = 0; |
|
57 | + foreach ($rows as $question_group_question) { |
|
58 | + $this->_insert_new_question_group_question($question_group_question); |
|
59 | + $items_actually_migrated++; |
|
60 | + } |
|
61 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
62 | + $this->set_completed(); |
|
63 | + } |
|
64 | + return $items_actually_migrated; |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - public function _count_records_to_migrate() |
|
69 | - { |
|
70 | - global $wpdb; |
|
71 | - return $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
72 | - } |
|
68 | + public function _count_records_to_migrate() |
|
69 | + { |
|
70 | + global $wpdb; |
|
71 | + return $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
72 | + } |
|
73 | 73 | |
74 | 74 | |
75 | - /** |
|
76 | - * Attempts to insert a new question group in the new format given an old one |
|
77 | - * |
|
78 | - * @param array $old_question_group_question |
|
79 | - * @return void |
|
80 | - * @throws EE_Error |
|
81 | - * @global wpdb $wpdb |
|
82 | - */ |
|
83 | - private function _insert_new_question_group_question(array $old_question_group_question): void |
|
84 | - { |
|
85 | - global $wpdb; |
|
86 | - $new_question_id = $this->get_migration_script()->get_mapping_new_pk( |
|
87 | - $wpdb->prefix . "events_question", |
|
88 | - $old_question_group_question['question_id'], |
|
89 | - $wpdb->prefix . "esp_question" |
|
90 | - ); |
|
91 | - $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk( |
|
92 | - $wpdb->prefix . "events_qst_group", |
|
93 | - $old_question_group_question['group_id'], |
|
94 | - $wpdb->prefix . "esp_question_group" |
|
95 | - ); |
|
96 | - if (! $new_question_id) { |
|
97 | - $this->add_error( |
|
98 | - sprintf( |
|
99 | - esc_html__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), |
|
100 | - $old_question_group_question['question_id'] |
|
101 | - ) |
|
102 | - ); |
|
103 | - return; |
|
104 | - } |
|
105 | - if (! $new_question_group_id) { |
|
106 | - $this->add_error( |
|
107 | - sprintf( |
|
108 | - esc_html__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), |
|
109 | - $old_question_group_question['group_id'] |
|
110 | - ) |
|
111 | - ); |
|
112 | - return; |
|
113 | - } |
|
114 | - // if it's a system question, it needs to be in the right system group. otherwise no dice! |
|
115 | - if ( |
|
116 | - ($this->_is_system_question_group($new_question_group_id) == |
|
117 | - $this->_is_system_question_for_question_group($new_question_id)) || |
|
118 | - ! $this->_is_system_question_for_question_group($new_question_id) |
|
119 | - ) { |
|
120 | - $cols_n_values = [ |
|
121 | - 'QSG_ID' => $new_question_group_id, |
|
122 | - 'QST_ID' => $new_question_id, |
|
123 | - ]; |
|
124 | - $data_types = [ |
|
125 | - '%d',// QSG_ID |
|
126 | - '%d',// QST_ID |
|
127 | - ]; |
|
128 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
129 | - if (! $success) { |
|
130 | - $this->add_error( |
|
131 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
132 | - $this->_old_table, |
|
133 | - $old_question_group_question, |
|
134 | - $this->_new_table, |
|
135 | - $cols_n_values, |
|
136 | - $data_types |
|
137 | - ) |
|
138 | - ); |
|
139 | - } |
|
140 | - } |
|
141 | - } |
|
75 | + /** |
|
76 | + * Attempts to insert a new question group in the new format given an old one |
|
77 | + * |
|
78 | + * @param array $old_question_group_question |
|
79 | + * @return void |
|
80 | + * @throws EE_Error |
|
81 | + * @global wpdb $wpdb |
|
82 | + */ |
|
83 | + private function _insert_new_question_group_question(array $old_question_group_question): void |
|
84 | + { |
|
85 | + global $wpdb; |
|
86 | + $new_question_id = $this->get_migration_script()->get_mapping_new_pk( |
|
87 | + $wpdb->prefix . "events_question", |
|
88 | + $old_question_group_question['question_id'], |
|
89 | + $wpdb->prefix . "esp_question" |
|
90 | + ); |
|
91 | + $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk( |
|
92 | + $wpdb->prefix . "events_qst_group", |
|
93 | + $old_question_group_question['group_id'], |
|
94 | + $wpdb->prefix . "esp_question_group" |
|
95 | + ); |
|
96 | + if (! $new_question_id) { |
|
97 | + $this->add_error( |
|
98 | + sprintf( |
|
99 | + esc_html__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), |
|
100 | + $old_question_group_question['question_id'] |
|
101 | + ) |
|
102 | + ); |
|
103 | + return; |
|
104 | + } |
|
105 | + if (! $new_question_group_id) { |
|
106 | + $this->add_error( |
|
107 | + sprintf( |
|
108 | + esc_html__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), |
|
109 | + $old_question_group_question['group_id'] |
|
110 | + ) |
|
111 | + ); |
|
112 | + return; |
|
113 | + } |
|
114 | + // if it's a system question, it needs to be in the right system group. otherwise no dice! |
|
115 | + if ( |
|
116 | + ($this->_is_system_question_group($new_question_group_id) == |
|
117 | + $this->_is_system_question_for_question_group($new_question_id)) || |
|
118 | + ! $this->_is_system_question_for_question_group($new_question_id) |
|
119 | + ) { |
|
120 | + $cols_n_values = [ |
|
121 | + 'QSG_ID' => $new_question_group_id, |
|
122 | + 'QST_ID' => $new_question_id, |
|
123 | + ]; |
|
124 | + $data_types = [ |
|
125 | + '%d',// QSG_ID |
|
126 | + '%d',// QST_ID |
|
127 | + ]; |
|
128 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
129 | + if (! $success) { |
|
130 | + $this->add_error( |
|
131 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
132 | + $this->_old_table, |
|
133 | + $old_question_group_question, |
|
134 | + $this->_new_table, |
|
135 | + $cols_n_values, |
|
136 | + $data_types |
|
137 | + ) |
|
138 | + ); |
|
139 | + } |
|
140 | + } |
|
141 | + } |
|
142 | 142 | |
143 | 143 | |
144 | - /** |
|
145 | - * If this question is a system question, returns the QSG_system number that |
|
146 | - * indicates the question group its permitted in. |
|
147 | - * |
|
148 | - * @param int $new_question_id |
|
149 | - * @return int |
|
150 | - * @global wpdb $wpdb |
|
151 | - */ |
|
152 | - private function _is_system_question_for_question_group(int $new_question_id): int |
|
153 | - { |
|
154 | - global $wpdb; |
|
155 | - $system_id = $wpdb->get_var( |
|
156 | - $wpdb->prepare( |
|
157 | - "SELECT QST_system FROM " . $wpdb->prefix . "esp_question WHERE QST_ID=%d", |
|
158 | - $new_question_id |
|
159 | - ) |
|
160 | - ); |
|
161 | - if (in_array($system_id, ['fname', 'lname', 'email'])) { |
|
162 | - return 1; |
|
163 | - } |
|
164 | - if ($system_id != '' && $system_id) { |
|
165 | - return 2; |
|
166 | - } |
|
167 | - return 0; |
|
168 | - } |
|
144 | + /** |
|
145 | + * If this question is a system question, returns the QSG_system number that |
|
146 | + * indicates the question group its permitted in. |
|
147 | + * |
|
148 | + * @param int $new_question_id |
|
149 | + * @return int |
|
150 | + * @global wpdb $wpdb |
|
151 | + */ |
|
152 | + private function _is_system_question_for_question_group(int $new_question_id): int |
|
153 | + { |
|
154 | + global $wpdb; |
|
155 | + $system_id = $wpdb->get_var( |
|
156 | + $wpdb->prepare( |
|
157 | + "SELECT QST_system FROM " . $wpdb->prefix . "esp_question WHERE QST_ID=%d", |
|
158 | + $new_question_id |
|
159 | + ) |
|
160 | + ); |
|
161 | + if (in_array($system_id, ['fname', 'lname', 'email'])) { |
|
162 | + return 1; |
|
163 | + } |
|
164 | + if ($system_id != '' && $system_id) { |
|
165 | + return 2; |
|
166 | + } |
|
167 | + return 0; |
|
168 | + } |
|
169 | 169 | |
170 | 170 | |
171 | - /** |
|
172 | - * Returns the question group's QSG_system value (1 meaning personal info, 2 |
|
173 | - * being address info, and 0 being neither) |
|
174 | - * |
|
175 | - * @param int $new_question_group_id |
|
176 | - * @return int |
|
177 | - * @global wpdb $wpdb |
|
178 | - */ |
|
179 | - private function _is_system_question_group(int $new_question_group_id): int |
|
180 | - { |
|
181 | - global $wpdb; |
|
182 | - return (int) $wpdb->get_var( |
|
183 | - $wpdb->prepare( |
|
184 | - "SELECT QSG_system FROM " . $wpdb->prefix . "esp_question_group WHERE QSG_ID=%d", |
|
185 | - $new_question_group_id |
|
186 | - ) |
|
187 | - ); |
|
188 | - } |
|
171 | + /** |
|
172 | + * Returns the question group's QSG_system value (1 meaning personal info, 2 |
|
173 | + * being address info, and 0 being neither) |
|
174 | + * |
|
175 | + * @param int $new_question_group_id |
|
176 | + * @return int |
|
177 | + * @global wpdb $wpdb |
|
178 | + */ |
|
179 | + private function _is_system_question_group(int $new_question_group_id): int |
|
180 | + { |
|
181 | + global $wpdb; |
|
182 | + return (int) $wpdb->get_var( |
|
183 | + $wpdb->prepare( |
|
184 | + "SELECT QSG_system FROM " . $wpdb->prefix . "esp_question_group WHERE QSG_ID=%d", |
|
185 | + $new_question_group_id |
|
186 | + ) |
|
187 | + ); |
|
188 | + } |
|
189 | 189 | } |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | public function __construct() |
32 | 32 | { |
33 | 33 | global $wpdb; |
34 | - $this->_old_table = $wpdb->prefix . "events_qst_group_rel"; |
|
35 | - $this->_new_table = $wpdb->prefix . "esp_question_group_question"; |
|
34 | + $this->_old_table = $wpdb->prefix."events_qst_group_rel"; |
|
35 | + $this->_new_table = $wpdb->prefix."esp_question_group_question"; |
|
36 | 36 | $this->_pretty_name = esc_html__("Question Group to Question Relations", "event_espresso"); |
37 | 37 | parent::__construct(); |
38 | 38 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | public function _count_records_to_migrate() |
69 | 69 | { |
70 | 70 | global $wpdb; |
71 | - return $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
71 | + return $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | |
@@ -83,17 +83,17 @@ discard block |
||
83 | 83 | private function _insert_new_question_group_question(array $old_question_group_question): void |
84 | 84 | { |
85 | 85 | global $wpdb; |
86 | - $new_question_id = $this->get_migration_script()->get_mapping_new_pk( |
|
87 | - $wpdb->prefix . "events_question", |
|
86 | + $new_question_id = $this->get_migration_script()->get_mapping_new_pk( |
|
87 | + $wpdb->prefix."events_question", |
|
88 | 88 | $old_question_group_question['question_id'], |
89 | - $wpdb->prefix . "esp_question" |
|
89 | + $wpdb->prefix."esp_question" |
|
90 | 90 | ); |
91 | 91 | $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk( |
92 | - $wpdb->prefix . "events_qst_group", |
|
92 | + $wpdb->prefix."events_qst_group", |
|
93 | 93 | $old_question_group_question['group_id'], |
94 | - $wpdb->prefix . "esp_question_group" |
|
94 | + $wpdb->prefix."esp_question_group" |
|
95 | 95 | ); |
96 | - if (! $new_question_id) { |
|
96 | + if ( ! $new_question_id) { |
|
97 | 97 | $this->add_error( |
98 | 98 | sprintf( |
99 | 99 | esc_html__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | ); |
103 | 103 | return; |
104 | 104 | } |
105 | - if (! $new_question_group_id) { |
|
105 | + if ( ! $new_question_group_id) { |
|
106 | 106 | $this->add_error( |
107 | 107 | sprintf( |
108 | 108 | esc_html__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), |
@@ -121,12 +121,12 @@ discard block |
||
121 | 121 | 'QSG_ID' => $new_question_group_id, |
122 | 122 | 'QST_ID' => $new_question_id, |
123 | 123 | ]; |
124 | - $data_types = [ |
|
125 | - '%d',// QSG_ID |
|
126 | - '%d',// QST_ID |
|
124 | + $data_types = [ |
|
125 | + '%d', // QSG_ID |
|
126 | + '%d', // QST_ID |
|
127 | 127 | ]; |
128 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
129 | - if (! $success) { |
|
128 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
129 | + if ( ! $success) { |
|
130 | 130 | $this->add_error( |
131 | 131 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
132 | 132 | $this->_old_table, |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | global $wpdb; |
155 | 155 | $system_id = $wpdb->get_var( |
156 | 156 | $wpdb->prepare( |
157 | - "SELECT QST_system FROM " . $wpdb->prefix . "esp_question WHERE QST_ID=%d", |
|
157 | + "SELECT QST_system FROM ".$wpdb->prefix."esp_question WHERE QST_ID=%d", |
|
158 | 158 | $new_question_id |
159 | 159 | ) |
160 | 160 | ); |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | global $wpdb; |
182 | 182 | return (int) $wpdb->get_var( |
183 | 183 | $wpdb->prepare( |
184 | - "SELECT QSG_system FROM " . $wpdb->prefix . "esp_question_group WHERE QSG_ID=%d", |
|
184 | + "SELECT QSG_system FROM ".$wpdb->prefix."esp_question_group WHERE QSG_ID=%d", |
|
185 | 185 | $new_question_group_id |
186 | 186 | ) |
187 | 187 | ); |