@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function mapping($refresh = false) |
39 | 39 | { |
40 | - if (! $this->mapping || $refresh) { |
|
40 | + if ( ! $this->mapping || $refresh) { |
|
41 | 41 | $this->mapping = $this->generateNewMapping(); |
42 | 42 | } |
43 | 43 | return $this->mapping; |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | protected function generateNewMapping() |
53 | 53 | { |
54 | 54 | $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\'; |
55 | - $event_calculations_class = $rest_api_calculations_namespace . 'Event'; |
|
56 | - $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime'; |
|
57 | - $registration_class = $rest_api_calculations_namespace . 'Registration'; |
|
58 | - $attendee_class = $rest_api_calculations_namespace . 'Attendee'; |
|
55 | + $event_calculations_class = $rest_api_calculations_namespace.'Event'; |
|
56 | + $datetime_calculations_class = $rest_api_calculations_namespace.'Datetime'; |
|
57 | + $registration_class = $rest_api_calculations_namespace.'Registration'; |
|
58 | + $attendee_class = $rest_api_calculations_namespace.'Attendee'; |
|
59 | 59 | return apply_filters( |
60 | 60 | 'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping', |
61 | 61 | array( |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | public function retrieveCalculatedFieldsForModel(EEM_Base $model) |
101 | 101 | { |
102 | 102 | $mapping = $this->mapping(); |
103 | - if (isset($mapping[ $model->get_this_model_name() ])) { |
|
104 | - return array_keys($mapping[ $model->get_this_model_name() ]); |
|
103 | + if (isset($mapping[$model->get_this_model_name()])) { |
|
104 | + return array_keys($mapping[$model->get_this_model_name()]); |
|
105 | 105 | } else { |
106 | 106 | return array(); |
107 | 107 | } |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | Base $controller |
128 | 128 | ) { |
129 | 129 | $mapping = $this->mapping(); |
130 | - if (isset($mapping[ $model->get_this_model_name() ]) |
|
131 | - && isset($mapping[ $model->get_this_model_name() ][ $field_name ]) |
|
130 | + if (isset($mapping[$model->get_this_model_name()]) |
|
131 | + && isset($mapping[$model->get_this_model_name()][$field_name]) |
|
132 | 132 | ) { |
133 | - $classname = $mapping[ $model->get_this_model_name() ][ $field_name ]; |
|
133 | + $classname = $mapping[$model->get_this_model_name()][$field_name]; |
|
134 | 134 | $class_method_name = EEH_Inflector::camelize_all_but_first($field_name); |
135 | 135 | return call_user_func(array($classname, $class_method_name), $wpdb_row, $rest_request, $controller); |
136 | 136 | } |
@@ -19,128 +19,128 @@ |
||
19 | 19 | class CalculatedModelFields |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $mapping; |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $mapping; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * @param bool $refresh |
|
30 | - * @return array top-level-keys are model names (eg "Event") |
|
31 | - * next-level are the calculated field names AND method names on classes |
|
32 | - * which perform calculations, values are the fully qualified classnames which do the calculations |
|
33 | - * These callbacks should accept as arguments: |
|
34 | - * the wpdb row results, |
|
35 | - * the WP_Request object, |
|
36 | - * the controller object |
|
37 | - */ |
|
38 | - public function mapping($refresh = false) |
|
39 | - { |
|
40 | - if (! $this->mapping || $refresh) { |
|
41 | - $this->mapping = $this->generateNewMapping(); |
|
42 | - } |
|
43 | - return $this->mapping; |
|
44 | - } |
|
28 | + /** |
|
29 | + * @param bool $refresh |
|
30 | + * @return array top-level-keys are model names (eg "Event") |
|
31 | + * next-level are the calculated field names AND method names on classes |
|
32 | + * which perform calculations, values are the fully qualified classnames which do the calculations |
|
33 | + * These callbacks should accept as arguments: |
|
34 | + * the wpdb row results, |
|
35 | + * the WP_Request object, |
|
36 | + * the controller object |
|
37 | + */ |
|
38 | + public function mapping($refresh = false) |
|
39 | + { |
|
40 | + if (! $this->mapping || $refresh) { |
|
41 | + $this->mapping = $this->generateNewMapping(); |
|
42 | + } |
|
43 | + return $this->mapping; |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * Generates anew mapping between model calculated fields and their callbacks |
|
49 | - * |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - protected function generateNewMapping() |
|
53 | - { |
|
54 | - $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\'; |
|
55 | - $event_calculations_class = $rest_api_calculations_namespace . 'Event'; |
|
56 | - $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime'; |
|
57 | - $registration_class = $rest_api_calculations_namespace . 'Registration'; |
|
58 | - $attendee_class = $rest_api_calculations_namespace . 'Attendee'; |
|
59 | - return apply_filters( |
|
60 | - 'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping', |
|
61 | - array( |
|
62 | - 'Event' => array( |
|
63 | - 'optimum_sales_at_start' => $event_calculations_class, |
|
64 | - 'optimum_sales_now' => $event_calculations_class, |
|
65 | - 'spots_taken' => $event_calculations_class, |
|
66 | - 'spots_taken_pending_payment' => $event_calculations_class, |
|
67 | - 'spaces_remaining' => $event_calculations_class, |
|
68 | - 'registrations_checked_in_count' => $event_calculations_class, |
|
69 | - 'registrations_checked_out_count' => $event_calculations_class, |
|
70 | - 'image_thumbnail' => $event_calculations_class, |
|
71 | - 'image_medium' => $event_calculations_class, |
|
72 | - 'image_medium_large' => $event_calculations_class, |
|
73 | - 'image_large' => $event_calculations_class, |
|
74 | - 'image_post_thumbnail' => $event_calculations_class, |
|
75 | - 'image_full' => $event_calculations_class, |
|
76 | - ), |
|
77 | - 'Datetime' => array( |
|
78 | - 'spaces_remaining_considering_tickets' => $datetime_calculations_class, |
|
79 | - 'registrations_checked_in_count' => $datetime_calculations_class, |
|
80 | - 'registrations_checked_out_count' => $datetime_calculations_class, |
|
81 | - 'spots_taken_pending_payment' => $datetime_calculations_class, |
|
82 | - ), |
|
83 | - 'Registration' => array( |
|
84 | - 'datetime_checkin_stati' => $registration_class, |
|
85 | - ), |
|
86 | - 'Attendee' => array( |
|
87 | - 'user_avatar' => $attendee_class, |
|
88 | - ), |
|
89 | - ) |
|
90 | - ); |
|
91 | - } |
|
47 | + /** |
|
48 | + * Generates anew mapping between model calculated fields and their callbacks |
|
49 | + * |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + protected function generateNewMapping() |
|
53 | + { |
|
54 | + $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\'; |
|
55 | + $event_calculations_class = $rest_api_calculations_namespace . 'Event'; |
|
56 | + $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime'; |
|
57 | + $registration_class = $rest_api_calculations_namespace . 'Registration'; |
|
58 | + $attendee_class = $rest_api_calculations_namespace . 'Attendee'; |
|
59 | + return apply_filters( |
|
60 | + 'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping', |
|
61 | + array( |
|
62 | + 'Event' => array( |
|
63 | + 'optimum_sales_at_start' => $event_calculations_class, |
|
64 | + 'optimum_sales_now' => $event_calculations_class, |
|
65 | + 'spots_taken' => $event_calculations_class, |
|
66 | + 'spots_taken_pending_payment' => $event_calculations_class, |
|
67 | + 'spaces_remaining' => $event_calculations_class, |
|
68 | + 'registrations_checked_in_count' => $event_calculations_class, |
|
69 | + 'registrations_checked_out_count' => $event_calculations_class, |
|
70 | + 'image_thumbnail' => $event_calculations_class, |
|
71 | + 'image_medium' => $event_calculations_class, |
|
72 | + 'image_medium_large' => $event_calculations_class, |
|
73 | + 'image_large' => $event_calculations_class, |
|
74 | + 'image_post_thumbnail' => $event_calculations_class, |
|
75 | + 'image_full' => $event_calculations_class, |
|
76 | + ), |
|
77 | + 'Datetime' => array( |
|
78 | + 'spaces_remaining_considering_tickets' => $datetime_calculations_class, |
|
79 | + 'registrations_checked_in_count' => $datetime_calculations_class, |
|
80 | + 'registrations_checked_out_count' => $datetime_calculations_class, |
|
81 | + 'spots_taken_pending_payment' => $datetime_calculations_class, |
|
82 | + ), |
|
83 | + 'Registration' => array( |
|
84 | + 'datetime_checkin_stati' => $registration_class, |
|
85 | + ), |
|
86 | + 'Attendee' => array( |
|
87 | + 'user_avatar' => $attendee_class, |
|
88 | + ), |
|
89 | + ) |
|
90 | + ); |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * Gets the known calculated fields for model |
|
96 | - * |
|
97 | - * @param EEM_Base $model |
|
98 | - * @return array allowable values for this field |
|
99 | - */ |
|
100 | - public function retrieveCalculatedFieldsForModel(EEM_Base $model) |
|
101 | - { |
|
102 | - $mapping = $this->mapping(); |
|
103 | - if (isset($mapping[ $model->get_this_model_name() ])) { |
|
104 | - return array_keys($mapping[ $model->get_this_model_name() ]); |
|
105 | - } else { |
|
106 | - return array(); |
|
107 | - } |
|
108 | - } |
|
94 | + /** |
|
95 | + * Gets the known calculated fields for model |
|
96 | + * |
|
97 | + * @param EEM_Base $model |
|
98 | + * @return array allowable values for this field |
|
99 | + */ |
|
100 | + public function retrieveCalculatedFieldsForModel(EEM_Base $model) |
|
101 | + { |
|
102 | + $mapping = $this->mapping(); |
|
103 | + if (isset($mapping[ $model->get_this_model_name() ])) { |
|
104 | + return array_keys($mapping[ $model->get_this_model_name() ]); |
|
105 | + } else { |
|
106 | + return array(); |
|
107 | + } |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * Retrieves the value for this calculation |
|
113 | - * |
|
114 | - * @param EEM_Base $model |
|
115 | - * @param string $field_name |
|
116 | - * @param array $wpdb_row |
|
117 | - * @param \WP_REST_Request |
|
118 | - * @param \EventEspresso\core\libraries\rest_api\controllers\Base $controller |
|
119 | - * @return mixed|null |
|
120 | - * @throws \EE_Error |
|
121 | - */ |
|
122 | - public function retrieveCalculatedFieldValue( |
|
123 | - EEM_Base $model, |
|
124 | - $field_name, |
|
125 | - $wpdb_row, |
|
126 | - $rest_request, |
|
127 | - Base $controller |
|
128 | - ) { |
|
129 | - $mapping = $this->mapping(); |
|
130 | - if (isset($mapping[ $model->get_this_model_name() ]) |
|
131 | - && isset($mapping[ $model->get_this_model_name() ][ $field_name ]) |
|
132 | - ) { |
|
133 | - $classname = $mapping[ $model->get_this_model_name() ][ $field_name ]; |
|
134 | - $class_method_name = EEH_Inflector::camelize_all_but_first($field_name); |
|
135 | - return call_user_func(array($classname, $class_method_name), $wpdb_row, $rest_request, $controller); |
|
136 | - } |
|
137 | - throw new RestException( |
|
138 | - 'calculated_field_does_not_exist', |
|
139 | - sprintf( |
|
140 | - __('There is no calculated field %1$s on resource %2$s', 'event_espresso'), |
|
141 | - $field_name, |
|
142 | - $model->get_this_model_name() |
|
143 | - ) |
|
144 | - ); |
|
145 | - } |
|
111 | + /** |
|
112 | + * Retrieves the value for this calculation |
|
113 | + * |
|
114 | + * @param EEM_Base $model |
|
115 | + * @param string $field_name |
|
116 | + * @param array $wpdb_row |
|
117 | + * @param \WP_REST_Request |
|
118 | + * @param \EventEspresso\core\libraries\rest_api\controllers\Base $controller |
|
119 | + * @return mixed|null |
|
120 | + * @throws \EE_Error |
|
121 | + */ |
|
122 | + public function retrieveCalculatedFieldValue( |
|
123 | + EEM_Base $model, |
|
124 | + $field_name, |
|
125 | + $wpdb_row, |
|
126 | + $rest_request, |
|
127 | + Base $controller |
|
128 | + ) { |
|
129 | + $mapping = $this->mapping(); |
|
130 | + if (isset($mapping[ $model->get_this_model_name() ]) |
|
131 | + && isset($mapping[ $model->get_this_model_name() ][ $field_name ]) |
|
132 | + ) { |
|
133 | + $classname = $mapping[ $model->get_this_model_name() ][ $field_name ]; |
|
134 | + $class_method_name = EEH_Inflector::camelize_all_but_first($field_name); |
|
135 | + return call_user_func(array($classname, $class_method_name), $wpdb_row, $rest_request, $controller); |
|
136 | + } |
|
137 | + throw new RestException( |
|
138 | + 'calculated_field_does_not_exist', |
|
139 | + sprintf( |
|
140 | + __('There is no calculated field %1$s on resource %2$s', 'event_espresso'), |
|
141 | + $field_name, |
|
142 | + $model->get_this_model_name() |
|
143 | + ) |
|
144 | + ); |
|
145 | + } |
|
146 | 146 | } |
@@ -11,592 +11,592 @@ |
||
11 | 11 | class EEG_Paypal_Pro extends EE_Onsite_Gateway |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @var $_paypal_api_username string |
|
16 | - */ |
|
17 | - protected $_username = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var $_password string |
|
21 | - */ |
|
22 | - protected $_password = null; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var $_signature string |
|
26 | - */ |
|
27 | - protected $_signature = null; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
31 | - */ |
|
32 | - protected $_credit_card_types = null; |
|
33 | - |
|
34 | - protected $_currencies_supported = array( |
|
35 | - 'USD', |
|
36 | - 'GBP', |
|
37 | - 'CAD', |
|
38 | - 'AUD', |
|
39 | - 'BRL', |
|
40 | - 'CHF', |
|
41 | - 'CZK', |
|
42 | - 'DKK', |
|
43 | - 'EUR', |
|
44 | - 'HKD', |
|
45 | - 'HUF', |
|
46 | - 'ILS', |
|
47 | - 'JPY', |
|
48 | - 'MXN', |
|
49 | - 'MYR', |
|
50 | - 'NOK', |
|
51 | - 'NZD', |
|
52 | - 'PHP', |
|
53 | - 'PLN', |
|
54 | - 'SEK', |
|
55 | - 'SGD', |
|
56 | - 'THB', |
|
57 | - 'TRY', |
|
58 | - 'TWD', |
|
59 | - 'RUB', |
|
60 | - 'INR', |
|
61 | - ); |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param EEI_Payment $payment |
|
67 | - * @param array $billing_info { |
|
68 | - * @type string $credit_card |
|
69 | - * @type string $credit_card_type |
|
70 | - * @type string $exp_month always 2 characters |
|
71 | - * @type string $exp_year always 4 characters |
|
72 | - * @type string $cvv |
|
73 | - * } |
|
74 | - * @see parent::do_direct_payment for more info |
|
75 | - * @return EE_Payment|EEI_Payment |
|
76 | - * @throws EE_Error |
|
77 | - */ |
|
78 | - public function do_direct_payment($payment, $billing_info = null) |
|
79 | - { |
|
80 | - $transaction = $payment->transaction(); |
|
81 | - if (! $transaction instanceof EEI_Transaction) { |
|
82 | - throw new EE_Error( |
|
83 | - esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
|
84 | - ); |
|
85 | - } |
|
86 | - $primary_registrant = $transaction->primary_registration(); |
|
87 | - if (! $primary_registrant instanceof EEI_Registration) { |
|
88 | - throw new EE_Error( |
|
89 | - esc_html__( |
|
90 | - 'No primary registration on transaction while paying with PayPal Pro.', |
|
91 | - 'event_espresso' |
|
92 | - ) |
|
93 | - ); |
|
94 | - } |
|
95 | - $attendee = $primary_registrant->attendee(); |
|
96 | - if (! $attendee instanceof EEI_Attendee) { |
|
97 | - throw new EE_Error( |
|
98 | - esc_html__( |
|
99 | - 'No attendee on primary registration while paying with PayPal Pro.', |
|
100 | - 'event_espresso' |
|
101 | - ) |
|
102 | - ); |
|
103 | - } |
|
104 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
105 | - $order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
106 | - // charge for the full amount. Show itemized list |
|
107 | - if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
108 | - $item_num = 1; |
|
109 | - $total_line_item = $transaction->total_line_item(); |
|
110 | - $order_items = array(); |
|
111 | - foreach ($total_line_item->get_items() as $line_item) { |
|
112 | - // ignore line items with a quantity of 0 |
|
113 | - if ($line_item->quantity() == 0) { |
|
114 | - continue; |
|
115 | - } |
|
116 | - $item = array( |
|
117 | - // Item Name. 127 char max. |
|
118 | - 'l_name' => substr( |
|
119 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
120 | - 0, |
|
121 | - 127 |
|
122 | - ), |
|
123 | - // Item description. 127 char max. |
|
124 | - 'l_desc' => substr( |
|
125 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
126 | - 0, |
|
127 | - 127 |
|
128 | - ), |
|
129 | - // Cost of individual item. |
|
130 | - 'l_amt' => $line_item->unit_price(), |
|
131 | - // Item Number. 127 char max. |
|
132 | - 'l_number' => $item_num++, |
|
133 | - // Item quantity. Must be any positive integer. |
|
134 | - 'l_qty' => $line_item->quantity(), |
|
135 | - // Item's sales tax amount. |
|
136 | - 'l_taxamt' => '', |
|
137 | - // eBay auction number of item. |
|
138 | - 'l_ebayitemnumber' => '', |
|
139 | - // eBay transaction ID of purchased item. |
|
140 | - 'l_ebayitemauctiontxnid' => '', |
|
141 | - // eBay order ID for the item. |
|
142 | - 'l_ebayitemorderid' => '', |
|
143 | - ); |
|
144 | - // add to array of all items |
|
145 | - array_push($order_items, $item); |
|
146 | - } |
|
147 | - $item_amount = $total_line_item->get_items_total(); |
|
148 | - $tax_amount = $total_line_item->get_total_tax(); |
|
149 | - } else { |
|
150 | - $order_items = array(); |
|
151 | - $item_amount = $payment->amount(); |
|
152 | - $tax_amount = 0; |
|
153 | - array_push($order_items, array( |
|
154 | - // Item Name. 127 char max. |
|
155 | - 'l_name' => substr( |
|
156 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
157 | - 0, |
|
158 | - 127 |
|
159 | - ), |
|
160 | - // Item description. 127 char max. |
|
161 | - 'l_desc' => substr( |
|
162 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
163 | - 0, |
|
164 | - 127 |
|
165 | - ), |
|
166 | - // Cost of individual item. |
|
167 | - 'l_amt' => $payment->amount(), |
|
168 | - // Item Number. 127 char max. |
|
169 | - 'l_number' => 1, |
|
170 | - // Item quantity. Must be any positive integer. |
|
171 | - 'l_qty' => 1, |
|
172 | - )); |
|
173 | - } |
|
174 | - // Populate data arrays with order data. |
|
175 | - $DPFields = array( |
|
176 | - // How you want to obtain payment ? |
|
177 | - // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture. |
|
178 | - // Sale indicates that this is a final sale for which you are requesting payment. Default is Sale. |
|
179 | - 'paymentaction' => 'Sale', |
|
180 | - // Required. IP address of the payer's browser. |
|
181 | - 'ipaddress' => $_SERVER['REMOTE_ADDR'], |
|
182 | - // Flag to determine whether you want the results returned by FMF. 1 or 0. Default is 0. |
|
183 | - 'returnfmfdetails' => '1', |
|
184 | - ); |
|
185 | - $CCDetails = array( |
|
186 | - // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. |
|
187 | - // If Maestro or Solo, the currency code must be GBP. |
|
188 | - // In addition, either start date or issue number must be specified. |
|
189 | - 'creditcardtype' => $billing_info['credit_card_type'], |
|
190 | - // Required. Credit card number. No spaces or punctuation. |
|
191 | - 'acct' => $billing_info['credit_card'], |
|
192 | - // Required. Credit card expiration date. Format is MMYYYY |
|
193 | - 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
194 | - // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
195 | - 'cvv2' => $billing_info['cvv'], |
|
196 | - ); |
|
197 | - $PayerInfo = array( |
|
198 | - // Email address of payer. |
|
199 | - 'email' => $billing_info['email'], |
|
200 | - // Unique PayPal customer ID for payer. |
|
201 | - 'payerid' => '', |
|
202 | - // Status of payer. Values are verified or unverified |
|
203 | - 'payerstatus' => '', |
|
204 | - // Payer's business name. |
|
205 | - 'business' => '', |
|
206 | - ); |
|
207 | - $PayerName = array( |
|
208 | - // Payer's salutation. 20 char max. |
|
209 | - 'salutation' => '', |
|
210 | - // Payer's first name. 25 char max. |
|
211 | - 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
212 | - // Payer's middle name. 25 char max. |
|
213 | - 'middlename' => '', |
|
214 | - // Payer's last name. 25 char max. |
|
215 | - 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
216 | - // Payer's suffix. 12 char max. |
|
217 | - 'suffix' => '', |
|
218 | - ); |
|
219 | - $BillingAddress = array( |
|
220 | - // Required. First street address. |
|
221 | - 'street' => $billing_info['address'], |
|
222 | - // Second street address. |
|
223 | - 'street2' => $billing_info['address2'], |
|
224 | - // Required. Name of City. |
|
225 | - 'city' => $billing_info['city'], |
|
226 | - // Required. Name of State or Province. |
|
227 | - 'state' => substr($billing_info['state'], 0, 40), |
|
228 | - // Required. Country code. |
|
229 | - 'countrycode' => $billing_info['country'], |
|
230 | - // Required. Postal code of payer. |
|
231 | - 'zip' => $billing_info['zip'], |
|
232 | - ); |
|
233 | - // check if the registration info contains the needed fields for paypal pro |
|
234 | - // (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
235 | - if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
236 | - $use_registration_address_info = true; |
|
237 | - } else { |
|
238 | - $use_registration_address_info = false; |
|
239 | - } |
|
240 | - // so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. |
|
241 | - // If not, use the billing info again |
|
242 | - $ShippingAddress = array( |
|
243 | - 'shiptoname' => substr($use_registration_address_info |
|
244 | - ? $attendee->full_name() |
|
245 | - : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
246 | - 'shiptostreet' => substr($use_registration_address_info |
|
247 | - ? $attendee->address() |
|
248 | - : $billing_info['address'], 0, 100), |
|
249 | - 'shiptostreet2' => substr($use_registration_address_info |
|
250 | - ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
251 | - 'shiptocity' => substr($use_registration_address_info |
|
252 | - ? $attendee->city() |
|
253 | - : $billing_info['city'], 0, 40), |
|
254 | - 'state' => substr($use_registration_address_info |
|
255 | - ? $attendee->state_name() |
|
256 | - : $billing_info['state'], 0, 40), |
|
257 | - 'shiptocountry' => $use_registration_address_info |
|
258 | - ? $attendee->country_ID() |
|
259 | - : $billing_info['country'], |
|
260 | - 'shiptozip' => substr($use_registration_address_info |
|
261 | - ? $attendee->zip() |
|
262 | - : $billing_info['zip'], 0, 20), |
|
263 | - 'shiptophonenum' => substr($use_registration_address_info |
|
264 | - ? $attendee->phone() |
|
265 | - : $billing_info['phone'], 0, 20), |
|
266 | - ); |
|
267 | - $PaymentDetails = array( |
|
268 | - // Required. Total amount of order, including shipping, handling, and tax. |
|
269 | - 'amt' => $gateway_formatter->formatCurrency($payment->amount()), |
|
270 | - // Required. Three-letter currency code. Default is USD. |
|
271 | - 'currencycode' => $payment->currency_code(), |
|
272 | - // Required if you include itemized cart details. (L_AMTn, etc.) |
|
273 | - // Subtotal of items not including S&H, or tax. |
|
274 | - 'itemamt' => $gateway_formatter->formatCurrency($item_amount),// |
|
275 | - // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
276 | - 'shippingamt' => '', |
|
277 | - // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
278 | - 'handlingamt' => '', |
|
279 | - // Required if you specify itemized cart tax details. |
|
280 | - // Sum of tax for all items on the order. Total sales tax. |
|
281 | - 'taxamt' => $gateway_formatter->formatCurrency($tax_amount), |
|
282 | - // Description of the order the customer is purchasing. 127 char max. |
|
283 | - 'desc' => $order_description, |
|
284 | - // Free-form field for your own use. 256 char max. |
|
285 | - 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
286 | - // Your own invoice or tracking number |
|
287 | - 'invnum' => wp_generate_password(12, false),// $transaction->ID(), |
|
288 | - // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
289 | - 'notifyurl' => '', |
|
290 | - 'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this |
|
291 | - ); |
|
292 | - // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
293 | - $PayPalRequestData = array( |
|
294 | - 'DPFields' => $DPFields, |
|
295 | - 'CCDetails' => $CCDetails, |
|
296 | - 'PayerInfo' => $PayerInfo, |
|
297 | - 'PayerName' => $PayerName, |
|
298 | - 'BillingAddress' => $BillingAddress, |
|
299 | - 'ShippingAddress' => $ShippingAddress, |
|
300 | - 'PaymentDetails' => $PaymentDetails, |
|
301 | - 'OrderItems' => $order_items, |
|
302 | - ); |
|
303 | - $this->_log_clean_request($PayPalRequestData, $payment); |
|
304 | - try { |
|
305 | - $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
306 | - // remove PCI-sensitive data so it doesn't get stored |
|
307 | - $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
308 | - $message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK']; |
|
309 | - if (empty($PayPalResult['RAWRESPONSE'])) { |
|
310 | - $payment->set_status($this->_pay_model->failed_status()); |
|
311 | - $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
312 | - $payment->set_details($PayPalResult); |
|
313 | - } else { |
|
314 | - if ($this->_APICallSuccessful($PayPalResult)) { |
|
315 | - $payment->set_status($this->_pay_model->approved_status()); |
|
316 | - } else { |
|
317 | - $payment->set_status($this->_pay_model->declined_status()); |
|
318 | - } |
|
319 | - // make sure we interpret the AMT as a float, not an international string |
|
320 | - // (where periods are thousand separators) |
|
321 | - $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
322 | - $payment->set_gateway_response($message); |
|
323 | - $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) |
|
324 | - ? $PayPalResult['TRANSACTIONID'] |
|
325 | - : null); |
|
326 | - $primary_registration_code = $primary_registrant instanceof EE_Registration |
|
327 | - ? $primary_registrant->reg_code() |
|
328 | - : ''; |
|
329 | - $payment->set_extra_accntng($primary_registration_code); |
|
330 | - $payment->set_details($PayPalResult); |
|
331 | - } |
|
332 | - } catch (Exception $e) { |
|
333 | - $payment->set_status($this->_pay_model->failed_status()); |
|
334 | - $payment->set_gateway_response($e->getMessage()); |
|
335 | - } |
|
336 | - // $payment->set_status( $this->_pay_model->declined_status() ); |
|
337 | - // $payment->set_gateway_response( '' ); |
|
338 | - return $payment; |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
345 | - * |
|
346 | - * @param array $request |
|
347 | - * @param EEI_Payment $payment |
|
348 | - * @return void |
|
349 | - */ |
|
350 | - private function _log_clean_request($request, $payment) |
|
351 | - { |
|
352 | - $cleaned_request_data = $request; |
|
353 | - unset($cleaned_request_data['CCDetails']['acct']); |
|
354 | - unset($cleaned_request_data['CCDetails']['cvv2']); |
|
355 | - unset($cleaned_request_data['CCDetails']['expdate']); |
|
356 | - $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * Cleans the response, logs it, and returns it |
|
363 | - * |
|
364 | - * @param array $response |
|
365 | - * @param EEI_Payment $payment |
|
366 | - * @return array cleaned |
|
367 | - */ |
|
368 | - private function _log_clean_response($response, $payment) |
|
369 | - { |
|
370 | - unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
371 | - unset($response['REQUESTDATA']['ACCT']); |
|
372 | - unset($response['REQUESTDATA']['EXPDATE']); |
|
373 | - unset($response['REQUESTDATA']['CVV2']); |
|
374 | - unset($response['RAWREQUEST']); |
|
375 | - $this->log(array('Paypal Response' => $response), $payment); |
|
376 | - return $response; |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * @param $DataArray |
|
383 | - * @return array |
|
384 | - */ |
|
385 | - private function prep_and_curl_request($DataArray) |
|
386 | - { |
|
387 | - // Create empty holders for each portion of the NVP string |
|
388 | - $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
389 | - $CCDetailsNVP = ''; |
|
390 | - $PayerInfoNVP = ''; |
|
391 | - $PayerNameNVP = ''; |
|
392 | - $BillingAddressNVP = ''; |
|
393 | - $ShippingAddressNVP = ''; |
|
394 | - $PaymentDetailsNVP = ''; |
|
395 | - $OrderItemsNVP = ''; |
|
396 | - $Secure3DNVP = ''; |
|
397 | - // DP Fields |
|
398 | - $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
399 | - foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
400 | - $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
401 | - } |
|
402 | - // CC Details Fields |
|
403 | - $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
404 | - foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
405 | - $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
406 | - } |
|
407 | - // PayerInfo Type Fields |
|
408 | - $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
409 | - foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
410 | - $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
411 | - } |
|
412 | - // Payer Name Fields |
|
413 | - $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
414 | - foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
415 | - $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
416 | - } |
|
417 | - // Address Fields (Billing) |
|
418 | - $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
419 | - foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
420 | - $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
421 | - } |
|
422 | - // Payment Details Type Fields |
|
423 | - $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
424 | - foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
425 | - $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
426 | - } |
|
427 | - // Payment Details Item Type Fields |
|
428 | - $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
429 | - $n = 0; |
|
430 | - foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
431 | - $CurrentItem = $OrderItems[ $OrderItemsVar ]; |
|
432 | - foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
433 | - $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
434 | - } |
|
435 | - $n++; |
|
436 | - } |
|
437 | - // Ship To Address Fields |
|
438 | - $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
439 | - foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
440 | - $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
441 | - } |
|
442 | - // 3D Secure Fields |
|
443 | - $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
444 | - foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
445 | - $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
446 | - } |
|
447 | - // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
448 | - $NVPRequest = 'USER=' |
|
449 | - . $this->_username |
|
450 | - . '&PWD=' |
|
451 | - . $this->_password |
|
452 | - . '&VERSION=64.0' |
|
453 | - . '&SIGNATURE=' |
|
454 | - . $this->_signature |
|
455 | - . $DPFieldsNVP |
|
456 | - . $CCDetailsNVP |
|
457 | - . $PayerInfoNVP |
|
458 | - . $PayerNameNVP |
|
459 | - . $BillingAddressNVP |
|
460 | - . $PaymentDetailsNVP |
|
461 | - . $OrderItemsNVP |
|
462 | - . $ShippingAddressNVP |
|
463 | - . $Secure3DNVP; |
|
464 | - $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
465 | - $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
466 | - $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
467 | - $Errors = $this->_GetErrors($NVPResponseArray); |
|
468 | - $NVPResponseArray['ERRORS'] = $Errors; |
|
469 | - $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
470 | - $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
471 | - $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
472 | - return $NVPResponseArray; |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * @param $Request |
|
479 | - * @return mixed |
|
480 | - */ |
|
481 | - private function _CURLRequest($Request) |
|
482 | - { |
|
483 | - $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
484 | - $curl = curl_init(); |
|
485 | - curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
486 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
487 | - curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
488 | - curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
489 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
490 | - curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
491 | - curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
492 | - // execute the curl POST |
|
493 | - $Response = curl_exec($curl); |
|
494 | - curl_close($curl); |
|
495 | - return $Response; |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * @param $NVPString |
|
502 | - * @return array |
|
503 | - */ |
|
504 | - private function _NVPToArray($NVPString) |
|
505 | - { |
|
506 | - // prepare responses into array |
|
507 | - $proArray = array(); |
|
508 | - while (strlen($NVPString)) { |
|
509 | - // name |
|
510 | - $keypos = strpos($NVPString, '='); |
|
511 | - $keyval = substr($NVPString, 0, $keypos); |
|
512 | - // value |
|
513 | - $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
514 | - $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
515 | - // decoding the response |
|
516 | - $proArray[ $keyval ] = urldecode($valval); |
|
517 | - $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
518 | - } |
|
519 | - return $proArray; |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * @param array $PayPalResult |
|
526 | - * @return bool |
|
527 | - */ |
|
528 | - private function _APICallSuccessful($PayPalResult) |
|
529 | - { |
|
530 | - $approved = false; |
|
531 | - // check main response message from PayPal |
|
532 | - if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
533 | - $ack = strtoupper($PayPalResult['ACK']); |
|
534 | - $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
535 | - } |
|
536 | - return $approved; |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * @param $DataArray |
|
543 | - * @return array |
|
544 | - */ |
|
545 | - private function _GetErrors($DataArray) |
|
546 | - { |
|
547 | - $Errors = array(); |
|
548 | - $n = 0; |
|
549 | - while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) { |
|
550 | - $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : ''; |
|
551 | - $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ]) |
|
552 | - ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ] |
|
553 | - : ''; |
|
554 | - $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ]) |
|
555 | - ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ] |
|
556 | - : ''; |
|
557 | - $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ]) |
|
558 | - ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ] |
|
559 | - : ''; |
|
560 | - $CurrentItem = array( |
|
561 | - 'L_ERRORCODE' => $LErrorCode, |
|
562 | - 'L_SHORTMESSAGE' => $LShortMessage, |
|
563 | - 'L_LONGMESSAGE' => $LLongMessage, |
|
564 | - 'L_SEVERITYCODE' => $LSeverityCode, |
|
565 | - ); |
|
566 | - array_push($Errors, $CurrentItem); |
|
567 | - $n++; |
|
568 | - } |
|
569 | - return $Errors; |
|
570 | - } |
|
571 | - |
|
572 | - |
|
573 | - |
|
574 | - /** |
|
575 | - * nothing to see here... move along.... |
|
576 | - * |
|
577 | - * @access protected |
|
578 | - * @param $Errors |
|
579 | - * @return string |
|
580 | - */ |
|
581 | - private function _DisplayErrors($Errors) |
|
582 | - { |
|
583 | - $error = ''; |
|
584 | - foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
585 | - $CurrentError = $Errors[ $ErrorVar ]; |
|
586 | - foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
587 | - $CurrentVarName = ''; |
|
588 | - if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
589 | - $CurrentVarName = 'Error Code'; |
|
590 | - } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
591 | - $CurrentVarName = 'Short Message'; |
|
592 | - } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
593 | - $CurrentVarName = 'Long Message'; |
|
594 | - } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
595 | - $CurrentVarName = 'Severity Code'; |
|
596 | - } |
|
597 | - $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
598 | - } |
|
599 | - } |
|
600 | - return $error; |
|
601 | - } |
|
14 | + /** |
|
15 | + * @var $_paypal_api_username string |
|
16 | + */ |
|
17 | + protected $_username = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var $_password string |
|
21 | + */ |
|
22 | + protected $_password = null; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var $_signature string |
|
26 | + */ |
|
27 | + protected $_signature = null; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
31 | + */ |
|
32 | + protected $_credit_card_types = null; |
|
33 | + |
|
34 | + protected $_currencies_supported = array( |
|
35 | + 'USD', |
|
36 | + 'GBP', |
|
37 | + 'CAD', |
|
38 | + 'AUD', |
|
39 | + 'BRL', |
|
40 | + 'CHF', |
|
41 | + 'CZK', |
|
42 | + 'DKK', |
|
43 | + 'EUR', |
|
44 | + 'HKD', |
|
45 | + 'HUF', |
|
46 | + 'ILS', |
|
47 | + 'JPY', |
|
48 | + 'MXN', |
|
49 | + 'MYR', |
|
50 | + 'NOK', |
|
51 | + 'NZD', |
|
52 | + 'PHP', |
|
53 | + 'PLN', |
|
54 | + 'SEK', |
|
55 | + 'SGD', |
|
56 | + 'THB', |
|
57 | + 'TRY', |
|
58 | + 'TWD', |
|
59 | + 'RUB', |
|
60 | + 'INR', |
|
61 | + ); |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param EEI_Payment $payment |
|
67 | + * @param array $billing_info { |
|
68 | + * @type string $credit_card |
|
69 | + * @type string $credit_card_type |
|
70 | + * @type string $exp_month always 2 characters |
|
71 | + * @type string $exp_year always 4 characters |
|
72 | + * @type string $cvv |
|
73 | + * } |
|
74 | + * @see parent::do_direct_payment for more info |
|
75 | + * @return EE_Payment|EEI_Payment |
|
76 | + * @throws EE_Error |
|
77 | + */ |
|
78 | + public function do_direct_payment($payment, $billing_info = null) |
|
79 | + { |
|
80 | + $transaction = $payment->transaction(); |
|
81 | + if (! $transaction instanceof EEI_Transaction) { |
|
82 | + throw new EE_Error( |
|
83 | + esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
|
84 | + ); |
|
85 | + } |
|
86 | + $primary_registrant = $transaction->primary_registration(); |
|
87 | + if (! $primary_registrant instanceof EEI_Registration) { |
|
88 | + throw new EE_Error( |
|
89 | + esc_html__( |
|
90 | + 'No primary registration on transaction while paying with PayPal Pro.', |
|
91 | + 'event_espresso' |
|
92 | + ) |
|
93 | + ); |
|
94 | + } |
|
95 | + $attendee = $primary_registrant->attendee(); |
|
96 | + if (! $attendee instanceof EEI_Attendee) { |
|
97 | + throw new EE_Error( |
|
98 | + esc_html__( |
|
99 | + 'No attendee on primary registration while paying with PayPal Pro.', |
|
100 | + 'event_espresso' |
|
101 | + ) |
|
102 | + ); |
|
103 | + } |
|
104 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
105 | + $order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
106 | + // charge for the full amount. Show itemized list |
|
107 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
108 | + $item_num = 1; |
|
109 | + $total_line_item = $transaction->total_line_item(); |
|
110 | + $order_items = array(); |
|
111 | + foreach ($total_line_item->get_items() as $line_item) { |
|
112 | + // ignore line items with a quantity of 0 |
|
113 | + if ($line_item->quantity() == 0) { |
|
114 | + continue; |
|
115 | + } |
|
116 | + $item = array( |
|
117 | + // Item Name. 127 char max. |
|
118 | + 'l_name' => substr( |
|
119 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
120 | + 0, |
|
121 | + 127 |
|
122 | + ), |
|
123 | + // Item description. 127 char max. |
|
124 | + 'l_desc' => substr( |
|
125 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
126 | + 0, |
|
127 | + 127 |
|
128 | + ), |
|
129 | + // Cost of individual item. |
|
130 | + 'l_amt' => $line_item->unit_price(), |
|
131 | + // Item Number. 127 char max. |
|
132 | + 'l_number' => $item_num++, |
|
133 | + // Item quantity. Must be any positive integer. |
|
134 | + 'l_qty' => $line_item->quantity(), |
|
135 | + // Item's sales tax amount. |
|
136 | + 'l_taxamt' => '', |
|
137 | + // eBay auction number of item. |
|
138 | + 'l_ebayitemnumber' => '', |
|
139 | + // eBay transaction ID of purchased item. |
|
140 | + 'l_ebayitemauctiontxnid' => '', |
|
141 | + // eBay order ID for the item. |
|
142 | + 'l_ebayitemorderid' => '', |
|
143 | + ); |
|
144 | + // add to array of all items |
|
145 | + array_push($order_items, $item); |
|
146 | + } |
|
147 | + $item_amount = $total_line_item->get_items_total(); |
|
148 | + $tax_amount = $total_line_item->get_total_tax(); |
|
149 | + } else { |
|
150 | + $order_items = array(); |
|
151 | + $item_amount = $payment->amount(); |
|
152 | + $tax_amount = 0; |
|
153 | + array_push($order_items, array( |
|
154 | + // Item Name. 127 char max. |
|
155 | + 'l_name' => substr( |
|
156 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
157 | + 0, |
|
158 | + 127 |
|
159 | + ), |
|
160 | + // Item description. 127 char max. |
|
161 | + 'l_desc' => substr( |
|
162 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
163 | + 0, |
|
164 | + 127 |
|
165 | + ), |
|
166 | + // Cost of individual item. |
|
167 | + 'l_amt' => $payment->amount(), |
|
168 | + // Item Number. 127 char max. |
|
169 | + 'l_number' => 1, |
|
170 | + // Item quantity. Must be any positive integer. |
|
171 | + 'l_qty' => 1, |
|
172 | + )); |
|
173 | + } |
|
174 | + // Populate data arrays with order data. |
|
175 | + $DPFields = array( |
|
176 | + // How you want to obtain payment ? |
|
177 | + // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture. |
|
178 | + // Sale indicates that this is a final sale for which you are requesting payment. Default is Sale. |
|
179 | + 'paymentaction' => 'Sale', |
|
180 | + // Required. IP address of the payer's browser. |
|
181 | + 'ipaddress' => $_SERVER['REMOTE_ADDR'], |
|
182 | + // Flag to determine whether you want the results returned by FMF. 1 or 0. Default is 0. |
|
183 | + 'returnfmfdetails' => '1', |
|
184 | + ); |
|
185 | + $CCDetails = array( |
|
186 | + // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. |
|
187 | + // If Maestro or Solo, the currency code must be GBP. |
|
188 | + // In addition, either start date or issue number must be specified. |
|
189 | + 'creditcardtype' => $billing_info['credit_card_type'], |
|
190 | + // Required. Credit card number. No spaces or punctuation. |
|
191 | + 'acct' => $billing_info['credit_card'], |
|
192 | + // Required. Credit card expiration date. Format is MMYYYY |
|
193 | + 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
194 | + // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
195 | + 'cvv2' => $billing_info['cvv'], |
|
196 | + ); |
|
197 | + $PayerInfo = array( |
|
198 | + // Email address of payer. |
|
199 | + 'email' => $billing_info['email'], |
|
200 | + // Unique PayPal customer ID for payer. |
|
201 | + 'payerid' => '', |
|
202 | + // Status of payer. Values are verified or unverified |
|
203 | + 'payerstatus' => '', |
|
204 | + // Payer's business name. |
|
205 | + 'business' => '', |
|
206 | + ); |
|
207 | + $PayerName = array( |
|
208 | + // Payer's salutation. 20 char max. |
|
209 | + 'salutation' => '', |
|
210 | + // Payer's first name. 25 char max. |
|
211 | + 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
212 | + // Payer's middle name. 25 char max. |
|
213 | + 'middlename' => '', |
|
214 | + // Payer's last name. 25 char max. |
|
215 | + 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
216 | + // Payer's suffix. 12 char max. |
|
217 | + 'suffix' => '', |
|
218 | + ); |
|
219 | + $BillingAddress = array( |
|
220 | + // Required. First street address. |
|
221 | + 'street' => $billing_info['address'], |
|
222 | + // Second street address. |
|
223 | + 'street2' => $billing_info['address2'], |
|
224 | + // Required. Name of City. |
|
225 | + 'city' => $billing_info['city'], |
|
226 | + // Required. Name of State or Province. |
|
227 | + 'state' => substr($billing_info['state'], 0, 40), |
|
228 | + // Required. Country code. |
|
229 | + 'countrycode' => $billing_info['country'], |
|
230 | + // Required. Postal code of payer. |
|
231 | + 'zip' => $billing_info['zip'], |
|
232 | + ); |
|
233 | + // check if the registration info contains the needed fields for paypal pro |
|
234 | + // (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
235 | + if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
236 | + $use_registration_address_info = true; |
|
237 | + } else { |
|
238 | + $use_registration_address_info = false; |
|
239 | + } |
|
240 | + // so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. |
|
241 | + // If not, use the billing info again |
|
242 | + $ShippingAddress = array( |
|
243 | + 'shiptoname' => substr($use_registration_address_info |
|
244 | + ? $attendee->full_name() |
|
245 | + : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
246 | + 'shiptostreet' => substr($use_registration_address_info |
|
247 | + ? $attendee->address() |
|
248 | + : $billing_info['address'], 0, 100), |
|
249 | + 'shiptostreet2' => substr($use_registration_address_info |
|
250 | + ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
251 | + 'shiptocity' => substr($use_registration_address_info |
|
252 | + ? $attendee->city() |
|
253 | + : $billing_info['city'], 0, 40), |
|
254 | + 'state' => substr($use_registration_address_info |
|
255 | + ? $attendee->state_name() |
|
256 | + : $billing_info['state'], 0, 40), |
|
257 | + 'shiptocountry' => $use_registration_address_info |
|
258 | + ? $attendee->country_ID() |
|
259 | + : $billing_info['country'], |
|
260 | + 'shiptozip' => substr($use_registration_address_info |
|
261 | + ? $attendee->zip() |
|
262 | + : $billing_info['zip'], 0, 20), |
|
263 | + 'shiptophonenum' => substr($use_registration_address_info |
|
264 | + ? $attendee->phone() |
|
265 | + : $billing_info['phone'], 0, 20), |
|
266 | + ); |
|
267 | + $PaymentDetails = array( |
|
268 | + // Required. Total amount of order, including shipping, handling, and tax. |
|
269 | + 'amt' => $gateway_formatter->formatCurrency($payment->amount()), |
|
270 | + // Required. Three-letter currency code. Default is USD. |
|
271 | + 'currencycode' => $payment->currency_code(), |
|
272 | + // Required if you include itemized cart details. (L_AMTn, etc.) |
|
273 | + // Subtotal of items not including S&H, or tax. |
|
274 | + 'itemamt' => $gateway_formatter->formatCurrency($item_amount),// |
|
275 | + // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
276 | + 'shippingamt' => '', |
|
277 | + // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
278 | + 'handlingamt' => '', |
|
279 | + // Required if you specify itemized cart tax details. |
|
280 | + // Sum of tax for all items on the order. Total sales tax. |
|
281 | + 'taxamt' => $gateway_formatter->formatCurrency($tax_amount), |
|
282 | + // Description of the order the customer is purchasing. 127 char max. |
|
283 | + 'desc' => $order_description, |
|
284 | + // Free-form field for your own use. 256 char max. |
|
285 | + 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
286 | + // Your own invoice or tracking number |
|
287 | + 'invnum' => wp_generate_password(12, false),// $transaction->ID(), |
|
288 | + // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
289 | + 'notifyurl' => '', |
|
290 | + 'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this |
|
291 | + ); |
|
292 | + // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
293 | + $PayPalRequestData = array( |
|
294 | + 'DPFields' => $DPFields, |
|
295 | + 'CCDetails' => $CCDetails, |
|
296 | + 'PayerInfo' => $PayerInfo, |
|
297 | + 'PayerName' => $PayerName, |
|
298 | + 'BillingAddress' => $BillingAddress, |
|
299 | + 'ShippingAddress' => $ShippingAddress, |
|
300 | + 'PaymentDetails' => $PaymentDetails, |
|
301 | + 'OrderItems' => $order_items, |
|
302 | + ); |
|
303 | + $this->_log_clean_request($PayPalRequestData, $payment); |
|
304 | + try { |
|
305 | + $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
306 | + // remove PCI-sensitive data so it doesn't get stored |
|
307 | + $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
308 | + $message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK']; |
|
309 | + if (empty($PayPalResult['RAWRESPONSE'])) { |
|
310 | + $payment->set_status($this->_pay_model->failed_status()); |
|
311 | + $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
312 | + $payment->set_details($PayPalResult); |
|
313 | + } else { |
|
314 | + if ($this->_APICallSuccessful($PayPalResult)) { |
|
315 | + $payment->set_status($this->_pay_model->approved_status()); |
|
316 | + } else { |
|
317 | + $payment->set_status($this->_pay_model->declined_status()); |
|
318 | + } |
|
319 | + // make sure we interpret the AMT as a float, not an international string |
|
320 | + // (where periods are thousand separators) |
|
321 | + $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
322 | + $payment->set_gateway_response($message); |
|
323 | + $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) |
|
324 | + ? $PayPalResult['TRANSACTIONID'] |
|
325 | + : null); |
|
326 | + $primary_registration_code = $primary_registrant instanceof EE_Registration |
|
327 | + ? $primary_registrant->reg_code() |
|
328 | + : ''; |
|
329 | + $payment->set_extra_accntng($primary_registration_code); |
|
330 | + $payment->set_details($PayPalResult); |
|
331 | + } |
|
332 | + } catch (Exception $e) { |
|
333 | + $payment->set_status($this->_pay_model->failed_status()); |
|
334 | + $payment->set_gateway_response($e->getMessage()); |
|
335 | + } |
|
336 | + // $payment->set_status( $this->_pay_model->declined_status() ); |
|
337 | + // $payment->set_gateway_response( '' ); |
|
338 | + return $payment; |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
345 | + * |
|
346 | + * @param array $request |
|
347 | + * @param EEI_Payment $payment |
|
348 | + * @return void |
|
349 | + */ |
|
350 | + private function _log_clean_request($request, $payment) |
|
351 | + { |
|
352 | + $cleaned_request_data = $request; |
|
353 | + unset($cleaned_request_data['CCDetails']['acct']); |
|
354 | + unset($cleaned_request_data['CCDetails']['cvv2']); |
|
355 | + unset($cleaned_request_data['CCDetails']['expdate']); |
|
356 | + $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * Cleans the response, logs it, and returns it |
|
363 | + * |
|
364 | + * @param array $response |
|
365 | + * @param EEI_Payment $payment |
|
366 | + * @return array cleaned |
|
367 | + */ |
|
368 | + private function _log_clean_response($response, $payment) |
|
369 | + { |
|
370 | + unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
371 | + unset($response['REQUESTDATA']['ACCT']); |
|
372 | + unset($response['REQUESTDATA']['EXPDATE']); |
|
373 | + unset($response['REQUESTDATA']['CVV2']); |
|
374 | + unset($response['RAWREQUEST']); |
|
375 | + $this->log(array('Paypal Response' => $response), $payment); |
|
376 | + return $response; |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * @param $DataArray |
|
383 | + * @return array |
|
384 | + */ |
|
385 | + private function prep_and_curl_request($DataArray) |
|
386 | + { |
|
387 | + // Create empty holders for each portion of the NVP string |
|
388 | + $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
389 | + $CCDetailsNVP = ''; |
|
390 | + $PayerInfoNVP = ''; |
|
391 | + $PayerNameNVP = ''; |
|
392 | + $BillingAddressNVP = ''; |
|
393 | + $ShippingAddressNVP = ''; |
|
394 | + $PaymentDetailsNVP = ''; |
|
395 | + $OrderItemsNVP = ''; |
|
396 | + $Secure3DNVP = ''; |
|
397 | + // DP Fields |
|
398 | + $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
399 | + foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
400 | + $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
401 | + } |
|
402 | + // CC Details Fields |
|
403 | + $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
404 | + foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
405 | + $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
406 | + } |
|
407 | + // PayerInfo Type Fields |
|
408 | + $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
409 | + foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
410 | + $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
411 | + } |
|
412 | + // Payer Name Fields |
|
413 | + $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
414 | + foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
415 | + $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
416 | + } |
|
417 | + // Address Fields (Billing) |
|
418 | + $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
419 | + foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
420 | + $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
421 | + } |
|
422 | + // Payment Details Type Fields |
|
423 | + $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
424 | + foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
425 | + $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
426 | + } |
|
427 | + // Payment Details Item Type Fields |
|
428 | + $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
429 | + $n = 0; |
|
430 | + foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
431 | + $CurrentItem = $OrderItems[ $OrderItemsVar ]; |
|
432 | + foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
433 | + $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
434 | + } |
|
435 | + $n++; |
|
436 | + } |
|
437 | + // Ship To Address Fields |
|
438 | + $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
439 | + foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
440 | + $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
441 | + } |
|
442 | + // 3D Secure Fields |
|
443 | + $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
444 | + foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
445 | + $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
446 | + } |
|
447 | + // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
448 | + $NVPRequest = 'USER=' |
|
449 | + . $this->_username |
|
450 | + . '&PWD=' |
|
451 | + . $this->_password |
|
452 | + . '&VERSION=64.0' |
|
453 | + . '&SIGNATURE=' |
|
454 | + . $this->_signature |
|
455 | + . $DPFieldsNVP |
|
456 | + . $CCDetailsNVP |
|
457 | + . $PayerInfoNVP |
|
458 | + . $PayerNameNVP |
|
459 | + . $BillingAddressNVP |
|
460 | + . $PaymentDetailsNVP |
|
461 | + . $OrderItemsNVP |
|
462 | + . $ShippingAddressNVP |
|
463 | + . $Secure3DNVP; |
|
464 | + $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
465 | + $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
466 | + $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
467 | + $Errors = $this->_GetErrors($NVPResponseArray); |
|
468 | + $NVPResponseArray['ERRORS'] = $Errors; |
|
469 | + $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
470 | + $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
471 | + $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
472 | + return $NVPResponseArray; |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * @param $Request |
|
479 | + * @return mixed |
|
480 | + */ |
|
481 | + private function _CURLRequest($Request) |
|
482 | + { |
|
483 | + $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
484 | + $curl = curl_init(); |
|
485 | + curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
486 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
487 | + curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
488 | + curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
489 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
490 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
491 | + curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
492 | + // execute the curl POST |
|
493 | + $Response = curl_exec($curl); |
|
494 | + curl_close($curl); |
|
495 | + return $Response; |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * @param $NVPString |
|
502 | + * @return array |
|
503 | + */ |
|
504 | + private function _NVPToArray($NVPString) |
|
505 | + { |
|
506 | + // prepare responses into array |
|
507 | + $proArray = array(); |
|
508 | + while (strlen($NVPString)) { |
|
509 | + // name |
|
510 | + $keypos = strpos($NVPString, '='); |
|
511 | + $keyval = substr($NVPString, 0, $keypos); |
|
512 | + // value |
|
513 | + $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
514 | + $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
515 | + // decoding the response |
|
516 | + $proArray[ $keyval ] = urldecode($valval); |
|
517 | + $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
518 | + } |
|
519 | + return $proArray; |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * @param array $PayPalResult |
|
526 | + * @return bool |
|
527 | + */ |
|
528 | + private function _APICallSuccessful($PayPalResult) |
|
529 | + { |
|
530 | + $approved = false; |
|
531 | + // check main response message from PayPal |
|
532 | + if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
533 | + $ack = strtoupper($PayPalResult['ACK']); |
|
534 | + $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
535 | + } |
|
536 | + return $approved; |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * @param $DataArray |
|
543 | + * @return array |
|
544 | + */ |
|
545 | + private function _GetErrors($DataArray) |
|
546 | + { |
|
547 | + $Errors = array(); |
|
548 | + $n = 0; |
|
549 | + while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) { |
|
550 | + $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : ''; |
|
551 | + $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ]) |
|
552 | + ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ] |
|
553 | + : ''; |
|
554 | + $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ]) |
|
555 | + ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ] |
|
556 | + : ''; |
|
557 | + $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ]) |
|
558 | + ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ] |
|
559 | + : ''; |
|
560 | + $CurrentItem = array( |
|
561 | + 'L_ERRORCODE' => $LErrorCode, |
|
562 | + 'L_SHORTMESSAGE' => $LShortMessage, |
|
563 | + 'L_LONGMESSAGE' => $LLongMessage, |
|
564 | + 'L_SEVERITYCODE' => $LSeverityCode, |
|
565 | + ); |
|
566 | + array_push($Errors, $CurrentItem); |
|
567 | + $n++; |
|
568 | + } |
|
569 | + return $Errors; |
|
570 | + } |
|
571 | + |
|
572 | + |
|
573 | + |
|
574 | + /** |
|
575 | + * nothing to see here... move along.... |
|
576 | + * |
|
577 | + * @access protected |
|
578 | + * @param $Errors |
|
579 | + * @return string |
|
580 | + */ |
|
581 | + private function _DisplayErrors($Errors) |
|
582 | + { |
|
583 | + $error = ''; |
|
584 | + foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
585 | + $CurrentError = $Errors[ $ErrorVar ]; |
|
586 | + foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
587 | + $CurrentVarName = ''; |
|
588 | + if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
589 | + $CurrentVarName = 'Error Code'; |
|
590 | + } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
591 | + $CurrentVarName = 'Short Message'; |
|
592 | + } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
593 | + $CurrentVarName = 'Long Message'; |
|
594 | + } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
595 | + $CurrentVarName = 'Severity Code'; |
|
596 | + } |
|
597 | + $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
598 | + } |
|
599 | + } |
|
600 | + return $error; |
|
601 | + } |
|
602 | 602 | } |
@@ -11,676 +11,676 @@ |
||
11 | 11 | */ |
12 | 12 | // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
13 | 13 | if (! function_exists('mb_strcut')) { |
14 | - /** |
|
15 | - * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
16 | - * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
17 | - * @param $string |
|
18 | - * @param $start |
|
19 | - * @param $length |
|
20 | - * @return bool|string |
|
21 | - */ |
|
22 | - function mb_strcut($string, $start, $length = null) |
|
23 | - { |
|
24 | - return mb_substr($string, $start, $length); |
|
25 | - } |
|
14 | + /** |
|
15 | + * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
16 | + * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
17 | + * @param $string |
|
18 | + * @param $start |
|
19 | + * @param $length |
|
20 | + * @return bool|string |
|
21 | + */ |
|
22 | + function mb_strcut($string, $start, $length = null) |
|
23 | + { |
|
24 | + return mb_substr($string, $start, $length); |
|
25 | + } |
|
26 | 26 | } |
27 | 27 | class EEG_Paypal_Express extends EE_Offsite_Gateway |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Merchant API Username. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $_api_username; |
|
36 | - |
|
37 | - /** |
|
38 | - * Merchant API Password. |
|
39 | - * |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $_api_password; |
|
43 | - |
|
44 | - /** |
|
45 | - * API Signature. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - protected $_api_signature; |
|
50 | - |
|
51 | - /** |
|
52 | - * Request Shipping address on PP checkout page. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - protected $_request_shipping_addr; |
|
57 | - |
|
58 | - /** |
|
59 | - * Business/personal logo. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - protected $_image_url; |
|
64 | - |
|
65 | - /** |
|
66 | - * gateway URL variable |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - protected $_base_gateway_url = ''; |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * EEG_Paypal_Express constructor. |
|
76 | - */ |
|
77 | - public function __construct() |
|
78 | - { |
|
79 | - $this->_currencies_supported = array( |
|
80 | - 'USD', |
|
81 | - 'AUD', |
|
82 | - 'BRL', |
|
83 | - 'CAD', |
|
84 | - 'CZK', |
|
85 | - 'DKK', |
|
86 | - 'EUR', |
|
87 | - 'HKD', |
|
88 | - 'HUF', |
|
89 | - 'ILS', |
|
90 | - 'JPY', |
|
91 | - 'MYR', |
|
92 | - 'MXN', |
|
93 | - 'NOK', |
|
94 | - 'NZD', |
|
95 | - 'PHP', |
|
96 | - 'PLN', |
|
97 | - 'GBP', |
|
98 | - 'RUB', |
|
99 | - 'SGD', |
|
100 | - 'SEK', |
|
101 | - 'CHF', |
|
102 | - 'TWD', |
|
103 | - 'THB', |
|
104 | - 'TRY', |
|
105 | - 'INR', |
|
106 | - ); |
|
107 | - parent::__construct(); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
114 | - * |
|
115 | - * @param array $settings_array |
|
116 | - */ |
|
117 | - public function set_settings($settings_array) |
|
118 | - { |
|
119 | - parent::set_settings($settings_array); |
|
120 | - // Redirect URL. |
|
121 | - $this->_base_gateway_url = $this->_debug_mode |
|
122 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
123 | - : 'https://api-3t.paypal.com/nvp'; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @param EEI_Payment $payment |
|
130 | - * @param array $billing_info |
|
131 | - * @param string $return_url |
|
132 | - * @param string $notify_url |
|
133 | - * @param string $cancel_url |
|
134 | - * @return \EE_Payment|\EEI_Payment |
|
135 | - * @throws \EE_Error |
|
136 | - */ |
|
137 | - public function set_redirection_info( |
|
138 | - $payment, |
|
139 | - $billing_info = array(), |
|
140 | - $return_url = null, |
|
141 | - $notify_url = null, |
|
142 | - $cancel_url = null |
|
143 | - ) { |
|
144 | - if (! $payment instanceof EEI_Payment) { |
|
145 | - $payment->set_gateway_response( |
|
146 | - esc_html__( |
|
147 | - 'Error. No associated payment was found.', |
|
148 | - 'event_espresso' |
|
149 | - ) |
|
150 | - ); |
|
151 | - $payment->set_status($this->_pay_model->failed_status()); |
|
152 | - return $payment; |
|
153 | - } |
|
154 | - $transaction = $payment->transaction(); |
|
155 | - if (! $transaction instanceof EEI_Transaction) { |
|
156 | - $payment->set_gateway_response( |
|
157 | - esc_html__( |
|
158 | - 'Could not process this payment because it has no associated transaction.', |
|
159 | - 'event_espresso' |
|
160 | - ) |
|
161 | - ); |
|
162 | - $payment->set_status($this->_pay_model->failed_status()); |
|
163 | - return $payment; |
|
164 | - } |
|
165 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
166 | - $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
167 | - $primary_registration = $transaction->primary_registration(); |
|
168 | - $primary_attendee = $primary_registration instanceof EE_Registration |
|
169 | - ? $primary_registration->attendee() |
|
170 | - : false; |
|
171 | - $locale = explode('-', get_bloginfo('language')); |
|
172 | - // Gather request parameters. |
|
173 | - $token_request_dtls = array( |
|
174 | - 'METHOD' => 'SetExpressCheckout', |
|
175 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
176 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
177 | - 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
178 | - 'RETURNURL' => $return_url, |
|
179 | - 'CANCELURL' => $cancel_url, |
|
180 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
181 | - // Buyer does not need to create a PayPal account to check out. |
|
182 | - // This is referred to as PayPal Account Optional. |
|
183 | - 'SOLUTIONTYPE' => 'Sole', |
|
184 | - // EE will blow up if you change this |
|
185 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
186 | - // Locale of the pages displayed by PayPal during Express Checkout. |
|
187 | - 'LOCALECODE' => $locale[1] |
|
188 | - ); |
|
189 | - // Show itemized list. |
|
190 | - $itemized_list = $this->itemize_list($payment, $transaction); |
|
191 | - $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
192 | - // Automatically filling out shipping and contact information. |
|
193 | - if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
194 | - // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
195 | - $token_request_dtls['NOSHIPPING'] = '2'; |
|
196 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
197 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
198 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
199 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
200 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
201 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
202 | - $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
203 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
204 | - } elseif (! $this->_request_shipping_addr) { |
|
205 | - // Do not request shipping details on the PP Checkout page. |
|
206 | - $token_request_dtls['NOSHIPPING'] = '1'; |
|
207 | - $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
208 | - } |
|
209 | - // Used a business/personal logo on the PayPal page. |
|
210 | - if (! empty($this->_image_url)) { |
|
211 | - $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
212 | - } |
|
213 | - $token_request_dtls = apply_filters( |
|
214 | - 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
215 | - $token_request_dtls, |
|
216 | - $this |
|
217 | - ); |
|
218 | - // Request PayPal token. |
|
219 | - $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
220 | - $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
221 | - $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
222 | - ? $token_rstatus['args'] |
|
223 | - : array(); |
|
224 | - if ($token_rstatus['status']) { |
|
225 | - // We got the Token so we may continue with the payment and redirect the client. |
|
226 | - $payment->set_details($response_args); |
|
227 | - $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
228 | - $payment->set_redirect_url( |
|
229 | - $gateway_url |
|
230 | - . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
231 | - . $response_args['TOKEN'] |
|
232 | - ); |
|
233 | - } else { |
|
234 | - if (isset($response_args['L_ERRORCODE'])) { |
|
235 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
236 | - } else { |
|
237 | - $payment->set_gateway_response( |
|
238 | - esc_html__( |
|
239 | - 'Error occurred while trying to setup the Express Checkout.', |
|
240 | - 'event_espresso' |
|
241 | - ) |
|
242 | - ); |
|
243 | - } |
|
244 | - $payment->set_details($response_args); |
|
245 | - $payment->set_status($this->_pay_model->failed_status()); |
|
246 | - } |
|
247 | - return $payment; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param array $update_info { |
|
254 | - * @type string $gateway_txn_id |
|
255 | - * @type string status an EEMI_Payment status |
|
256 | - * } |
|
257 | - * @param EEI_Transaction $transaction |
|
258 | - * @return EEI_Payment |
|
259 | - */ |
|
260 | - public function handle_payment_update($update_info, $transaction) |
|
261 | - { |
|
262 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
263 | - if ($payment instanceof EEI_Payment) { |
|
264 | - $this->log(array('Return from Authorization' => $update_info), $payment); |
|
265 | - $transaction = $payment->transaction(); |
|
266 | - if (! $transaction instanceof EEI_Transaction) { |
|
267 | - $payment->set_gateway_response( |
|
268 | - esc_html__( |
|
269 | - 'Could not process this payment because it has no associated transaction.', |
|
270 | - 'event_espresso' |
|
271 | - ) |
|
272 | - ); |
|
273 | - $payment->set_status($this->_pay_model->failed_status()); |
|
274 | - return $payment; |
|
275 | - } |
|
276 | - $primary_registrant = $transaction->primary_registration(); |
|
277 | - $payment_details = $payment->details(); |
|
278 | - // Check if we still have the token. |
|
279 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
280 | - $payment->set_status($this->_pay_model->failed_status()); |
|
281 | - return $payment; |
|
282 | - } |
|
283 | - $cdetails_request_dtls = array( |
|
284 | - 'METHOD' => 'GetExpressCheckoutDetails', |
|
285 | - 'TOKEN' => $payment_details['TOKEN'], |
|
286 | - ); |
|
287 | - // Request Customer Details. |
|
288 | - $cdetails_request_response = $this->_ppExpress_request( |
|
289 | - $cdetails_request_dtls, |
|
290 | - 'Customer Details', |
|
291 | - $payment |
|
292 | - ); |
|
293 | - $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
294 | - $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
295 | - ? $cdetails_rstatus['args'] |
|
296 | - : array(); |
|
297 | - if ($cdetails_rstatus['status']) { |
|
298 | - // We got the PayerID so now we can Complete the transaction. |
|
299 | - $docheckout_request_dtls = array( |
|
300 | - 'METHOD' => 'DoExpressCheckoutPayment', |
|
301 | - 'PAYERID' => $cdata_response_args['PAYERID'], |
|
302 | - 'TOKEN' => $payment_details['TOKEN'], |
|
303 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
304 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
305 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
306 | - // EE will blow up if you change this |
|
307 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
308 | - ); |
|
309 | - // Include itemized list. |
|
310 | - $itemized_list = $this->itemize_list( |
|
311 | - $payment, |
|
312 | - $transaction, |
|
313 | - $cdata_response_args |
|
314 | - ); |
|
315 | - $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
316 | - // Payment Checkout/Capture. |
|
317 | - $docheckout_request_response = $this->_ppExpress_request( |
|
318 | - $docheckout_request_dtls, |
|
319 | - 'Do Payment', |
|
320 | - $payment |
|
321 | - ); |
|
322 | - $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
323 | - $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
324 | - ? $docheckout_rstatus['args'] |
|
325 | - : array(); |
|
326 | - if ($docheckout_rstatus['status']) { |
|
327 | - // All is well, payment approved. |
|
328 | - $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
329 | - $primary_registrant->reg_code() |
|
330 | - : ''; |
|
331 | - $payment->set_extra_accntng($primary_registration_code); |
|
332 | - $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
333 | - ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
334 | - : 0); |
|
335 | - $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
336 | - ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
337 | - : null); |
|
338 | - $payment->set_details($cdata_response_args); |
|
339 | - $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
340 | - ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
341 | - : ''); |
|
342 | - $payment->set_status($this->_pay_model->approved_status()); |
|
343 | - } else { |
|
344 | - if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
345 | - $payment->set_gateway_response( |
|
346 | - $docheckout_response_args['L_ERRORCODE'] |
|
347 | - . '; ' |
|
348 | - . $docheckout_response_args['L_SHORTMESSAGE'] |
|
349 | - ); |
|
350 | - } else { |
|
351 | - $payment->set_gateway_response( |
|
352 | - esc_html__( |
|
353 | - 'Error occurred while trying to Capture the funds.', |
|
354 | - 'event_espresso' |
|
355 | - ) |
|
356 | - ); |
|
357 | - } |
|
358 | - $payment->set_details($docheckout_response_args); |
|
359 | - $payment->set_status($this->_pay_model->declined_status()); |
|
360 | - } |
|
361 | - } else { |
|
362 | - if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
363 | - $payment->set_gateway_response( |
|
364 | - $cdata_response_args['L_ERRORCODE'] |
|
365 | - . '; ' |
|
366 | - . $cdata_response_args['L_SHORTMESSAGE'] |
|
367 | - ); |
|
368 | - } else { |
|
369 | - $payment->set_gateway_response( |
|
370 | - esc_html__( |
|
371 | - 'Error occurred while trying to get payment Details from PayPal.', |
|
372 | - 'event_espresso' |
|
373 | - ) |
|
374 | - ); |
|
375 | - } |
|
376 | - $payment->set_details($cdata_response_args); |
|
377 | - $payment->set_status($this->_pay_model->failed_status()); |
|
378 | - } |
|
379 | - } else { |
|
380 | - $payment->set_gateway_response( |
|
381 | - esc_html__( |
|
382 | - 'Error occurred while trying to process the payment.', |
|
383 | - 'event_espresso' |
|
384 | - ) |
|
385 | - ); |
|
386 | - $payment->set_status($this->_pay_model->failed_status()); |
|
387 | - } |
|
388 | - return $payment; |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * Make a list of items that are in the giver transaction. |
|
395 | - * |
|
396 | - * @param EEI_Payment $payment |
|
397 | - * @param EEI_Transaction $transaction |
|
398 | - * @param array $request_response_args Data from a previous communication with PP. |
|
399 | - * @return array |
|
400 | - */ |
|
401 | - public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
402 | - { |
|
403 | - $itemized_list = array(); |
|
404 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
405 | - // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
406 | - if (! empty($request_response_args) |
|
407 | - && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
408 | - && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
409 | - ) { |
|
410 | - foreach ($request_response_args as $arg_key => $arg_val) { |
|
411 | - if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
412 | - && strpos($arg_key, 'NOTIFYURL') === false |
|
413 | - ) { |
|
414 | - $itemized_list[ $arg_key ] = $arg_val; |
|
415 | - } |
|
416 | - } |
|
417 | - // If we got only a few Items then something is not right. |
|
418 | - if (count($itemized_list) > 2) { |
|
419 | - return $itemized_list; |
|
420 | - } else { |
|
421 | - if (WP_DEBUG) { |
|
422 | - throw new EE_Error( |
|
423 | - sprintf( |
|
424 | - esc_html__( |
|
425 | - // @codingStandardsIgnoreStart |
|
426 | - 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
427 | - // @codingStandardsIgnoreEnd |
|
428 | - 'event_espresso' |
|
429 | - ), |
|
430 | - wp_json_encode($itemized_list) |
|
431 | - ) |
|
432 | - ); |
|
433 | - } |
|
434 | - // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
435 | - $itemized_list = array(); |
|
436 | - $this->log( |
|
437 | - array( |
|
438 | - esc_html__( |
|
439 | - 'Could not generate a proper item list with:', |
|
440 | - 'event_espresso' |
|
441 | - ) => $request_response_args |
|
442 | - ), |
|
443 | - $payment |
|
444 | - ); |
|
445 | - } |
|
446 | - } |
|
447 | - // ...otherwise we generate a new list for this transaction. |
|
448 | - if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
449 | - $item_num = 0; |
|
450 | - $itemized_sum = 0; |
|
451 | - $total_line_items = $transaction->total_line_item(); |
|
452 | - // Go through each item in the list. |
|
453 | - foreach ($total_line_items->get_items() as $line_item) { |
|
454 | - if ($line_item instanceof EE_Line_Item) { |
|
455 | - // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
456 | - if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
457 | - continue; |
|
458 | - } |
|
459 | - $unit_price = $line_item->unit_price(); |
|
460 | - $line_item_quantity = $line_item->quantity(); |
|
461 | - // This is a discount. |
|
462 | - if ($line_item->is_percent()) { |
|
463 | - $unit_price = $line_item->total(); |
|
464 | - $line_item_quantity = 1; |
|
465 | - } |
|
466 | - // Item Name. |
|
467 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
468 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
469 | - 0, |
|
470 | - 127 |
|
471 | - ); |
|
472 | - // Item description. |
|
473 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
474 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
475 | - 0, |
|
476 | - 127 |
|
477 | - ); |
|
478 | - // Cost of individual item. |
|
479 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
480 | - // Item Number. |
|
481 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
482 | - // Item quantity. |
|
483 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
484 | - // Digital item is sold. |
|
485 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
486 | - $itemized_sum += $line_item->total(); |
|
487 | - ++$item_num; |
|
488 | - } |
|
489 | - } |
|
490 | - // Item's sales S/H and tax amount. |
|
491 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
492 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
493 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
494 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
495 | - $itemized_sum_diff_from_txn_total = round( |
|
496 | - $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
497 | - 2 |
|
498 | - ); |
|
499 | - // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
500 | - // add the difference as an extra line item. |
|
501 | - if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
502 | - // Item Name. |
|
503 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
504 | - esc_html__( |
|
505 | - 'Other (promotion/surcharge/cancellation)', |
|
506 | - 'event_espresso' |
|
507 | - ), |
|
508 | - 0, |
|
509 | - 127 |
|
510 | - ); |
|
511 | - // Item description. |
|
512 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
513 | - // Cost of individual item. |
|
514 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
515 | - $itemized_sum_diff_from_txn_total |
|
516 | - ); |
|
517 | - // Item Number. |
|
518 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
519 | - // Item quantity. |
|
520 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
521 | - // Digital item is sold. |
|
522 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
523 | - $item_num++; |
|
524 | - } |
|
525 | - } else { |
|
526 | - // Just one Item. |
|
527 | - // Item Name. |
|
528 | - $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
529 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
530 | - 0, |
|
531 | - 127 |
|
532 | - ); |
|
533 | - // Item description. |
|
534 | - $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
535 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
536 | - 0, |
|
537 | - 127 |
|
538 | - ); |
|
539 | - // Cost of individual item. |
|
540 | - $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
541 | - // Item Number. |
|
542 | - $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
543 | - // Item quantity. |
|
544 | - $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
545 | - // Digital item is sold. |
|
546 | - $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
547 | - // Item's sales S/H and tax amount. |
|
548 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
549 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
550 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
551 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
552 | - } |
|
553 | - return $itemized_list; |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * Make the Express checkout request. |
|
560 | - * |
|
561 | - * @param array $request_params |
|
562 | - * @param string $request_text |
|
563 | - * @param EEI_Payment $payment |
|
564 | - * @return mixed |
|
565 | - */ |
|
566 | - public function _ppExpress_request($request_params, $request_text, $payment) |
|
567 | - { |
|
568 | - $request_dtls = array( |
|
569 | - 'VERSION' => '204.0', |
|
570 | - 'USER' => urlencode($this->_api_username), |
|
571 | - 'PWD' => urlencode($this->_api_password), |
|
572 | - 'SIGNATURE' => urlencode($this->_api_signature), |
|
573 | - ); |
|
574 | - $dtls = array_merge($request_dtls, $request_params); |
|
575 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
576 | - // Request Customer Details. |
|
577 | - $request_response = wp_remote_post( |
|
578 | - $this->_base_gateway_url, |
|
579 | - array( |
|
580 | - 'method' => 'POST', |
|
581 | - 'timeout' => 45, |
|
582 | - 'httpversion' => '1.1', |
|
583 | - 'cookies' => array(), |
|
584 | - 'headers' => array(), |
|
585 | - 'body' => http_build_query($dtls, '', '&'), |
|
586 | - ) |
|
587 | - ); |
|
588 | - // Log the response. |
|
589 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
590 | - return $request_response; |
|
591 | - } |
|
592 | - |
|
593 | - |
|
594 | - |
|
595 | - /** |
|
596 | - * Check the response status. |
|
597 | - * |
|
598 | - * @param mixed $request_response |
|
599 | - * @return array |
|
600 | - */ |
|
601 | - public function _ppExpress_check_response($request_response) |
|
602 | - { |
|
603 | - if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
604 | - // If we got here then there was an error in this request. |
|
605 | - return array('status' => false, 'args' => $request_response); |
|
606 | - } |
|
607 | - $response_args = array(); |
|
608 | - parse_str(urldecode($request_response['body']), $response_args); |
|
609 | - if (! isset($response_args['ACK'])) { |
|
610 | - return array('status' => false, 'args' => $request_response); |
|
611 | - } |
|
612 | - if (( |
|
613 | - isset($response_args['PAYERID']) |
|
614 | - || isset($response_args['TOKEN']) |
|
615 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
616 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
617 | - ) |
|
618 | - && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
619 | - ) { |
|
620 | - // Response status OK, return response parameters for further processing. |
|
621 | - return array('status' => true, 'args' => $response_args); |
|
622 | - } |
|
623 | - $errors = $this->_get_errors($response_args); |
|
624 | - return array('status' => false, 'args' => $errors); |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - |
|
629 | - /** |
|
630 | - * Log a "Cleared" request. |
|
631 | - * |
|
632 | - * @param array $request |
|
633 | - * @param EEI_Payment $payment |
|
634 | - * @param string $info |
|
635 | - * @return void |
|
636 | - */ |
|
637 | - private function _log_clean_request($request, $payment, $info) |
|
638 | - { |
|
639 | - $cleaned_request_data = $request; |
|
640 | - unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
641 | - $this->log(array($info => $cleaned_request_data), $payment); |
|
642 | - } |
|
643 | - |
|
644 | - |
|
645 | - |
|
646 | - /** |
|
647 | - * Get error from the response data. |
|
648 | - * |
|
649 | - * @param array $data_array |
|
650 | - * @return array |
|
651 | - */ |
|
652 | - private function _get_errors($data_array) |
|
653 | - { |
|
654 | - $errors = array(); |
|
655 | - $n = 0; |
|
656 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
657 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
658 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
659 | - : ''; |
|
660 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
661 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
662 | - : ''; |
|
663 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
664 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
665 | - : ''; |
|
666 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
667 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
668 | - : ''; |
|
669 | - if ($n === 0) { |
|
670 | - $errors = array( |
|
671 | - 'L_ERRORCODE' => $l_error_code, |
|
672 | - 'L_SHORTMESSAGE' => $l_short_message, |
|
673 | - 'L_LONGMESSAGE' => $l_long_message, |
|
674 | - 'L_SEVERITYCODE' => $l_severity_code, |
|
675 | - ); |
|
676 | - } else { |
|
677 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
678 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
679 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
680 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
681 | - } |
|
682 | - $n++; |
|
683 | - } |
|
684 | - return $errors; |
|
685 | - } |
|
30 | + /** |
|
31 | + * Merchant API Username. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $_api_username; |
|
36 | + |
|
37 | + /** |
|
38 | + * Merchant API Password. |
|
39 | + * |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $_api_password; |
|
43 | + |
|
44 | + /** |
|
45 | + * API Signature. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + protected $_api_signature; |
|
50 | + |
|
51 | + /** |
|
52 | + * Request Shipping address on PP checkout page. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + protected $_request_shipping_addr; |
|
57 | + |
|
58 | + /** |
|
59 | + * Business/personal logo. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + protected $_image_url; |
|
64 | + |
|
65 | + /** |
|
66 | + * gateway URL variable |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + protected $_base_gateway_url = ''; |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * EEG_Paypal_Express constructor. |
|
76 | + */ |
|
77 | + public function __construct() |
|
78 | + { |
|
79 | + $this->_currencies_supported = array( |
|
80 | + 'USD', |
|
81 | + 'AUD', |
|
82 | + 'BRL', |
|
83 | + 'CAD', |
|
84 | + 'CZK', |
|
85 | + 'DKK', |
|
86 | + 'EUR', |
|
87 | + 'HKD', |
|
88 | + 'HUF', |
|
89 | + 'ILS', |
|
90 | + 'JPY', |
|
91 | + 'MYR', |
|
92 | + 'MXN', |
|
93 | + 'NOK', |
|
94 | + 'NZD', |
|
95 | + 'PHP', |
|
96 | + 'PLN', |
|
97 | + 'GBP', |
|
98 | + 'RUB', |
|
99 | + 'SGD', |
|
100 | + 'SEK', |
|
101 | + 'CHF', |
|
102 | + 'TWD', |
|
103 | + 'THB', |
|
104 | + 'TRY', |
|
105 | + 'INR', |
|
106 | + ); |
|
107 | + parent::__construct(); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
114 | + * |
|
115 | + * @param array $settings_array |
|
116 | + */ |
|
117 | + public function set_settings($settings_array) |
|
118 | + { |
|
119 | + parent::set_settings($settings_array); |
|
120 | + // Redirect URL. |
|
121 | + $this->_base_gateway_url = $this->_debug_mode |
|
122 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
123 | + : 'https://api-3t.paypal.com/nvp'; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @param EEI_Payment $payment |
|
130 | + * @param array $billing_info |
|
131 | + * @param string $return_url |
|
132 | + * @param string $notify_url |
|
133 | + * @param string $cancel_url |
|
134 | + * @return \EE_Payment|\EEI_Payment |
|
135 | + * @throws \EE_Error |
|
136 | + */ |
|
137 | + public function set_redirection_info( |
|
138 | + $payment, |
|
139 | + $billing_info = array(), |
|
140 | + $return_url = null, |
|
141 | + $notify_url = null, |
|
142 | + $cancel_url = null |
|
143 | + ) { |
|
144 | + if (! $payment instanceof EEI_Payment) { |
|
145 | + $payment->set_gateway_response( |
|
146 | + esc_html__( |
|
147 | + 'Error. No associated payment was found.', |
|
148 | + 'event_espresso' |
|
149 | + ) |
|
150 | + ); |
|
151 | + $payment->set_status($this->_pay_model->failed_status()); |
|
152 | + return $payment; |
|
153 | + } |
|
154 | + $transaction = $payment->transaction(); |
|
155 | + if (! $transaction instanceof EEI_Transaction) { |
|
156 | + $payment->set_gateway_response( |
|
157 | + esc_html__( |
|
158 | + 'Could not process this payment because it has no associated transaction.', |
|
159 | + 'event_espresso' |
|
160 | + ) |
|
161 | + ); |
|
162 | + $payment->set_status($this->_pay_model->failed_status()); |
|
163 | + return $payment; |
|
164 | + } |
|
165 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
166 | + $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
167 | + $primary_registration = $transaction->primary_registration(); |
|
168 | + $primary_attendee = $primary_registration instanceof EE_Registration |
|
169 | + ? $primary_registration->attendee() |
|
170 | + : false; |
|
171 | + $locale = explode('-', get_bloginfo('language')); |
|
172 | + // Gather request parameters. |
|
173 | + $token_request_dtls = array( |
|
174 | + 'METHOD' => 'SetExpressCheckout', |
|
175 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
176 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
177 | + 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
178 | + 'RETURNURL' => $return_url, |
|
179 | + 'CANCELURL' => $cancel_url, |
|
180 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
181 | + // Buyer does not need to create a PayPal account to check out. |
|
182 | + // This is referred to as PayPal Account Optional. |
|
183 | + 'SOLUTIONTYPE' => 'Sole', |
|
184 | + // EE will blow up if you change this |
|
185 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
186 | + // Locale of the pages displayed by PayPal during Express Checkout. |
|
187 | + 'LOCALECODE' => $locale[1] |
|
188 | + ); |
|
189 | + // Show itemized list. |
|
190 | + $itemized_list = $this->itemize_list($payment, $transaction); |
|
191 | + $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
192 | + // Automatically filling out shipping and contact information. |
|
193 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
194 | + // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
195 | + $token_request_dtls['NOSHIPPING'] = '2'; |
|
196 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
197 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
198 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
199 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
200 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
201 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
202 | + $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
203 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
204 | + } elseif (! $this->_request_shipping_addr) { |
|
205 | + // Do not request shipping details on the PP Checkout page. |
|
206 | + $token_request_dtls['NOSHIPPING'] = '1'; |
|
207 | + $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
208 | + } |
|
209 | + // Used a business/personal logo on the PayPal page. |
|
210 | + if (! empty($this->_image_url)) { |
|
211 | + $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
212 | + } |
|
213 | + $token_request_dtls = apply_filters( |
|
214 | + 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
215 | + $token_request_dtls, |
|
216 | + $this |
|
217 | + ); |
|
218 | + // Request PayPal token. |
|
219 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
220 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
221 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
222 | + ? $token_rstatus['args'] |
|
223 | + : array(); |
|
224 | + if ($token_rstatus['status']) { |
|
225 | + // We got the Token so we may continue with the payment and redirect the client. |
|
226 | + $payment->set_details($response_args); |
|
227 | + $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
228 | + $payment->set_redirect_url( |
|
229 | + $gateway_url |
|
230 | + . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
231 | + . $response_args['TOKEN'] |
|
232 | + ); |
|
233 | + } else { |
|
234 | + if (isset($response_args['L_ERRORCODE'])) { |
|
235 | + $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
236 | + } else { |
|
237 | + $payment->set_gateway_response( |
|
238 | + esc_html__( |
|
239 | + 'Error occurred while trying to setup the Express Checkout.', |
|
240 | + 'event_espresso' |
|
241 | + ) |
|
242 | + ); |
|
243 | + } |
|
244 | + $payment->set_details($response_args); |
|
245 | + $payment->set_status($this->_pay_model->failed_status()); |
|
246 | + } |
|
247 | + return $payment; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param array $update_info { |
|
254 | + * @type string $gateway_txn_id |
|
255 | + * @type string status an EEMI_Payment status |
|
256 | + * } |
|
257 | + * @param EEI_Transaction $transaction |
|
258 | + * @return EEI_Payment |
|
259 | + */ |
|
260 | + public function handle_payment_update($update_info, $transaction) |
|
261 | + { |
|
262 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
263 | + if ($payment instanceof EEI_Payment) { |
|
264 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
265 | + $transaction = $payment->transaction(); |
|
266 | + if (! $transaction instanceof EEI_Transaction) { |
|
267 | + $payment->set_gateway_response( |
|
268 | + esc_html__( |
|
269 | + 'Could not process this payment because it has no associated transaction.', |
|
270 | + 'event_espresso' |
|
271 | + ) |
|
272 | + ); |
|
273 | + $payment->set_status($this->_pay_model->failed_status()); |
|
274 | + return $payment; |
|
275 | + } |
|
276 | + $primary_registrant = $transaction->primary_registration(); |
|
277 | + $payment_details = $payment->details(); |
|
278 | + // Check if we still have the token. |
|
279 | + if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
280 | + $payment->set_status($this->_pay_model->failed_status()); |
|
281 | + return $payment; |
|
282 | + } |
|
283 | + $cdetails_request_dtls = array( |
|
284 | + 'METHOD' => 'GetExpressCheckoutDetails', |
|
285 | + 'TOKEN' => $payment_details['TOKEN'], |
|
286 | + ); |
|
287 | + // Request Customer Details. |
|
288 | + $cdetails_request_response = $this->_ppExpress_request( |
|
289 | + $cdetails_request_dtls, |
|
290 | + 'Customer Details', |
|
291 | + $payment |
|
292 | + ); |
|
293 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
294 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
295 | + ? $cdetails_rstatus['args'] |
|
296 | + : array(); |
|
297 | + if ($cdetails_rstatus['status']) { |
|
298 | + // We got the PayerID so now we can Complete the transaction. |
|
299 | + $docheckout_request_dtls = array( |
|
300 | + 'METHOD' => 'DoExpressCheckoutPayment', |
|
301 | + 'PAYERID' => $cdata_response_args['PAYERID'], |
|
302 | + 'TOKEN' => $payment_details['TOKEN'], |
|
303 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
304 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
305 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
306 | + // EE will blow up if you change this |
|
307 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
308 | + ); |
|
309 | + // Include itemized list. |
|
310 | + $itemized_list = $this->itemize_list( |
|
311 | + $payment, |
|
312 | + $transaction, |
|
313 | + $cdata_response_args |
|
314 | + ); |
|
315 | + $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
316 | + // Payment Checkout/Capture. |
|
317 | + $docheckout_request_response = $this->_ppExpress_request( |
|
318 | + $docheckout_request_dtls, |
|
319 | + 'Do Payment', |
|
320 | + $payment |
|
321 | + ); |
|
322 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
323 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
324 | + ? $docheckout_rstatus['args'] |
|
325 | + : array(); |
|
326 | + if ($docheckout_rstatus['status']) { |
|
327 | + // All is well, payment approved. |
|
328 | + $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
329 | + $primary_registrant->reg_code() |
|
330 | + : ''; |
|
331 | + $payment->set_extra_accntng($primary_registration_code); |
|
332 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
333 | + ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
334 | + : 0); |
|
335 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
336 | + ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
337 | + : null); |
|
338 | + $payment->set_details($cdata_response_args); |
|
339 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
340 | + ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
341 | + : ''); |
|
342 | + $payment->set_status($this->_pay_model->approved_status()); |
|
343 | + } else { |
|
344 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
345 | + $payment->set_gateway_response( |
|
346 | + $docheckout_response_args['L_ERRORCODE'] |
|
347 | + . '; ' |
|
348 | + . $docheckout_response_args['L_SHORTMESSAGE'] |
|
349 | + ); |
|
350 | + } else { |
|
351 | + $payment->set_gateway_response( |
|
352 | + esc_html__( |
|
353 | + 'Error occurred while trying to Capture the funds.', |
|
354 | + 'event_espresso' |
|
355 | + ) |
|
356 | + ); |
|
357 | + } |
|
358 | + $payment->set_details($docheckout_response_args); |
|
359 | + $payment->set_status($this->_pay_model->declined_status()); |
|
360 | + } |
|
361 | + } else { |
|
362 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
363 | + $payment->set_gateway_response( |
|
364 | + $cdata_response_args['L_ERRORCODE'] |
|
365 | + . '; ' |
|
366 | + . $cdata_response_args['L_SHORTMESSAGE'] |
|
367 | + ); |
|
368 | + } else { |
|
369 | + $payment->set_gateway_response( |
|
370 | + esc_html__( |
|
371 | + 'Error occurred while trying to get payment Details from PayPal.', |
|
372 | + 'event_espresso' |
|
373 | + ) |
|
374 | + ); |
|
375 | + } |
|
376 | + $payment->set_details($cdata_response_args); |
|
377 | + $payment->set_status($this->_pay_model->failed_status()); |
|
378 | + } |
|
379 | + } else { |
|
380 | + $payment->set_gateway_response( |
|
381 | + esc_html__( |
|
382 | + 'Error occurred while trying to process the payment.', |
|
383 | + 'event_espresso' |
|
384 | + ) |
|
385 | + ); |
|
386 | + $payment->set_status($this->_pay_model->failed_status()); |
|
387 | + } |
|
388 | + return $payment; |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * Make a list of items that are in the giver transaction. |
|
395 | + * |
|
396 | + * @param EEI_Payment $payment |
|
397 | + * @param EEI_Transaction $transaction |
|
398 | + * @param array $request_response_args Data from a previous communication with PP. |
|
399 | + * @return array |
|
400 | + */ |
|
401 | + public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
402 | + { |
|
403 | + $itemized_list = array(); |
|
404 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
405 | + // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
406 | + if (! empty($request_response_args) |
|
407 | + && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
408 | + && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
409 | + ) { |
|
410 | + foreach ($request_response_args as $arg_key => $arg_val) { |
|
411 | + if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
412 | + && strpos($arg_key, 'NOTIFYURL') === false |
|
413 | + ) { |
|
414 | + $itemized_list[ $arg_key ] = $arg_val; |
|
415 | + } |
|
416 | + } |
|
417 | + // If we got only a few Items then something is not right. |
|
418 | + if (count($itemized_list) > 2) { |
|
419 | + return $itemized_list; |
|
420 | + } else { |
|
421 | + if (WP_DEBUG) { |
|
422 | + throw new EE_Error( |
|
423 | + sprintf( |
|
424 | + esc_html__( |
|
425 | + // @codingStandardsIgnoreStart |
|
426 | + 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
427 | + // @codingStandardsIgnoreEnd |
|
428 | + 'event_espresso' |
|
429 | + ), |
|
430 | + wp_json_encode($itemized_list) |
|
431 | + ) |
|
432 | + ); |
|
433 | + } |
|
434 | + // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
435 | + $itemized_list = array(); |
|
436 | + $this->log( |
|
437 | + array( |
|
438 | + esc_html__( |
|
439 | + 'Could not generate a proper item list with:', |
|
440 | + 'event_espresso' |
|
441 | + ) => $request_response_args |
|
442 | + ), |
|
443 | + $payment |
|
444 | + ); |
|
445 | + } |
|
446 | + } |
|
447 | + // ...otherwise we generate a new list for this transaction. |
|
448 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
449 | + $item_num = 0; |
|
450 | + $itemized_sum = 0; |
|
451 | + $total_line_items = $transaction->total_line_item(); |
|
452 | + // Go through each item in the list. |
|
453 | + foreach ($total_line_items->get_items() as $line_item) { |
|
454 | + if ($line_item instanceof EE_Line_Item) { |
|
455 | + // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
456 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
457 | + continue; |
|
458 | + } |
|
459 | + $unit_price = $line_item->unit_price(); |
|
460 | + $line_item_quantity = $line_item->quantity(); |
|
461 | + // This is a discount. |
|
462 | + if ($line_item->is_percent()) { |
|
463 | + $unit_price = $line_item->total(); |
|
464 | + $line_item_quantity = 1; |
|
465 | + } |
|
466 | + // Item Name. |
|
467 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
468 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
469 | + 0, |
|
470 | + 127 |
|
471 | + ); |
|
472 | + // Item description. |
|
473 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
474 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
475 | + 0, |
|
476 | + 127 |
|
477 | + ); |
|
478 | + // Cost of individual item. |
|
479 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
480 | + // Item Number. |
|
481 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
482 | + // Item quantity. |
|
483 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
484 | + // Digital item is sold. |
|
485 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
486 | + $itemized_sum += $line_item->total(); |
|
487 | + ++$item_num; |
|
488 | + } |
|
489 | + } |
|
490 | + // Item's sales S/H and tax amount. |
|
491 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
492 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
493 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
494 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
495 | + $itemized_sum_diff_from_txn_total = round( |
|
496 | + $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
497 | + 2 |
|
498 | + ); |
|
499 | + // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
500 | + // add the difference as an extra line item. |
|
501 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
502 | + // Item Name. |
|
503 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
504 | + esc_html__( |
|
505 | + 'Other (promotion/surcharge/cancellation)', |
|
506 | + 'event_espresso' |
|
507 | + ), |
|
508 | + 0, |
|
509 | + 127 |
|
510 | + ); |
|
511 | + // Item description. |
|
512 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
513 | + // Cost of individual item. |
|
514 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
515 | + $itemized_sum_diff_from_txn_total |
|
516 | + ); |
|
517 | + // Item Number. |
|
518 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
519 | + // Item quantity. |
|
520 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
521 | + // Digital item is sold. |
|
522 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
523 | + $item_num++; |
|
524 | + } |
|
525 | + } else { |
|
526 | + // Just one Item. |
|
527 | + // Item Name. |
|
528 | + $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
529 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
530 | + 0, |
|
531 | + 127 |
|
532 | + ); |
|
533 | + // Item description. |
|
534 | + $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
535 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
536 | + 0, |
|
537 | + 127 |
|
538 | + ); |
|
539 | + // Cost of individual item. |
|
540 | + $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
541 | + // Item Number. |
|
542 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
543 | + // Item quantity. |
|
544 | + $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
545 | + // Digital item is sold. |
|
546 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
547 | + // Item's sales S/H and tax amount. |
|
548 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
549 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
550 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
551 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
552 | + } |
|
553 | + return $itemized_list; |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * Make the Express checkout request. |
|
560 | + * |
|
561 | + * @param array $request_params |
|
562 | + * @param string $request_text |
|
563 | + * @param EEI_Payment $payment |
|
564 | + * @return mixed |
|
565 | + */ |
|
566 | + public function _ppExpress_request($request_params, $request_text, $payment) |
|
567 | + { |
|
568 | + $request_dtls = array( |
|
569 | + 'VERSION' => '204.0', |
|
570 | + 'USER' => urlencode($this->_api_username), |
|
571 | + 'PWD' => urlencode($this->_api_password), |
|
572 | + 'SIGNATURE' => urlencode($this->_api_signature), |
|
573 | + ); |
|
574 | + $dtls = array_merge($request_dtls, $request_params); |
|
575 | + $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
576 | + // Request Customer Details. |
|
577 | + $request_response = wp_remote_post( |
|
578 | + $this->_base_gateway_url, |
|
579 | + array( |
|
580 | + 'method' => 'POST', |
|
581 | + 'timeout' => 45, |
|
582 | + 'httpversion' => '1.1', |
|
583 | + 'cookies' => array(), |
|
584 | + 'headers' => array(), |
|
585 | + 'body' => http_build_query($dtls, '', '&'), |
|
586 | + ) |
|
587 | + ); |
|
588 | + // Log the response. |
|
589 | + $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
590 | + return $request_response; |
|
591 | + } |
|
592 | + |
|
593 | + |
|
594 | + |
|
595 | + /** |
|
596 | + * Check the response status. |
|
597 | + * |
|
598 | + * @param mixed $request_response |
|
599 | + * @return array |
|
600 | + */ |
|
601 | + public function _ppExpress_check_response($request_response) |
|
602 | + { |
|
603 | + if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
604 | + // If we got here then there was an error in this request. |
|
605 | + return array('status' => false, 'args' => $request_response); |
|
606 | + } |
|
607 | + $response_args = array(); |
|
608 | + parse_str(urldecode($request_response['body']), $response_args); |
|
609 | + if (! isset($response_args['ACK'])) { |
|
610 | + return array('status' => false, 'args' => $request_response); |
|
611 | + } |
|
612 | + if (( |
|
613 | + isset($response_args['PAYERID']) |
|
614 | + || isset($response_args['TOKEN']) |
|
615 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
616 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
617 | + ) |
|
618 | + && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
619 | + ) { |
|
620 | + // Response status OK, return response parameters for further processing. |
|
621 | + return array('status' => true, 'args' => $response_args); |
|
622 | + } |
|
623 | + $errors = $this->_get_errors($response_args); |
|
624 | + return array('status' => false, 'args' => $errors); |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + |
|
629 | + /** |
|
630 | + * Log a "Cleared" request. |
|
631 | + * |
|
632 | + * @param array $request |
|
633 | + * @param EEI_Payment $payment |
|
634 | + * @param string $info |
|
635 | + * @return void |
|
636 | + */ |
|
637 | + private function _log_clean_request($request, $payment, $info) |
|
638 | + { |
|
639 | + $cleaned_request_data = $request; |
|
640 | + unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
641 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
642 | + } |
|
643 | + |
|
644 | + |
|
645 | + |
|
646 | + /** |
|
647 | + * Get error from the response data. |
|
648 | + * |
|
649 | + * @param array $data_array |
|
650 | + * @return array |
|
651 | + */ |
|
652 | + private function _get_errors($data_array) |
|
653 | + { |
|
654 | + $errors = array(); |
|
655 | + $n = 0; |
|
656 | + while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
657 | + $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
658 | + ? $data_array[ "L_ERRORCODE{$n}" ] |
|
659 | + : ''; |
|
660 | + $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
661 | + ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
662 | + : ''; |
|
663 | + $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
664 | + ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
665 | + : ''; |
|
666 | + $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
667 | + ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
668 | + : ''; |
|
669 | + if ($n === 0) { |
|
670 | + $errors = array( |
|
671 | + 'L_ERRORCODE' => $l_error_code, |
|
672 | + 'L_SHORTMESSAGE' => $l_short_message, |
|
673 | + 'L_LONGMESSAGE' => $l_long_message, |
|
674 | + 'L_SEVERITYCODE' => $l_severity_code, |
|
675 | + ); |
|
676 | + } else { |
|
677 | + $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
678 | + $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
679 | + $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
680 | + $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
681 | + } |
|
682 | + $n++; |
|
683 | + } |
|
684 | + return $errors; |
|
685 | + } |
|
686 | 686 | } |
@@ -25,427 +25,427 @@ discard block |
||
25 | 25 | class EEG_Aim extends EE_Onsite_Gateway |
26 | 26 | { |
27 | 27 | |
28 | - const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; // Authnet URL |
|
29 | - |
|
30 | - const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; |
|
31 | - |
|
32 | - protected $_login_id; |
|
33 | - |
|
34 | - protected $_transaction_key; |
|
35 | - |
|
36 | - protected $_server; |
|
37 | - |
|
38 | - protected $_currencies_supported = array( |
|
39 | - 'AUD', |
|
40 | - 'USD', |
|
41 | - 'CAD', |
|
42 | - 'EUR', |
|
43 | - 'GBP', |
|
44 | - 'NZD', |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Whether to send test transactions (even to live site) |
|
49 | - * |
|
50 | - * @var boolean |
|
51 | - */ |
|
52 | - protected $_test_transactions; |
|
53 | - |
|
54 | - private $VERIFY_PEER = false; |
|
55 | - |
|
56 | - private $_x_post_fields = array( |
|
57 | - "version" => "3.1", |
|
58 | - "delim_char" => ",", |
|
59 | - "delim_data" => "TRUE", |
|
60 | - "relay_response" => "FALSE", |
|
61 | - "encap_char" => "|", |
|
62 | - ); |
|
63 | - |
|
64 | - private $_additional_line_items = array(); |
|
65 | - |
|
66 | - /** |
|
67 | - * A list of all fields in the AIM API. |
|
68 | - * Used to warn user if they try to set a field not offered in the API. |
|
69 | - */ |
|
70 | - private $_all_aim_fields = array( |
|
71 | - "address", |
|
72 | - "allow_partial_auth", |
|
73 | - "amount", |
|
74 | - "auth_code", |
|
75 | - "authentication_indicator", |
|
76 | - "bank_aba_code", |
|
77 | - "bank_acct_name", |
|
78 | - "bank_acct_num", |
|
79 | - "bank_acct_type", |
|
80 | - "bank_check_number", |
|
81 | - "bank_name", |
|
82 | - "card_code", |
|
83 | - "card_num", |
|
84 | - "cardholder_authentication_value", |
|
85 | - "city", |
|
86 | - "company", |
|
87 | - "country", |
|
88 | - "cust_id", |
|
89 | - "customer_ip", |
|
90 | - "delim_char", |
|
91 | - "delim_data", |
|
92 | - "description", |
|
93 | - "duplicate_window", |
|
94 | - "duty", |
|
95 | - "echeck_type", |
|
96 | - "email", |
|
97 | - "email_customer", |
|
98 | - "encap_char", |
|
99 | - "exp_date", |
|
100 | - "fax", |
|
101 | - "first_name", |
|
102 | - "footer_email_receipt", |
|
103 | - "freight", |
|
104 | - "header_email_receipt", |
|
105 | - "invoice_num", |
|
106 | - "last_name", |
|
107 | - "line_item", |
|
108 | - "login", |
|
109 | - "method", |
|
110 | - "phone", |
|
111 | - "po_num", |
|
112 | - "recurring_billing", |
|
113 | - "relay_response", |
|
114 | - "ship_to_address", |
|
115 | - "ship_to_city", |
|
116 | - "ship_to_company", |
|
117 | - "ship_to_country", |
|
118 | - "ship_to_first_name", |
|
119 | - "ship_to_last_name", |
|
120 | - "ship_to_state", |
|
121 | - "ship_to_zip", |
|
122 | - "split_tender_id", |
|
123 | - "state", |
|
124 | - "tax", |
|
125 | - "tax_exempt", |
|
126 | - "test_request", |
|
127 | - "tran_key", |
|
128 | - "trans_id", |
|
129 | - "type", |
|
130 | - "version", |
|
131 | - "zip", |
|
132 | - "solution_id", |
|
133 | - "currency_code" |
|
134 | - ); |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * Gets the URL where the request should go. This is filterable |
|
139 | - * |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - protected function _get_server_url() |
|
143 | - { |
|
144 | - return apply_filters( |
|
145 | - 'FHEE__EEG_Aim___get_server_url', |
|
146 | - $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL, |
|
147 | - $this |
|
148 | - ); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * TEMPORARY CALLBACK! Do not use |
|
154 | - * Callback which filters the server url. This is added so site admins can revert to using |
|
155 | - * the old AIM server in case Akamai service breaks their integration. |
|
156 | - * Using Akamai will, however, be mandatory on June 30th 2016 Authorize.net |
|
157 | - * (see http://www.authorize.net/support/akamaifaqs/#firewall?utm_campaign=April%202016%20Technical%20Updates%20for%20Merchants.html&utm_medium=email&utm_source=Eloqua&elqTrackId=46103bdc375c411a979c2f658fc99074&elq=7026706360154fee9b6d588b27d8eb6a&elqaid=506&elqat=1&elqCampaignId=343) |
|
158 | - * Once that happens, this will be obsolete and WILL BE REMOVED. |
|
159 | - * |
|
160 | - * @param string $url |
|
161 | - * @param EEG_Aim $gateway_object |
|
162 | - * @return string |
|
163 | - */ |
|
164 | - public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object) |
|
165 | - { |
|
166 | - if ($gateway_object->_server === 'authorize.net' && ! $gateway_object->_debug_mode) { |
|
167 | - return 'https://secure.authorize.net/gateway/transact.dll'; |
|
168 | - } else { |
|
169 | - return $url; |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Asks the gateway to do whatever it does to process the payment. Onsite gateways will |
|
176 | - * usually send a request directly to the payment provider and update the payment's status based on that; |
|
177 | - * whereas offsite gateways will usually just update the payment with the URL and query parameters to use |
|
178 | - * for sending the request via http_remote_request() |
|
179 | - * |
|
180 | - * @param EEI_Payment $payment |
|
181 | - * @param array $billing_info { |
|
182 | - * @type $credit_card string |
|
183 | - * @type $cvv string |
|
184 | - * @type $exp_month string |
|
185 | - * @type $exp_year string |
|
186 | - * @see parent::do_direct_payment |
|
187 | - * } |
|
188 | - * @return EEI_Payment updated |
|
189 | - */ |
|
190 | - public function do_direct_payment($payment, $billing_info = null) |
|
191 | - { |
|
192 | - add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2); |
|
193 | - // Enable test mode if needed |
|
194 | - // 4007000000027 <-- test successful visa |
|
195 | - // 4222222222222 <-- test failure card number |
|
196 | - |
|
197 | - $item_num = 1; |
|
198 | - $transaction = $payment->transaction(); |
|
199 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
200 | - $order_description = $gateway_formatter->formatOrderDescription($payment); |
|
201 | - $primary_registrant = $transaction->primary_registration(); |
|
202 | - // if we're are charging for the full amount, show the normal line items |
|
203 | - // and the itemized total adds up properly |
|
204 | - if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
205 | - $total_line_item = $transaction->total_line_item(); |
|
206 | - foreach ($total_line_item->get_items() as $line_item) { |
|
207 | - if ($line_item->quantity() == 0) { |
|
208 | - continue; |
|
209 | - } |
|
210 | - $this->addLineItem( |
|
211 | - $item_num++, |
|
212 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
213 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
214 | - $line_item->quantity(), |
|
215 | - $line_item->unit_price(), |
|
216 | - 'N' |
|
217 | - ); |
|
218 | - $order_description .= $line_item->desc().', '; |
|
219 | - } |
|
220 | - foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
221 | - $this->addLineItem( |
|
222 | - $item_num++, |
|
223 | - $tax_line_item->name(), |
|
224 | - $tax_line_item->desc(), |
|
225 | - 1, |
|
226 | - $tax_line_item->total(), |
|
227 | - 'N' |
|
228 | - ); |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - // start transaction |
|
233 | - // if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
|
234 | - $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
|
235 | - $this->setField('solution_id', $partner_id); |
|
236 | - $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount())); |
|
237 | - $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
238 | - $this->_set_sensitive_billing_data($billing_info); |
|
239 | - $this->setField('first_name', $billing_info['first_name']); |
|
240 | - $this->setField('last_name', $billing_info['last_name']); |
|
241 | - $this->setField('email', $billing_info['email']); |
|
242 | - $this->setField('company', $billing_info['company']); |
|
243 | - $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
|
244 | - $this->setField('city', $billing_info['city']); |
|
245 | - $this->setField('state', $billing_info['state']); |
|
246 | - $this->setField('country', $billing_info['country']); |
|
247 | - $this->setField('zip', $billing_info['zip']); |
|
248 | - $this->setField('fax', $billing_info['fax']); |
|
249 | - $this->setField('cust_id', $primary_registrant->ID()); |
|
250 | - $this->setField('phone', $billing_info['phone']); |
|
251 | - $currency_config = LoaderFactory::getLoader()->load('EE_Currency_Config'); |
|
252 | - $this->setField('currency_code', $currency_config->code); |
|
253 | - // invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
|
254 | - // press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
|
255 | - // in which case, we need to generate teh invoice num per request right here... |
|
256 | - $this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
257 | - // tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
|
258 | - $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
259 | - |
|
260 | - if ($this->_test_transactions) { |
|
261 | - $this->test_request = "true"; |
|
262 | - } |
|
263 | - |
|
264 | - // Capture response |
|
265 | - $this->type = "AUTH_CAPTURE"; |
|
266 | - $response = $this->_sendRequest($payment); |
|
267 | - if (! empty($response)) { |
|
268 | - if ($response->error_message) { |
|
269 | - $payment->set_status($this->_pay_model->failed_status()); |
|
270 | - $payment->set_gateway_response($response->error_message); |
|
271 | - } else { |
|
272 | - $payment_status = $response->approved |
|
273 | - ? $this->_pay_model->approved_status() |
|
274 | - : $this->_pay_model->declined_status(); |
|
275 | - $payment->set_status($payment_status); |
|
276 | - // make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
277 | - $payment->set_amount((float) $response->amount); |
|
278 | - $payment->set_gateway_response( |
|
279 | - sprintf( |
|
280 | - esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
|
281 | - $response->response_reason_text, |
|
282 | - $response->response_reason_code |
|
283 | - ) |
|
284 | - ); |
|
285 | - if ($this->_debug_mode) { |
|
286 | - $txn_id = $response->invoice_number; |
|
287 | - } else { |
|
288 | - $txn_id = $response->transaction_id; |
|
289 | - } |
|
290 | - $payment->set_txn_id_chq_nmbr($txn_id); |
|
291 | - } |
|
292 | - $payment->set_extra_accntng($primary_registrant->reg_code()); |
|
293 | - $payment->set_details(print_r($response, true)); |
|
294 | - } else { |
|
295 | - $payment->set_status($this->_pay_model->failed_status()); |
|
296 | - $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
|
297 | - $payment->set_details(print_r($response, true)); |
|
298 | - } |
|
299 | - return $payment; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * Sets billing data for the upcoming request to AIM that is considered sensitive; |
|
305 | - * also this method can be overridden by children classes to easily change |
|
306 | - * what billing data gets sent |
|
307 | - * |
|
308 | - * @param array $billing_info |
|
309 | - */ |
|
310 | - protected function _set_sensitive_billing_data($billing_info) |
|
311 | - { |
|
312 | - $this->setField('card_num', $billing_info['credit_card']); |
|
313 | - $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
314 | - $this->setField('card_code', $billing_info['cvv']); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Add a line item. |
|
320 | - * |
|
321 | - * @param string $item_id |
|
322 | - * @param string $item_name |
|
323 | - * @param string $item_description |
|
324 | - * @param string $item_quantity |
|
325 | - * @param string $item_unit_price |
|
326 | - * @param string $item_taxable |
|
327 | - */ |
|
328 | - public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable) |
|
329 | - { |
|
330 | - $args = array( |
|
331 | - substr($item_id, 0, 31), |
|
332 | - substr($item_name, 0, 31), |
|
333 | - substr($item_description, 0, 255), |
|
334 | - number_format(abs($item_quantity), 2, '.', ''), |
|
335 | - number_format(abs($item_unit_price), 2, '.', ''), |
|
336 | - $item_taxable === 'N' ? 'N' : 'Y' |
|
337 | - ); |
|
338 | - $this->_additional_line_items[] = implode('<|>', $args); |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * Set an individual name/value pair. This will append x_ to the name |
|
344 | - * before posting. |
|
345 | - * |
|
346 | - * @param string $name |
|
347 | - * @param string $value |
|
348 | - * @throws AuthorizeNetException |
|
349 | - */ |
|
350 | - protected function setField($name, $value) |
|
351 | - { |
|
352 | - if (in_array($name, $this->_all_aim_fields)) { |
|
353 | - $this->_x_post_fields[ $name ] = $value; |
|
354 | - } else { |
|
355 | - throw new AuthorizeNetException("Error: no field $name exists in the AIM API. |
|
28 | + const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; // Authnet URL |
|
29 | + |
|
30 | + const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; |
|
31 | + |
|
32 | + protected $_login_id; |
|
33 | + |
|
34 | + protected $_transaction_key; |
|
35 | + |
|
36 | + protected $_server; |
|
37 | + |
|
38 | + protected $_currencies_supported = array( |
|
39 | + 'AUD', |
|
40 | + 'USD', |
|
41 | + 'CAD', |
|
42 | + 'EUR', |
|
43 | + 'GBP', |
|
44 | + 'NZD', |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Whether to send test transactions (even to live site) |
|
49 | + * |
|
50 | + * @var boolean |
|
51 | + */ |
|
52 | + protected $_test_transactions; |
|
53 | + |
|
54 | + private $VERIFY_PEER = false; |
|
55 | + |
|
56 | + private $_x_post_fields = array( |
|
57 | + "version" => "3.1", |
|
58 | + "delim_char" => ",", |
|
59 | + "delim_data" => "TRUE", |
|
60 | + "relay_response" => "FALSE", |
|
61 | + "encap_char" => "|", |
|
62 | + ); |
|
63 | + |
|
64 | + private $_additional_line_items = array(); |
|
65 | + |
|
66 | + /** |
|
67 | + * A list of all fields in the AIM API. |
|
68 | + * Used to warn user if they try to set a field not offered in the API. |
|
69 | + */ |
|
70 | + private $_all_aim_fields = array( |
|
71 | + "address", |
|
72 | + "allow_partial_auth", |
|
73 | + "amount", |
|
74 | + "auth_code", |
|
75 | + "authentication_indicator", |
|
76 | + "bank_aba_code", |
|
77 | + "bank_acct_name", |
|
78 | + "bank_acct_num", |
|
79 | + "bank_acct_type", |
|
80 | + "bank_check_number", |
|
81 | + "bank_name", |
|
82 | + "card_code", |
|
83 | + "card_num", |
|
84 | + "cardholder_authentication_value", |
|
85 | + "city", |
|
86 | + "company", |
|
87 | + "country", |
|
88 | + "cust_id", |
|
89 | + "customer_ip", |
|
90 | + "delim_char", |
|
91 | + "delim_data", |
|
92 | + "description", |
|
93 | + "duplicate_window", |
|
94 | + "duty", |
|
95 | + "echeck_type", |
|
96 | + "email", |
|
97 | + "email_customer", |
|
98 | + "encap_char", |
|
99 | + "exp_date", |
|
100 | + "fax", |
|
101 | + "first_name", |
|
102 | + "footer_email_receipt", |
|
103 | + "freight", |
|
104 | + "header_email_receipt", |
|
105 | + "invoice_num", |
|
106 | + "last_name", |
|
107 | + "line_item", |
|
108 | + "login", |
|
109 | + "method", |
|
110 | + "phone", |
|
111 | + "po_num", |
|
112 | + "recurring_billing", |
|
113 | + "relay_response", |
|
114 | + "ship_to_address", |
|
115 | + "ship_to_city", |
|
116 | + "ship_to_company", |
|
117 | + "ship_to_country", |
|
118 | + "ship_to_first_name", |
|
119 | + "ship_to_last_name", |
|
120 | + "ship_to_state", |
|
121 | + "ship_to_zip", |
|
122 | + "split_tender_id", |
|
123 | + "state", |
|
124 | + "tax", |
|
125 | + "tax_exempt", |
|
126 | + "test_request", |
|
127 | + "tran_key", |
|
128 | + "trans_id", |
|
129 | + "type", |
|
130 | + "version", |
|
131 | + "zip", |
|
132 | + "solution_id", |
|
133 | + "currency_code" |
|
134 | + ); |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * Gets the URL where the request should go. This is filterable |
|
139 | + * |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + protected function _get_server_url() |
|
143 | + { |
|
144 | + return apply_filters( |
|
145 | + 'FHEE__EEG_Aim___get_server_url', |
|
146 | + $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL, |
|
147 | + $this |
|
148 | + ); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * TEMPORARY CALLBACK! Do not use |
|
154 | + * Callback which filters the server url. This is added so site admins can revert to using |
|
155 | + * the old AIM server in case Akamai service breaks their integration. |
|
156 | + * Using Akamai will, however, be mandatory on June 30th 2016 Authorize.net |
|
157 | + * (see http://www.authorize.net/support/akamaifaqs/#firewall?utm_campaign=April%202016%20Technical%20Updates%20for%20Merchants.html&utm_medium=email&utm_source=Eloqua&elqTrackId=46103bdc375c411a979c2f658fc99074&elq=7026706360154fee9b6d588b27d8eb6a&elqaid=506&elqat=1&elqCampaignId=343) |
|
158 | + * Once that happens, this will be obsolete and WILL BE REMOVED. |
|
159 | + * |
|
160 | + * @param string $url |
|
161 | + * @param EEG_Aim $gateway_object |
|
162 | + * @return string |
|
163 | + */ |
|
164 | + public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object) |
|
165 | + { |
|
166 | + if ($gateway_object->_server === 'authorize.net' && ! $gateway_object->_debug_mode) { |
|
167 | + return 'https://secure.authorize.net/gateway/transact.dll'; |
|
168 | + } else { |
|
169 | + return $url; |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Asks the gateway to do whatever it does to process the payment. Onsite gateways will |
|
176 | + * usually send a request directly to the payment provider and update the payment's status based on that; |
|
177 | + * whereas offsite gateways will usually just update the payment with the URL and query parameters to use |
|
178 | + * for sending the request via http_remote_request() |
|
179 | + * |
|
180 | + * @param EEI_Payment $payment |
|
181 | + * @param array $billing_info { |
|
182 | + * @type $credit_card string |
|
183 | + * @type $cvv string |
|
184 | + * @type $exp_month string |
|
185 | + * @type $exp_year string |
|
186 | + * @see parent::do_direct_payment |
|
187 | + * } |
|
188 | + * @return EEI_Payment updated |
|
189 | + */ |
|
190 | + public function do_direct_payment($payment, $billing_info = null) |
|
191 | + { |
|
192 | + add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2); |
|
193 | + // Enable test mode if needed |
|
194 | + // 4007000000027 <-- test successful visa |
|
195 | + // 4222222222222 <-- test failure card number |
|
196 | + |
|
197 | + $item_num = 1; |
|
198 | + $transaction = $payment->transaction(); |
|
199 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
200 | + $order_description = $gateway_formatter->formatOrderDescription($payment); |
|
201 | + $primary_registrant = $transaction->primary_registration(); |
|
202 | + // if we're are charging for the full amount, show the normal line items |
|
203 | + // and the itemized total adds up properly |
|
204 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
205 | + $total_line_item = $transaction->total_line_item(); |
|
206 | + foreach ($total_line_item->get_items() as $line_item) { |
|
207 | + if ($line_item->quantity() == 0) { |
|
208 | + continue; |
|
209 | + } |
|
210 | + $this->addLineItem( |
|
211 | + $item_num++, |
|
212 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
213 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
214 | + $line_item->quantity(), |
|
215 | + $line_item->unit_price(), |
|
216 | + 'N' |
|
217 | + ); |
|
218 | + $order_description .= $line_item->desc().', '; |
|
219 | + } |
|
220 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
221 | + $this->addLineItem( |
|
222 | + $item_num++, |
|
223 | + $tax_line_item->name(), |
|
224 | + $tax_line_item->desc(), |
|
225 | + 1, |
|
226 | + $tax_line_item->total(), |
|
227 | + 'N' |
|
228 | + ); |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + // start transaction |
|
233 | + // if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
|
234 | + $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
|
235 | + $this->setField('solution_id', $partner_id); |
|
236 | + $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount())); |
|
237 | + $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
238 | + $this->_set_sensitive_billing_data($billing_info); |
|
239 | + $this->setField('first_name', $billing_info['first_name']); |
|
240 | + $this->setField('last_name', $billing_info['last_name']); |
|
241 | + $this->setField('email', $billing_info['email']); |
|
242 | + $this->setField('company', $billing_info['company']); |
|
243 | + $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
|
244 | + $this->setField('city', $billing_info['city']); |
|
245 | + $this->setField('state', $billing_info['state']); |
|
246 | + $this->setField('country', $billing_info['country']); |
|
247 | + $this->setField('zip', $billing_info['zip']); |
|
248 | + $this->setField('fax', $billing_info['fax']); |
|
249 | + $this->setField('cust_id', $primary_registrant->ID()); |
|
250 | + $this->setField('phone', $billing_info['phone']); |
|
251 | + $currency_config = LoaderFactory::getLoader()->load('EE_Currency_Config'); |
|
252 | + $this->setField('currency_code', $currency_config->code); |
|
253 | + // invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
|
254 | + // press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
|
255 | + // in which case, we need to generate teh invoice num per request right here... |
|
256 | + $this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
257 | + // tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
|
258 | + $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
259 | + |
|
260 | + if ($this->_test_transactions) { |
|
261 | + $this->test_request = "true"; |
|
262 | + } |
|
263 | + |
|
264 | + // Capture response |
|
265 | + $this->type = "AUTH_CAPTURE"; |
|
266 | + $response = $this->_sendRequest($payment); |
|
267 | + if (! empty($response)) { |
|
268 | + if ($response->error_message) { |
|
269 | + $payment->set_status($this->_pay_model->failed_status()); |
|
270 | + $payment->set_gateway_response($response->error_message); |
|
271 | + } else { |
|
272 | + $payment_status = $response->approved |
|
273 | + ? $this->_pay_model->approved_status() |
|
274 | + : $this->_pay_model->declined_status(); |
|
275 | + $payment->set_status($payment_status); |
|
276 | + // make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
277 | + $payment->set_amount((float) $response->amount); |
|
278 | + $payment->set_gateway_response( |
|
279 | + sprintf( |
|
280 | + esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
|
281 | + $response->response_reason_text, |
|
282 | + $response->response_reason_code |
|
283 | + ) |
|
284 | + ); |
|
285 | + if ($this->_debug_mode) { |
|
286 | + $txn_id = $response->invoice_number; |
|
287 | + } else { |
|
288 | + $txn_id = $response->transaction_id; |
|
289 | + } |
|
290 | + $payment->set_txn_id_chq_nmbr($txn_id); |
|
291 | + } |
|
292 | + $payment->set_extra_accntng($primary_registrant->reg_code()); |
|
293 | + $payment->set_details(print_r($response, true)); |
|
294 | + } else { |
|
295 | + $payment->set_status($this->_pay_model->failed_status()); |
|
296 | + $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
|
297 | + $payment->set_details(print_r($response, true)); |
|
298 | + } |
|
299 | + return $payment; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * Sets billing data for the upcoming request to AIM that is considered sensitive; |
|
305 | + * also this method can be overridden by children classes to easily change |
|
306 | + * what billing data gets sent |
|
307 | + * |
|
308 | + * @param array $billing_info |
|
309 | + */ |
|
310 | + protected function _set_sensitive_billing_data($billing_info) |
|
311 | + { |
|
312 | + $this->setField('card_num', $billing_info['credit_card']); |
|
313 | + $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
314 | + $this->setField('card_code', $billing_info['cvv']); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Add a line item. |
|
320 | + * |
|
321 | + * @param string $item_id |
|
322 | + * @param string $item_name |
|
323 | + * @param string $item_description |
|
324 | + * @param string $item_quantity |
|
325 | + * @param string $item_unit_price |
|
326 | + * @param string $item_taxable |
|
327 | + */ |
|
328 | + public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable) |
|
329 | + { |
|
330 | + $args = array( |
|
331 | + substr($item_id, 0, 31), |
|
332 | + substr($item_name, 0, 31), |
|
333 | + substr($item_description, 0, 255), |
|
334 | + number_format(abs($item_quantity), 2, '.', ''), |
|
335 | + number_format(abs($item_unit_price), 2, '.', ''), |
|
336 | + $item_taxable === 'N' ? 'N' : 'Y' |
|
337 | + ); |
|
338 | + $this->_additional_line_items[] = implode('<|>', $args); |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * Set an individual name/value pair. This will append x_ to the name |
|
344 | + * before posting. |
|
345 | + * |
|
346 | + * @param string $name |
|
347 | + * @param string $value |
|
348 | + * @throws AuthorizeNetException |
|
349 | + */ |
|
350 | + protected function setField($name, $value) |
|
351 | + { |
|
352 | + if (in_array($name, $this->_all_aim_fields)) { |
|
353 | + $this->_x_post_fields[ $name ] = $value; |
|
354 | + } else { |
|
355 | + throw new AuthorizeNetException("Error: no field $name exists in the AIM API. |
|
356 | 356 | To set a custom field use setCustomField('field','value') instead."); |
357 | - } |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * Posts the request to AuthorizeNet & returns response. |
|
363 | - * |
|
364 | - * @param $payment |
|
365 | - * @return \EE_AuthorizeNetAIM_Response |
|
366 | - */ |
|
367 | - private function _sendRequest($payment) |
|
368 | - { |
|
369 | - $this->_x_post_fields['login'] = $this->_login_id; |
|
370 | - $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
|
371 | - $x_keys = array(); |
|
372 | - foreach ($this->_x_post_fields as $key => $value) { |
|
373 | - $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
374 | - } |
|
375 | - // Add line items |
|
376 | - foreach ($this->_additional_line_items as $key => $value) { |
|
377 | - $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
378 | - } |
|
379 | - $this->_log_clean_request($x_keys, $payment); |
|
380 | - $post_url = $this->_get_server_url(); |
|
381 | - $curl_request = curl_init($post_url); |
|
382 | - $post_body = implode("&", $x_keys); |
|
383 | - curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
|
384 | - curl_setopt($curl_request, CURLOPT_HEADER, 0); |
|
385 | - curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
|
386 | - curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
|
387 | - curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
|
388 | - if ($this->VERIFY_PEER) { |
|
389 | - curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
390 | - } else { |
|
391 | - curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
|
392 | - } |
|
393 | - |
|
394 | - if (preg_match('/xml/', $post_url)) { |
|
395 | - curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); |
|
396 | - } |
|
397 | - |
|
398 | - $response = curl_exec($curl_request); |
|
399 | - |
|
400 | - curl_close($curl_request); |
|
401 | - $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
402 | - |
|
403 | - return $this->_log_and_clean_response($response_obj, $payment); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * Logs the clean data only |
|
409 | - * |
|
410 | - * @param array $request_array |
|
411 | - * @param EEI_Payment $payment |
|
412 | - */ |
|
413 | - protected function _log_clean_request($request_array, $payment) |
|
414 | - { |
|
415 | - $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
416 | - foreach ($request_array as $index => $keyvaltogether) { |
|
417 | - foreach ($keys_to_filter_out as $key) { |
|
418 | - if (strpos($keyvaltogether, $key) === 0) { |
|
419 | - // found it at the first character |
|
420 | - // so its one of them |
|
421 | - unset($request_array[ $index ]); |
|
422 | - } |
|
423 | - } |
|
424 | - } |
|
425 | - $this->log( |
|
426 | - array( |
|
427 | - 'AIM Request sent:' => $request_array, |
|
428 | - 'Server URL' => $this->_get_server_url() |
|
429 | - ), |
|
430 | - $payment |
|
431 | - ); |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Logs the response and cleans it |
|
438 | - * |
|
439 | - * @param EE_AuthorizeNetAIM_Response $response_obj |
|
440 | - * @param EE_Payment $payment |
|
441 | - * @return \EE_AuthorizeNetAIM_Response |
|
442 | - */ |
|
443 | - private function _log_and_clean_response($response_obj, $payment) |
|
444 | - { |
|
445 | - $response_obj->account_number = ''; |
|
446 | - $this->log(array('AIM Response received:' => (array) $response_obj), $payment); |
|
447 | - return $response_obj; |
|
448 | - } |
|
357 | + } |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * Posts the request to AuthorizeNet & returns response. |
|
363 | + * |
|
364 | + * @param $payment |
|
365 | + * @return \EE_AuthorizeNetAIM_Response |
|
366 | + */ |
|
367 | + private function _sendRequest($payment) |
|
368 | + { |
|
369 | + $this->_x_post_fields['login'] = $this->_login_id; |
|
370 | + $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
|
371 | + $x_keys = array(); |
|
372 | + foreach ($this->_x_post_fields as $key => $value) { |
|
373 | + $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
374 | + } |
|
375 | + // Add line items |
|
376 | + foreach ($this->_additional_line_items as $key => $value) { |
|
377 | + $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
378 | + } |
|
379 | + $this->_log_clean_request($x_keys, $payment); |
|
380 | + $post_url = $this->_get_server_url(); |
|
381 | + $curl_request = curl_init($post_url); |
|
382 | + $post_body = implode("&", $x_keys); |
|
383 | + curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
|
384 | + curl_setopt($curl_request, CURLOPT_HEADER, 0); |
|
385 | + curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
|
386 | + curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
|
387 | + curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
|
388 | + if ($this->VERIFY_PEER) { |
|
389 | + curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
390 | + } else { |
|
391 | + curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
|
392 | + } |
|
393 | + |
|
394 | + if (preg_match('/xml/', $post_url)) { |
|
395 | + curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); |
|
396 | + } |
|
397 | + |
|
398 | + $response = curl_exec($curl_request); |
|
399 | + |
|
400 | + curl_close($curl_request); |
|
401 | + $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
402 | + |
|
403 | + return $this->_log_and_clean_response($response_obj, $payment); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * Logs the clean data only |
|
409 | + * |
|
410 | + * @param array $request_array |
|
411 | + * @param EEI_Payment $payment |
|
412 | + */ |
|
413 | + protected function _log_clean_request($request_array, $payment) |
|
414 | + { |
|
415 | + $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
416 | + foreach ($request_array as $index => $keyvaltogether) { |
|
417 | + foreach ($keys_to_filter_out as $key) { |
|
418 | + if (strpos($keyvaltogether, $key) === 0) { |
|
419 | + // found it at the first character |
|
420 | + // so its one of them |
|
421 | + unset($request_array[ $index ]); |
|
422 | + } |
|
423 | + } |
|
424 | + } |
|
425 | + $this->log( |
|
426 | + array( |
|
427 | + 'AIM Request sent:' => $request_array, |
|
428 | + 'Server URL' => $this->_get_server_url() |
|
429 | + ), |
|
430 | + $payment |
|
431 | + ); |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Logs the response and cleans it |
|
438 | + * |
|
439 | + * @param EE_AuthorizeNetAIM_Response $response_obj |
|
440 | + * @param EE_Payment $payment |
|
441 | + * @return \EE_AuthorizeNetAIM_Response |
|
442 | + */ |
|
443 | + private function _log_and_clean_response($response_obj, $payment) |
|
444 | + { |
|
445 | + $response_obj->account_number = ''; |
|
446 | + $this->log(array('AIM Response received:' => (array) $response_obj), $payment); |
|
447 | + return $response_obj; |
|
448 | + } |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | |
@@ -461,192 +461,192 @@ discard block |
||
461 | 461 | class EE_AuthorizeNetAIM_Response |
462 | 462 | { |
463 | 463 | |
464 | - const APPROVED = '1'; |
|
465 | - const DECLINED = '2'; |
|
466 | - const ERROR = '3'; |
|
467 | - const HELD = '4'; |
|
468 | - |
|
469 | - protected $_x_post_fields = array( |
|
470 | - "version" => "3.1", |
|
471 | - "delim_char" => ",", |
|
472 | - "delim_data" => "TRUE", |
|
473 | - "relay_response" => "FALSE", |
|
474 | - "encap_char" => "|", |
|
475 | - ); |
|
476 | - public $approved; |
|
477 | - public $declined; |
|
478 | - public $error; |
|
479 | - public $held; |
|
480 | - public $response_code; |
|
481 | - public $response_subcode; |
|
482 | - public $response_reason_code; |
|
483 | - public $response_reason_text; |
|
484 | - public $authorization_code; |
|
485 | - public $avs_response; |
|
486 | - public $transaction_id; |
|
487 | - public $invoice_number; |
|
488 | - public $description; |
|
489 | - public $amount; |
|
490 | - public $method; |
|
491 | - public $transaction_type; |
|
492 | - public $customer_id; |
|
493 | - public $first_name; |
|
494 | - public $last_name; |
|
495 | - public $company; |
|
496 | - public $address; |
|
497 | - public $city; |
|
498 | - public $state; |
|
499 | - public $zip_code; |
|
500 | - public $country; |
|
501 | - public $phone; |
|
502 | - public $fax; |
|
503 | - public $email_address; |
|
504 | - public $ship_to_first_name; |
|
505 | - public $ship_to_last_name; |
|
506 | - public $ship_to_company; |
|
507 | - public $ship_to_address; |
|
508 | - public $ship_to_city; |
|
509 | - public $ship_to_state; |
|
510 | - public $ship_to_zip_code; |
|
511 | - public $ship_to_country; |
|
512 | - public $tax; |
|
513 | - public $duty; |
|
514 | - public $freight; |
|
515 | - public $tax_exempt; |
|
516 | - public $purchase_order_number; |
|
517 | - public $md5_hash; |
|
518 | - public $card_code_response; |
|
519 | - public $cavv_response; // cardholder_authentication_verification_response |
|
520 | - public $account_number; |
|
521 | - public $card_type; |
|
522 | - public $split_tender_id; |
|
523 | - public $requested_amount; |
|
524 | - public $balance_on_card; |
|
525 | - public $response; // The response string from AuthorizeNet. |
|
526 | - public $error_message; |
|
527 | - private $_response_array = array(); // An array with the split response. |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * Constructor. Parses the AuthorizeNet response string |
|
532 | - * |
|
533 | - * @param string $response The response from the AuthNet server. |
|
534 | - * @var string $delimiter The delimiter used (default is ",") |
|
535 | - * @var string $encap_char The encap_char used (default is "|") |
|
536 | - * @var array $custom_fields Any custom fields set in the request. |
|
537 | - */ |
|
538 | - |
|
539 | - public function __construct($response) |
|
540 | - { |
|
541 | - $encap_char = $this->_x_post_fields['encap_char']; |
|
542 | - $delimiter = $this->_x_post_fields['delim_char']; |
|
543 | - if ($response) { |
|
544 | - // Split Array |
|
545 | - $this->response = $response; |
|
546 | - if ($encap_char) { |
|
547 | - $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
548 | - } else { |
|
549 | - $this->_response_array = explode($delimiter, $response); |
|
550 | - } |
|
551 | - |
|
552 | - /** |
|
553 | - * If AuthorizeNet doesn't return a delimited response. |
|
554 | - */ |
|
555 | - if (count($this->_response_array) < 10) { |
|
556 | - $this->approved = false; |
|
557 | - $this->error = true; |
|
558 | - $this->error_message = sprintf( |
|
559 | - esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'), |
|
560 | - esc_html($response) |
|
561 | - ); |
|
562 | - return; |
|
563 | - } |
|
564 | - |
|
565 | - |
|
566 | - |
|
567 | - // Set all fields |
|
568 | - $this->response_code = $this->_response_array[0]; |
|
569 | - $this->response_subcode = $this->_response_array[1]; |
|
570 | - $this->response_reason_code = $this->_response_array[2]; |
|
571 | - $this->response_reason_text = $this->_response_array[3]; |
|
572 | - $this->authorization_code = $this->_response_array[4]; |
|
573 | - $this->avs_response = $this->_response_array[5]; |
|
574 | - $this->transaction_id = $this->_response_array[6]; |
|
575 | - $this->invoice_number = $this->_response_array[7]; |
|
576 | - $this->description = $this->_response_array[8]; |
|
577 | - $this->amount = $this->_response_array[9]; |
|
578 | - $this->method = $this->_response_array[10]; |
|
579 | - $this->transaction_type = $this->_response_array[11]; |
|
580 | - $this->customer_id = $this->_response_array[12]; |
|
581 | - $this->first_name = $this->_response_array[13]; |
|
582 | - $this->last_name = $this->_response_array[14]; |
|
583 | - $this->company = $this->_response_array[15]; |
|
584 | - $this->address = $this->_response_array[16]; |
|
585 | - $this->city = $this->_response_array[17]; |
|
586 | - $this->state = $this->_response_array[18]; |
|
587 | - $this->zip_code = $this->_response_array[19]; |
|
588 | - $this->country = $this->_response_array[20]; |
|
589 | - $this->phone = $this->_response_array[21]; |
|
590 | - $this->fax = $this->_response_array[22]; |
|
591 | - $this->email_address = $this->_response_array[23]; |
|
592 | - $this->ship_to_first_name = $this->_response_array[24]; |
|
593 | - $this->ship_to_last_name = $this->_response_array[25]; |
|
594 | - $this->ship_to_company = $this->_response_array[26]; |
|
595 | - $this->ship_to_address = $this->_response_array[27]; |
|
596 | - $this->ship_to_city = $this->_response_array[28]; |
|
597 | - $this->ship_to_state = $this->_response_array[29]; |
|
598 | - $this->ship_to_zip_code = $this->_response_array[30]; |
|
599 | - $this->ship_to_country = $this->_response_array[31]; |
|
600 | - $this->tax = $this->_response_array[32]; |
|
601 | - $this->duty = $this->_response_array[33]; |
|
602 | - $this->freight = $this->_response_array[34]; |
|
603 | - $this->tax_exempt = $this->_response_array[35]; |
|
604 | - $this->purchase_order_number = $this->_response_array[36]; |
|
605 | - $this->md5_hash = $this->_response_array[37]; |
|
606 | - $this->card_code_response = $this->_response_array[38]; |
|
607 | - $this->cavv_response = $this->_response_array[39]; |
|
608 | - $this->account_number = $this->_response_array[50]; |
|
609 | - $this->card_type = $this->_response_array[51]; |
|
610 | - $this->split_tender_id = $this->_response_array[52]; |
|
611 | - $this->requested_amount = $this->_response_array[53]; |
|
612 | - $this->balance_on_card = $this->_response_array[54]; |
|
613 | - |
|
614 | - $this->approved = ($this->response_code === self::APPROVED); |
|
615 | - $this->declined = ($this->response_code === self::DECLINED); |
|
616 | - $this->error = ($this->response_code === self::ERROR); |
|
617 | - $this->held = ($this->response_code === self::HELD); |
|
618 | - } else { |
|
619 | - $this->approved = false; |
|
620 | - $this->error = true; |
|
621 | - $this->error_message = esc_html__( |
|
622 | - 'Error connecting to Authorize.net', |
|
623 | - 'event_espresso' |
|
624 | - ); |
|
625 | - } |
|
626 | - } |
|
464 | + const APPROVED = '1'; |
|
465 | + const DECLINED = '2'; |
|
466 | + const ERROR = '3'; |
|
467 | + const HELD = '4'; |
|
468 | + |
|
469 | + protected $_x_post_fields = array( |
|
470 | + "version" => "3.1", |
|
471 | + "delim_char" => ",", |
|
472 | + "delim_data" => "TRUE", |
|
473 | + "relay_response" => "FALSE", |
|
474 | + "encap_char" => "|", |
|
475 | + ); |
|
476 | + public $approved; |
|
477 | + public $declined; |
|
478 | + public $error; |
|
479 | + public $held; |
|
480 | + public $response_code; |
|
481 | + public $response_subcode; |
|
482 | + public $response_reason_code; |
|
483 | + public $response_reason_text; |
|
484 | + public $authorization_code; |
|
485 | + public $avs_response; |
|
486 | + public $transaction_id; |
|
487 | + public $invoice_number; |
|
488 | + public $description; |
|
489 | + public $amount; |
|
490 | + public $method; |
|
491 | + public $transaction_type; |
|
492 | + public $customer_id; |
|
493 | + public $first_name; |
|
494 | + public $last_name; |
|
495 | + public $company; |
|
496 | + public $address; |
|
497 | + public $city; |
|
498 | + public $state; |
|
499 | + public $zip_code; |
|
500 | + public $country; |
|
501 | + public $phone; |
|
502 | + public $fax; |
|
503 | + public $email_address; |
|
504 | + public $ship_to_first_name; |
|
505 | + public $ship_to_last_name; |
|
506 | + public $ship_to_company; |
|
507 | + public $ship_to_address; |
|
508 | + public $ship_to_city; |
|
509 | + public $ship_to_state; |
|
510 | + public $ship_to_zip_code; |
|
511 | + public $ship_to_country; |
|
512 | + public $tax; |
|
513 | + public $duty; |
|
514 | + public $freight; |
|
515 | + public $tax_exempt; |
|
516 | + public $purchase_order_number; |
|
517 | + public $md5_hash; |
|
518 | + public $card_code_response; |
|
519 | + public $cavv_response; // cardholder_authentication_verification_response |
|
520 | + public $account_number; |
|
521 | + public $card_type; |
|
522 | + public $split_tender_id; |
|
523 | + public $requested_amount; |
|
524 | + public $balance_on_card; |
|
525 | + public $response; // The response string from AuthorizeNet. |
|
526 | + public $error_message; |
|
527 | + private $_response_array = array(); // An array with the split response. |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * Constructor. Parses the AuthorizeNet response string |
|
532 | + * |
|
533 | + * @param string $response The response from the AuthNet server. |
|
534 | + * @var string $delimiter The delimiter used (default is ",") |
|
535 | + * @var string $encap_char The encap_char used (default is "|") |
|
536 | + * @var array $custom_fields Any custom fields set in the request. |
|
537 | + */ |
|
538 | + |
|
539 | + public function __construct($response) |
|
540 | + { |
|
541 | + $encap_char = $this->_x_post_fields['encap_char']; |
|
542 | + $delimiter = $this->_x_post_fields['delim_char']; |
|
543 | + if ($response) { |
|
544 | + // Split Array |
|
545 | + $this->response = $response; |
|
546 | + if ($encap_char) { |
|
547 | + $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
548 | + } else { |
|
549 | + $this->_response_array = explode($delimiter, $response); |
|
550 | + } |
|
551 | + |
|
552 | + /** |
|
553 | + * If AuthorizeNet doesn't return a delimited response. |
|
554 | + */ |
|
555 | + if (count($this->_response_array) < 10) { |
|
556 | + $this->approved = false; |
|
557 | + $this->error = true; |
|
558 | + $this->error_message = sprintf( |
|
559 | + esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'), |
|
560 | + esc_html($response) |
|
561 | + ); |
|
562 | + return; |
|
563 | + } |
|
564 | + |
|
565 | + |
|
566 | + |
|
567 | + // Set all fields |
|
568 | + $this->response_code = $this->_response_array[0]; |
|
569 | + $this->response_subcode = $this->_response_array[1]; |
|
570 | + $this->response_reason_code = $this->_response_array[2]; |
|
571 | + $this->response_reason_text = $this->_response_array[3]; |
|
572 | + $this->authorization_code = $this->_response_array[4]; |
|
573 | + $this->avs_response = $this->_response_array[5]; |
|
574 | + $this->transaction_id = $this->_response_array[6]; |
|
575 | + $this->invoice_number = $this->_response_array[7]; |
|
576 | + $this->description = $this->_response_array[8]; |
|
577 | + $this->amount = $this->_response_array[9]; |
|
578 | + $this->method = $this->_response_array[10]; |
|
579 | + $this->transaction_type = $this->_response_array[11]; |
|
580 | + $this->customer_id = $this->_response_array[12]; |
|
581 | + $this->first_name = $this->_response_array[13]; |
|
582 | + $this->last_name = $this->_response_array[14]; |
|
583 | + $this->company = $this->_response_array[15]; |
|
584 | + $this->address = $this->_response_array[16]; |
|
585 | + $this->city = $this->_response_array[17]; |
|
586 | + $this->state = $this->_response_array[18]; |
|
587 | + $this->zip_code = $this->_response_array[19]; |
|
588 | + $this->country = $this->_response_array[20]; |
|
589 | + $this->phone = $this->_response_array[21]; |
|
590 | + $this->fax = $this->_response_array[22]; |
|
591 | + $this->email_address = $this->_response_array[23]; |
|
592 | + $this->ship_to_first_name = $this->_response_array[24]; |
|
593 | + $this->ship_to_last_name = $this->_response_array[25]; |
|
594 | + $this->ship_to_company = $this->_response_array[26]; |
|
595 | + $this->ship_to_address = $this->_response_array[27]; |
|
596 | + $this->ship_to_city = $this->_response_array[28]; |
|
597 | + $this->ship_to_state = $this->_response_array[29]; |
|
598 | + $this->ship_to_zip_code = $this->_response_array[30]; |
|
599 | + $this->ship_to_country = $this->_response_array[31]; |
|
600 | + $this->tax = $this->_response_array[32]; |
|
601 | + $this->duty = $this->_response_array[33]; |
|
602 | + $this->freight = $this->_response_array[34]; |
|
603 | + $this->tax_exempt = $this->_response_array[35]; |
|
604 | + $this->purchase_order_number = $this->_response_array[36]; |
|
605 | + $this->md5_hash = $this->_response_array[37]; |
|
606 | + $this->card_code_response = $this->_response_array[38]; |
|
607 | + $this->cavv_response = $this->_response_array[39]; |
|
608 | + $this->account_number = $this->_response_array[50]; |
|
609 | + $this->card_type = $this->_response_array[51]; |
|
610 | + $this->split_tender_id = $this->_response_array[52]; |
|
611 | + $this->requested_amount = $this->_response_array[53]; |
|
612 | + $this->balance_on_card = $this->_response_array[54]; |
|
613 | + |
|
614 | + $this->approved = ($this->response_code === self::APPROVED); |
|
615 | + $this->declined = ($this->response_code === self::DECLINED); |
|
616 | + $this->error = ($this->response_code === self::ERROR); |
|
617 | + $this->held = ($this->response_code === self::HELD); |
|
618 | + } else { |
|
619 | + $this->approved = false; |
|
620 | + $this->error = true; |
|
621 | + $this->error_message = esc_html__( |
|
622 | + 'Error connecting to Authorize.net', |
|
623 | + 'event_espresso' |
|
624 | + ); |
|
625 | + } |
|
626 | + } |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | if (! class_exists('AuthorizeNetException')) { |
630 | - /** |
|
631 | - * Class AuthorizeNetException |
|
632 | - * |
|
633 | - * @package AuthorizeNet |
|
634 | - */ |
|
635 | - class AuthorizeNetException extends Exception |
|
636 | - { |
|
637 | - |
|
638 | - /** |
|
639 | - * Construct the exception. Note: The message is NOT binary safe. |
|
640 | - * |
|
641 | - * @link http://php.net/manual/en/exception.construct.php |
|
642 | - * @param string $message [optional] The Exception message to throw. |
|
643 | - * @param int $code [optional] The Exception code. |
|
644 | - * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
|
645 | - * @since 5.1.0 |
|
646 | - */ |
|
647 | - public function __construct($message = "", $code = 0, Exception $previous = null) |
|
648 | - { |
|
649 | - parent::__construct($message, $code, $previous); |
|
650 | - } |
|
651 | - } |
|
630 | + /** |
|
631 | + * Class AuthorizeNetException |
|
632 | + * |
|
633 | + * @package AuthorizeNet |
|
634 | + */ |
|
635 | + class AuthorizeNetException extends Exception |
|
636 | + { |
|
637 | + |
|
638 | + /** |
|
639 | + * Construct the exception. Note: The message is NOT binary safe. |
|
640 | + * |
|
641 | + * @link http://php.net/manual/en/exception.construct.php |
|
642 | + * @param string $message [optional] The Exception message to throw. |
|
643 | + * @param int $code [optional] The Exception code. |
|
644 | + * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
|
645 | + * @since 5.1.0 |
|
646 | + */ |
|
647 | + public function __construct($message = "", $code = 0, Exception $previous = null) |
|
648 | + { |
|
649 | + parent::__construct($message, $code, $previous); |
|
650 | + } |
|
651 | + } |
|
652 | 652 | } |
@@ -17,158 +17,158 @@ |
||
17 | 17 | class CachingLoader extends CachingLoaderDecorator |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string $identifier |
|
22 | - */ |
|
23 | - protected $identifier; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var CollectionInterface $cache |
|
27 | - */ |
|
28 | - protected $cache; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var ObjectIdentifier |
|
32 | - */ |
|
33 | - private $object_identifier; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * CachingLoader constructor. |
|
38 | - * |
|
39 | - * @param LoaderDecoratorInterface $loader |
|
40 | - * @param CollectionInterface $cache |
|
41 | - * @param ObjectIdentifier $object_identifier |
|
42 | - * @param string $identifier |
|
43 | - * @throws InvalidDataTypeException |
|
44 | - */ |
|
45 | - public function __construct( |
|
46 | - LoaderDecoratorInterface $loader, |
|
47 | - CollectionInterface $cache, |
|
48 | - ObjectIdentifier $object_identifier, |
|
49 | - $identifier = '' |
|
50 | - ) { |
|
51 | - parent::__construct($loader); |
|
52 | - $this->cache = $cache; |
|
53 | - $this->object_identifier = $object_identifier; |
|
54 | - $this->setIdentifier($identifier); |
|
55 | - if ($this->identifier !== '') { |
|
56 | - // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
57 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
58 | - // where "IDENTIFIER" = the string that was set during construction |
|
59 | - add_action( |
|
60 | - "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
61 | - array($this, 'reset') |
|
62 | - ); |
|
63 | - } |
|
64 | - // to clear ALL caches, simply do the following: |
|
65 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
66 | - add_action( |
|
67 | - 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
68 | - array($this, 'reset') |
|
69 | - ); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function identifier() |
|
77 | - { |
|
78 | - return $this->identifier; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @param string $identifier |
|
84 | - * @throws InvalidDataTypeException |
|
85 | - */ |
|
86 | - private function setIdentifier($identifier) |
|
87 | - { |
|
88 | - if (! is_string($identifier)) { |
|
89 | - throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
90 | - } |
|
91 | - $this->identifier = $identifier; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @param FullyQualifiedName|string $fqcn |
|
97 | - * @param mixed $object |
|
98 | - * @param array $arguments |
|
99 | - * @return bool |
|
100 | - * @throws InvalidArgumentException |
|
101 | - */ |
|
102 | - public function share($fqcn, $object, array $arguments = array()) |
|
103 | - { |
|
104 | - if ($object instanceof $fqcn) { |
|
105 | - return $this->cache->add( |
|
106 | - $object, |
|
107 | - $this->object_identifier->getIdentifier($fqcn, $arguments) |
|
108 | - ); |
|
109 | - } |
|
110 | - throw new InvalidArgumentException( |
|
111 | - sprintf( |
|
112 | - esc_html__( |
|
113 | - 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - $fqcn |
|
117 | - ) |
|
118 | - ); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @param FullyQualifiedName|string $fqcn |
|
124 | - * @param array $arguments |
|
125 | - * @param bool $shared |
|
126 | - * @param array $interfaces |
|
127 | - * @return mixed |
|
128 | - */ |
|
129 | - public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array()) |
|
130 | - { |
|
131 | - $fqcn = ltrim($fqcn, '\\'); |
|
132 | - // caching can be turned off via the following code: |
|
133 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
134 | - if (apply_filters( |
|
135 | - 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
136 | - false, |
|
137 | - $this |
|
138 | - )) { |
|
139 | - // even though $shared might be true, caching could be bypassed for whatever reason, |
|
140 | - // so we don't want the core loader to cache anything, therefore caching is turned off |
|
141 | - return $this->loader->load($fqcn, $arguments, false); |
|
142 | - } |
|
143 | - $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
144 | - if ($this->cache->has($object_identifier)) { |
|
145 | - return $this->cache->get($object_identifier); |
|
146 | - } |
|
147 | - $object = $this->loader->load($fqcn, $arguments, $shared); |
|
148 | - if ($object instanceof $fqcn) { |
|
149 | - $this->cache->add($object, $object_identifier); |
|
150 | - } |
|
151 | - return $object; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * empties cache and calls reset() on loader if method exists |
|
157 | - */ |
|
158 | - public function reset() |
|
159 | - { |
|
160 | - $this->clearCache(); |
|
161 | - $this->loader->reset(); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * unsets and detaches ALL objects from the cache |
|
167 | - * |
|
168 | - * @since 4.9.62.p |
|
169 | - */ |
|
170 | - public function clearCache() |
|
171 | - { |
|
172 | - $this->cache->trashAndDetachAll(); |
|
173 | - } |
|
20 | + /** |
|
21 | + * @var string $identifier |
|
22 | + */ |
|
23 | + protected $identifier; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var CollectionInterface $cache |
|
27 | + */ |
|
28 | + protected $cache; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var ObjectIdentifier |
|
32 | + */ |
|
33 | + private $object_identifier; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * CachingLoader constructor. |
|
38 | + * |
|
39 | + * @param LoaderDecoratorInterface $loader |
|
40 | + * @param CollectionInterface $cache |
|
41 | + * @param ObjectIdentifier $object_identifier |
|
42 | + * @param string $identifier |
|
43 | + * @throws InvalidDataTypeException |
|
44 | + */ |
|
45 | + public function __construct( |
|
46 | + LoaderDecoratorInterface $loader, |
|
47 | + CollectionInterface $cache, |
|
48 | + ObjectIdentifier $object_identifier, |
|
49 | + $identifier = '' |
|
50 | + ) { |
|
51 | + parent::__construct($loader); |
|
52 | + $this->cache = $cache; |
|
53 | + $this->object_identifier = $object_identifier; |
|
54 | + $this->setIdentifier($identifier); |
|
55 | + if ($this->identifier !== '') { |
|
56 | + // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
57 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
58 | + // where "IDENTIFIER" = the string that was set during construction |
|
59 | + add_action( |
|
60 | + "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
61 | + array($this, 'reset') |
|
62 | + ); |
|
63 | + } |
|
64 | + // to clear ALL caches, simply do the following: |
|
65 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
66 | + add_action( |
|
67 | + 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
68 | + array($this, 'reset') |
|
69 | + ); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function identifier() |
|
77 | + { |
|
78 | + return $this->identifier; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @param string $identifier |
|
84 | + * @throws InvalidDataTypeException |
|
85 | + */ |
|
86 | + private function setIdentifier($identifier) |
|
87 | + { |
|
88 | + if (! is_string($identifier)) { |
|
89 | + throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
90 | + } |
|
91 | + $this->identifier = $identifier; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @param FullyQualifiedName|string $fqcn |
|
97 | + * @param mixed $object |
|
98 | + * @param array $arguments |
|
99 | + * @return bool |
|
100 | + * @throws InvalidArgumentException |
|
101 | + */ |
|
102 | + public function share($fqcn, $object, array $arguments = array()) |
|
103 | + { |
|
104 | + if ($object instanceof $fqcn) { |
|
105 | + return $this->cache->add( |
|
106 | + $object, |
|
107 | + $this->object_identifier->getIdentifier($fqcn, $arguments) |
|
108 | + ); |
|
109 | + } |
|
110 | + throw new InvalidArgumentException( |
|
111 | + sprintf( |
|
112 | + esc_html__( |
|
113 | + 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + $fqcn |
|
117 | + ) |
|
118 | + ); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @param FullyQualifiedName|string $fqcn |
|
124 | + * @param array $arguments |
|
125 | + * @param bool $shared |
|
126 | + * @param array $interfaces |
|
127 | + * @return mixed |
|
128 | + */ |
|
129 | + public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array()) |
|
130 | + { |
|
131 | + $fqcn = ltrim($fqcn, '\\'); |
|
132 | + // caching can be turned off via the following code: |
|
133 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
134 | + if (apply_filters( |
|
135 | + 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
136 | + false, |
|
137 | + $this |
|
138 | + )) { |
|
139 | + // even though $shared might be true, caching could be bypassed for whatever reason, |
|
140 | + // so we don't want the core loader to cache anything, therefore caching is turned off |
|
141 | + return $this->loader->load($fqcn, $arguments, false); |
|
142 | + } |
|
143 | + $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
144 | + if ($this->cache->has($object_identifier)) { |
|
145 | + return $this->cache->get($object_identifier); |
|
146 | + } |
|
147 | + $object = $this->loader->load($fqcn, $arguments, $shared); |
|
148 | + if ($object instanceof $fqcn) { |
|
149 | + $this->cache->add($object, $object_identifier); |
|
150 | + } |
|
151 | + return $object; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * empties cache and calls reset() on loader if method exists |
|
157 | + */ |
|
158 | + public function reset() |
|
159 | + { |
|
160 | + $this->clearCache(); |
|
161 | + $this->loader->reset(); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * unsets and detaches ALL objects from the cache |
|
167 | + * |
|
168 | + * @since 4.9.62.p |
|
169 | + */ |
|
170 | + public function clearCache() |
|
171 | + { |
|
172 | + $this->cache->trashAndDetachAll(); |
|
173 | + } |
|
174 | 174 | } |
@@ -6,22 +6,22 @@ discard block |
||
6 | 6 | */ |
7 | 7 | function espresso_load_error_handling() |
8 | 8 | { |
9 | - static $error_handling_loaded = false; |
|
10 | - if ($error_handling_loaded) { |
|
11 | - return; |
|
12 | - } |
|
13 | - // load debugging tools |
|
14 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
16 | - \EEH_Debug_Tools::instance(); |
|
17 | - } |
|
18 | - // load error handling |
|
19 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
21 | - } else { |
|
22 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
23 | - } |
|
24 | - $error_handling_loaded = true; |
|
9 | + static $error_handling_loaded = false; |
|
10 | + if ($error_handling_loaded) { |
|
11 | + return; |
|
12 | + } |
|
13 | + // load debugging tools |
|
14 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
16 | + \EEH_Debug_Tools::instance(); |
|
17 | + } |
|
18 | + // load error handling |
|
19 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
21 | + } else { |
|
22 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
23 | + } |
|
24 | + $error_handling_loaded = true; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | |
@@ -35,19 +35,19 @@ discard block |
||
35 | 35 | */ |
36 | 36 | function espresso_load_required($classname, $full_path_to_file) |
37 | 37 | { |
38 | - if (is_readable($full_path_to_file)) { |
|
39 | - require_once $full_path_to_file; |
|
40 | - } else { |
|
41 | - throw new \EE_Error( |
|
42 | - sprintf( |
|
43 | - esc_html__( |
|
44 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
45 | - 'event_espresso' |
|
46 | - ), |
|
47 | - $classname |
|
48 | - ) |
|
49 | - ); |
|
50 | - } |
|
38 | + if (is_readable($full_path_to_file)) { |
|
39 | + require_once $full_path_to_file; |
|
40 | + } else { |
|
41 | + throw new \EE_Error( |
|
42 | + sprintf( |
|
43 | + esc_html__( |
|
44 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
45 | + 'event_espresso' |
|
46 | + ), |
|
47 | + $classname |
|
48 | + ) |
|
49 | + ); |
|
50 | + } |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | |
@@ -66,43 +66,43 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function bootstrap_espresso() |
68 | 68 | { |
69 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
70 | - try { |
|
71 | - espresso_load_error_handling(); |
|
72 | - espresso_load_required( |
|
73 | - 'EEH_Base', |
|
74 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
75 | - ); |
|
76 | - espresso_load_required( |
|
77 | - 'EEH_File', |
|
78 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
79 | - ); |
|
80 | - espresso_load_required( |
|
81 | - 'EEH_File', |
|
82 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
83 | - ); |
|
84 | - espresso_load_required( |
|
85 | - 'EEH_Array', |
|
86 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
87 | - ); |
|
88 | - espresso_load_required( |
|
89 | - 'EE_Base', |
|
90 | - EE_CORE . 'EE_Base.core.php' |
|
91 | - ); |
|
92 | - // instantiate and configure PSR4 autoloader |
|
93 | - espresso_load_required( |
|
94 | - 'Psr4Autoloader', |
|
95 | - EE_CORE . 'Psr4Autoloader.php' |
|
96 | - ); |
|
97 | - espresso_load_required( |
|
98 | - 'EE_Psr4AutoloaderInit', |
|
99 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
100 | - ); |
|
101 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
102 | - $AutoloaderInit->initializeAutoloader(); |
|
103 | - new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
104 | - } catch (Exception $e) { |
|
105 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
106 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
107 | - } |
|
69 | + require_once __DIR__ . '/espresso_definitions.php'; |
|
70 | + try { |
|
71 | + espresso_load_error_handling(); |
|
72 | + espresso_load_required( |
|
73 | + 'EEH_Base', |
|
74 | + EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
75 | + ); |
|
76 | + espresso_load_required( |
|
77 | + 'EEH_File', |
|
78 | + EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
79 | + ); |
|
80 | + espresso_load_required( |
|
81 | + 'EEH_File', |
|
82 | + EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
83 | + ); |
|
84 | + espresso_load_required( |
|
85 | + 'EEH_Array', |
|
86 | + EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
87 | + ); |
|
88 | + espresso_load_required( |
|
89 | + 'EE_Base', |
|
90 | + EE_CORE . 'EE_Base.core.php' |
|
91 | + ); |
|
92 | + // instantiate and configure PSR4 autoloader |
|
93 | + espresso_load_required( |
|
94 | + 'Psr4Autoloader', |
|
95 | + EE_CORE . 'Psr4Autoloader.php' |
|
96 | + ); |
|
97 | + espresso_load_required( |
|
98 | + 'EE_Psr4AutoloaderInit', |
|
99 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
100 | + ); |
|
101 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
102 | + $AutoloaderInit->initializeAutoloader(); |
|
103 | + new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
104 | + } catch (Exception $e) { |
|
105 | + require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
106 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
107 | + } |
|
108 | 108 | } |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | return; |
12 | 12 | } |
13 | 13 | // load debugging tools |
14 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
14 | + if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) { |
|
15 | + require_once EE_HELPERS.'EEH_Debug_Tools.helper.php'; |
|
16 | 16 | \EEH_Debug_Tools::instance(); |
17 | 17 | } |
18 | 18 | // load error handling |
19 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
19 | + if (is_readable(EE_CORE.'EE_Error.core.php')) { |
|
20 | + require_once EE_CORE.'EE_Error.core.php'; |
|
21 | 21 | } else { |
22 | 22 | wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
23 | 23 | } |
@@ -66,43 +66,43 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function bootstrap_espresso() |
68 | 68 | { |
69 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
69 | + require_once __DIR__.'/espresso_definitions.php'; |
|
70 | 70 | try { |
71 | 71 | espresso_load_error_handling(); |
72 | 72 | espresso_load_required( |
73 | 73 | 'EEH_Base', |
74 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
74 | + EE_CORE.'helpers'.DS.'EEH_Base.helper.php' |
|
75 | 75 | ); |
76 | 76 | espresso_load_required( |
77 | 77 | 'EEH_File', |
78 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
78 | + EE_CORE.'interfaces'.DS.'EEHI_File.interface.php' |
|
79 | 79 | ); |
80 | 80 | espresso_load_required( |
81 | 81 | 'EEH_File', |
82 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
82 | + EE_CORE.'helpers'.DS.'EEH_File.helper.php' |
|
83 | 83 | ); |
84 | 84 | espresso_load_required( |
85 | 85 | 'EEH_Array', |
86 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
86 | + EE_CORE.'helpers'.DS.'EEH_Array.helper.php' |
|
87 | 87 | ); |
88 | 88 | espresso_load_required( |
89 | 89 | 'EE_Base', |
90 | - EE_CORE . 'EE_Base.core.php' |
|
90 | + EE_CORE.'EE_Base.core.php' |
|
91 | 91 | ); |
92 | 92 | // instantiate and configure PSR4 autoloader |
93 | 93 | espresso_load_required( |
94 | 94 | 'Psr4Autoloader', |
95 | - EE_CORE . 'Psr4Autoloader.php' |
|
95 | + EE_CORE.'Psr4Autoloader.php' |
|
96 | 96 | ); |
97 | 97 | espresso_load_required( |
98 | 98 | 'EE_Psr4AutoloaderInit', |
99 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
99 | + EE_CORE.'EE_Psr4AutoloaderInit.core.php' |
|
100 | 100 | ); |
101 | 101 | $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
102 | 102 | $AutoloaderInit->initializeAutoloader(); |
103 | 103 | new EventEspresso\core\services\bootstrap\BootstrapCore(); |
104 | 104 | } catch (Exception $e) { |
105 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
105 | + require_once EE_CORE.'exceptions'.DS.'ExceptionStackTraceDisplay.php'; |
|
106 | 106 | new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
107 | 107 | } |
108 | 108 | } |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | $stages = glob(EE_CORE . 'data_migration_scripts/4_5_0_stages/*'); |
17 | 17 | $class_to_filepath = array(); |
18 | 18 | foreach ($stages as $filepath) { |
19 | - $matches = array(); |
|
20 | - preg_match('~4_5_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
21 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
19 | + $matches = array(); |
|
20 | + preg_match('~4_5_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
21 | + $class_to_filepath[ $matches[1] ] = $filepath; |
|
22 | 22 | } |
23 | 23 | // give addons a chance to autoload their stages too |
24 | 24 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_5_0__autoloaded_stages', $class_to_filepath); |
@@ -31,59 +31,59 @@ discard block |
||
31 | 31 | |
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * EE_DMS_Core_4_5_0 constructor. |
|
36 | - * |
|
37 | - * @param TableManager $table_manager |
|
38 | - * @param TableAnalysis $table_analysis |
|
39 | - */ |
|
40 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
41 | - { |
|
42 | - $this->_pretty_name = __("Data Update to Event Espresso 4.5.0", "event_espresso"); |
|
43 | - $this->_priority = 10; |
|
44 | - $this->_migration_stages = array( |
|
45 | - new EE_DMS_4_5_0_update_wp_user_for_tickets(), |
|
46 | - new EE_DMS_4_5_0_update_wp_user_for_prices(), |
|
47 | - new EE_DMS_4_5_0_update_wp_user_for_price_types(), |
|
48 | - new EE_DMS_4_5_0_update_wp_user_for_question_groups(), |
|
49 | - new EE_DMS_4_5_0_invoice_settings(), |
|
50 | - ); |
|
51 | - parent::__construct($table_manager, $table_analysis); |
|
52 | - } |
|
34 | + /** |
|
35 | + * EE_DMS_Core_4_5_0 constructor. |
|
36 | + * |
|
37 | + * @param TableManager $table_manager |
|
38 | + * @param TableAnalysis $table_analysis |
|
39 | + */ |
|
40 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
41 | + { |
|
42 | + $this->_pretty_name = __("Data Update to Event Espresso 4.5.0", "event_espresso"); |
|
43 | + $this->_priority = 10; |
|
44 | + $this->_migration_stages = array( |
|
45 | + new EE_DMS_4_5_0_update_wp_user_for_tickets(), |
|
46 | + new EE_DMS_4_5_0_update_wp_user_for_prices(), |
|
47 | + new EE_DMS_4_5_0_update_wp_user_for_price_types(), |
|
48 | + new EE_DMS_4_5_0_update_wp_user_for_question_groups(), |
|
49 | + new EE_DMS_4_5_0_invoice_settings(), |
|
50 | + ); |
|
51 | + parent::__construct($table_manager, $table_analysis); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | - public function can_migrate_from_version($version_array) |
|
57 | - { |
|
58 | - $version_string = $version_array['Core']; |
|
59 | - if (version_compare($version_string, '4.5.0', '<=') && version_compare($version_string, '4.3.0', '>=')) { |
|
56 | + public function can_migrate_from_version($version_array) |
|
57 | + { |
|
58 | + $version_string = $version_array['Core']; |
|
59 | + if (version_compare($version_string, '4.5.0', '<=') && version_compare($version_string, '4.3.0', '>=')) { |
|
60 | 60 | // echo "$version_string can be migrated from"; |
61 | - return true; |
|
62 | - } elseif (! $version_string) { |
|
61 | + return true; |
|
62 | + } elseif (! $version_string) { |
|
63 | 63 | // echo "no version string provided: $version_string"; |
64 | - // no version string provided... this must be pre 4.3 |
|
65 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
66 | - } else { |
|
64 | + // no version string provided... this must be pre 4.3 |
|
65 | + return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
66 | + } else { |
|
67 | 67 | // echo "$version_string doesnt apply"; |
68 | - return false; |
|
69 | - } |
|
70 | - } |
|
68 | + return false; |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | 73 | |
74 | - public function schema_changes_before_migration() |
|
75 | - { |
|
76 | - // relies on 4.1's EEH_Activation::create_table |
|
77 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
78 | - $table_name = 'esp_answer'; |
|
79 | - $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
74 | + public function schema_changes_before_migration() |
|
75 | + { |
|
76 | + // relies on 4.1's EEH_Activation::create_table |
|
77 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
78 | + $table_name = 'esp_answer'; |
|
79 | + $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
80 | 80 | REG_ID INT UNSIGNED NOT NULL, |
81 | 81 | QST_ID INT UNSIGNED NOT NULL, |
82 | 82 | ANS_value TEXT NOT NULL, |
83 | 83 | PRIMARY KEY (ANS_ID)"; |
84 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
85 | - $table_name = 'esp_attendee_meta'; |
|
86 | - $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
84 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
85 | + $table_name = 'esp_attendee_meta'; |
|
86 | + $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
87 | 87 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
88 | 88 | ATT_fname VARCHAR(45) NOT NULL, |
89 | 89 | ATT_lname VARCHAR(45) NOT NULL, |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | KEY ATT_fname (ATT_fname), |
100 | 100 | KEY ATT_lname (ATT_lname), |
101 | 101 | KEY ATT_email (ATT_email(191))"; |
102 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
103 | - $table_name = 'esp_country'; |
|
104 | - $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
102 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
103 | + $table_name = 'esp_country'; |
|
104 | + $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
105 | 105 | CNT_ISO3 VARCHAR(3) COLLATE utf8_bin NOT NULL, |
106 | 106 | RGN_ID TINYINT(3) UNSIGNED DEFAULT NULL, |
107 | 107 | CNT_name VARCHAR(45) COLLATE utf8_bin NOT NULL, |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | CNT_is_EU TINYINT(1) DEFAULT '0', |
118 | 118 | CNT_active TINYINT(1) DEFAULT '0', |
119 | 119 | PRIMARY KEY (CNT_ISO)"; |
120 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
121 | - $table_name = 'esp_datetime'; |
|
122 | - $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
120 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
121 | + $table_name = 'esp_datetime'; |
|
122 | + $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
123 | 123 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
124 | 124 | DTT_name VARCHAR(255) NOT NULL DEFAULT '', |
125 | 125 | DTT_description TEXT NOT NULL, |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | PRIMARY KEY (DTT_ID), |
135 | 135 | KEY EVT_ID (EVT_ID), |
136 | 136 | KEY DTT_is_primary (DTT_is_primary)"; |
137 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
138 | - $table_name = 'esp_event_meta'; |
|
139 | - $sql = " |
|
137 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
138 | + $table_name = 'esp_event_meta'; |
|
139 | + $sql = " |
|
140 | 140 | EVTM_ID INT NOT NULL AUTO_INCREMENT, |
141 | 141 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
142 | 142 | EVT_display_desc TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
@@ -151,31 +151,31 @@ discard block |
||
151 | 151 | EVT_external_URL VARCHAR(200) NULL, |
152 | 152 | EVT_donations TINYINT(1) NULL, |
153 | 153 | PRIMARY KEY (EVTM_ID)"; |
154 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
155 | - $table_name = 'esp_event_question_group'; |
|
156 | - $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
154 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
155 | + $table_name = 'esp_event_question_group'; |
|
156 | + $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
157 | 157 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
158 | 158 | QSG_ID INT UNSIGNED NOT NULL, |
159 | 159 | EQG_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
160 | 160 | PRIMARY KEY (EQG_ID)"; |
161 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
162 | - $table_name = 'esp_event_venue'; |
|
163 | - $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
161 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
162 | + $table_name = 'esp_event_venue'; |
|
163 | + $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
164 | 164 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
165 | 165 | VNU_ID BIGINT(20) UNSIGNED NOT NULL, |
166 | 166 | EVV_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
167 | 167 | PRIMARY KEY (EVV_ID)"; |
168 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
169 | - $table_name = 'esp_extra_meta'; |
|
170 | - $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
168 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
169 | + $table_name = 'esp_extra_meta'; |
|
170 | + $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
171 | 171 | OBJ_ID INT(11) DEFAULT NULL, |
172 | 172 | EXM_type VARCHAR(45) DEFAULT NULL, |
173 | 173 | EXM_key VARCHAR(45) DEFAULT NULL, |
174 | 174 | EXM_value TEXT, |
175 | 175 | PRIMARY KEY (EXM_ID)"; |
176 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
177 | - $table_name = 'esp_line_item'; |
|
178 | - $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
176 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
177 | + $table_name = 'esp_line_item'; |
|
178 | + $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
179 | 179 | LIN_code VARCHAR(245) NOT NULL DEFAULT '', |
180 | 180 | TXN_ID INT(11) DEFAULT NULL, |
181 | 181 | LIN_name VARCHAR(245) NOT NULL DEFAULT '', |
@@ -191,19 +191,19 @@ discard block |
||
191 | 191 | OBJ_ID INT(11) DEFAULT NULL, |
192 | 192 | OBJ_type VARCHAR(45)DEFAULT NULL, |
193 | 193 | PRIMARY KEY (LIN_ID)"; |
194 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
195 | - $table_name = 'esp_message_template'; |
|
196 | - $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
194 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
195 | + $table_name = 'esp_message_template'; |
|
196 | + $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
197 | 197 | GRP_ID INT(10) UNSIGNED NOT NULL, |
198 | 198 | MTP_context VARCHAR(50) NOT NULL, |
199 | 199 | MTP_template_field VARCHAR(30) NOT NULL, |
200 | 200 | MTP_content TEXT NOT NULL, |
201 | 201 | PRIMARY KEY (MTP_ID), |
202 | 202 | KEY GRP_ID (GRP_ID)"; |
203 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
204 | - $this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID'); |
|
205 | - $table_name = 'esp_message_template_group'; |
|
206 | - $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
203 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
204 | + $this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID'); |
|
205 | + $table_name = 'esp_message_template_group'; |
|
206 | + $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
207 | 207 | MTP_user_id INT(10) NOT NULL DEFAULT '1', |
208 | 208 | MTP_name VARCHAR(245) NOT NULL DEFAULT '', |
209 | 209 | MTP_description VARCHAR(245) NOT NULL DEFAULT '', |
@@ -215,17 +215,17 @@ discard block |
||
215 | 215 | MTP_is_active TINYINT(1) NOT NULL DEFAULT '1', |
216 | 216 | PRIMARY KEY (GRP_ID), |
217 | 217 | KEY MTP_user_id (MTP_user_id)"; |
218 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
219 | - $table_name = 'esp_event_message_template'; |
|
220 | - $sql = "EMT_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
218 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
219 | + $table_name = 'esp_event_message_template'; |
|
220 | + $sql = "EMT_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
221 | 221 | EVT_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, |
222 | 222 | GRP_ID INT(10) UNSIGNED NOT NULL DEFAULT 0, |
223 | 223 | PRIMARY KEY (EMT_ID), |
224 | 224 | KEY EVT_ID (EVT_ID), |
225 | 225 | KEY GRP_ID (GRP_ID)"; |
226 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
227 | - $table_name = 'esp_payment'; |
|
228 | - $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
226 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
227 | + $table_name = 'esp_payment'; |
|
228 | + $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
229 | 229 | TXN_ID INT(10) UNSIGNED DEFAULT NULL, |
230 | 230 | STS_ID VARCHAR(3) COLLATE utf8_bin DEFAULT NULL, |
231 | 231 | PAY_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -241,28 +241,28 @@ discard block |
||
241 | 241 | PRIMARY KEY (PAY_ID), |
242 | 242 | KEY TXN_ID (TXN_ID), |
243 | 243 | KEY PAY_timestamp (PAY_timestamp)"; |
244 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
245 | - $table_name = "esp_ticket_price"; |
|
246 | - $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
244 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
245 | + $table_name = "esp_ticket_price"; |
|
246 | + $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
247 | 247 | TKT_ID INT(10) UNSIGNED NOT NULL, |
248 | 248 | PRC_ID INT(10) UNSIGNED NOT NULL, |
249 | 249 | PRIMARY KEY (TKP_ID)"; |
250 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
251 | - $table_name = "esp_datetime_ticket"; |
|
252 | - $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
250 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
251 | + $table_name = "esp_datetime_ticket"; |
|
252 | + $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
253 | 253 | DTT_ID INT(10) UNSIGNED NOT NULL, |
254 | 254 | TKT_ID INT(10) UNSIGNED NOT NULL, |
255 | 255 | PRIMARY KEY (DTK_ID)"; |
256 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
257 | - $table_name = "esp_ticket_template"; |
|
258 | - $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
256 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
257 | + $table_name = "esp_ticket_template"; |
|
258 | + $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
259 | 259 | TTM_name VARCHAR(45) NOT NULL, |
260 | 260 | TTM_description TEXT, |
261 | 261 | TTM_file VARCHAR(45), |
262 | 262 | PRIMARY KEY (TTM_ID)"; |
263 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
264 | - $table_name = 'esp_question'; |
|
265 | - $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
263 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
264 | + $table_name = 'esp_question'; |
|
265 | + $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
266 | 266 | QST_display_text TEXT NOT NULL, |
267 | 267 | QST_admin_label VARCHAR(255) NOT NULL, |
268 | 268 | QST_system VARCHAR(25) DEFAULT NULL, |
@@ -274,25 +274,25 @@ discard block |
||
274 | 274 | QST_wp_user BIGINT UNSIGNED NULL, |
275 | 275 | QST_deleted TINYINT UNSIGNED NOT NULL DEFAULT 0, |
276 | 276 | PRIMARY KEY (QST_ID)'; |
277 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
278 | - $table_name = 'esp_question_group_question'; |
|
279 | - $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
277 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
278 | + $table_name = 'esp_question_group_question'; |
|
279 | + $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
280 | 280 | QSG_ID INT UNSIGNED NOT NULL, |
281 | 281 | QST_ID INT UNSIGNED NOT NULL, |
282 | 282 | QGQ_order INT UNSIGNED NOT NULL DEFAULT 0, |
283 | 283 | PRIMARY KEY (QGQ_ID) "; |
284 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
285 | - $table_name = 'esp_question_option'; |
|
286 | - $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
284 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
285 | + $table_name = 'esp_question_option'; |
|
286 | + $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
287 | 287 | QSO_value VARCHAR(255) NOT NULL, |
288 | 288 | QSO_desc TEXT NOT NULL, |
289 | 289 | QST_ID INT UNSIGNED NOT NULL, |
290 | 290 | QSO_order INT UNSIGNED NOT NULL DEFAULT 0, |
291 | 291 | QSO_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
292 | 292 | PRIMARY KEY (QSO_ID)"; |
293 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
294 | - $table_name = 'esp_registration'; |
|
295 | - $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
293 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
294 | + $table_name = 'esp_registration'; |
|
295 | + $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
296 | 296 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
297 | 297 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
298 | 298 | TXN_ID INT(10) UNSIGNED NOT NULL, |
@@ -315,25 +315,25 @@ discard block |
||
315 | 315 | KEY STS_ID (STS_ID), |
316 | 316 | KEY REG_url_link (REG_url_link), |
317 | 317 | KEY REG_code (REG_code)"; |
318 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
319 | - $table_name = 'esp_checkin'; |
|
320 | - $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
318 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
319 | + $table_name = 'esp_checkin'; |
|
320 | + $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
321 | 321 | REG_ID INT(10) UNSIGNED NOT NULL, |
322 | 322 | DTT_ID INT(10) UNSIGNED NOT NULL, |
323 | 323 | CHK_in TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
324 | 324 | CHK_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
325 | 325 | PRIMARY KEY (CHK_ID)"; |
326 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
327 | - $table_name = 'esp_state'; |
|
328 | - $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
326 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
327 | + $table_name = 'esp_state'; |
|
328 | + $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
329 | 329 | CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
330 | 330 | STA_abbrev VARCHAR(6) COLLATE utf8_bin NOT NULL, |
331 | 331 | STA_name VARCHAR(100) COLLATE utf8_bin NOT NULL, |
332 | 332 | STA_active TINYINT(1) DEFAULT '1', |
333 | 333 | PRIMARY KEY (STA_ID)"; |
334 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
335 | - $table_name = 'esp_status'; |
|
336 | - $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
334 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
335 | + $table_name = 'esp_status'; |
|
336 | + $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
337 | 337 | STS_code VARCHAR(45) COLLATE utf8_bin NOT NULL, |
338 | 338 | STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL, |
339 | 339 | STS_can_edit TINYINT(1) NOT NULL DEFAULT 0, |
@@ -341,9 +341,9 @@ discard block |
||
341 | 341 | STS_open TINYINT(1) NOT NULL DEFAULT 1, |
342 | 342 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
343 | 343 | KEY STS_type (STS_type)"; |
344 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
345 | - $table_name = 'esp_transaction'; |
|
346 | - $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
344 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
345 | + $table_name = 'esp_transaction'; |
|
346 | + $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
347 | 347 | TXN_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
348 | 348 | TXN_total DECIMAL(10,3) DEFAULT '0.00', |
349 | 349 | TXN_paid DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
@@ -354,9 +354,9 @@ discard block |
||
354 | 354 | PRIMARY KEY (TXN_ID), |
355 | 355 | KEY TXN_timestamp (TXN_timestamp), |
356 | 356 | KEY STS_ID (STS_ID)"; |
357 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
358 | - $table_name = 'esp_venue_meta'; |
|
359 | - $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
357 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
358 | + $table_name = 'esp_venue_meta'; |
|
359 | + $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
360 | 360 | VNU_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, |
361 | 361 | VNU_address VARCHAR(255) DEFAULT NULL, |
362 | 362 | VNU_address2 VARCHAR(255) DEFAULT NULL, |
@@ -374,10 +374,10 @@ discard block |
||
374 | 374 | PRIMARY KEY (VNUM_ID), |
375 | 375 | KEY STA_ID (STA_ID), |
376 | 376 | KEY CNT_ISO (CNT_ISO)"; |
377 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
378 | - // modified tables |
|
379 | - $table_name = "esp_price"; |
|
380 | - $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
377 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
378 | + // modified tables |
|
379 | + $table_name = "esp_price"; |
|
380 | + $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
381 | 381 | PRT_ID TINYINT(3) UNSIGNED NOT NULL, |
382 | 382 | PRC_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
383 | 383 | PRC_name VARCHAR(245) NOT NULL, |
@@ -389,9 +389,9 @@ discard block |
||
389 | 389 | PRC_wp_user BIGINT UNSIGNED NULL, |
390 | 390 | PRC_parent INT(10) UNSIGNED DEFAULT 0, |
391 | 391 | PRIMARY KEY (PRC_ID)"; |
392 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
393 | - $table_name = "esp_price_type"; |
|
394 | - $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
392 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
393 | + $table_name = "esp_price_type"; |
|
394 | + $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
395 | 395 | PRT_name VARCHAR(45) NOT NULL, |
396 | 396 | PBT_ID TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', |
397 | 397 | PRT_is_percent TINYINT(1) NOT NULL DEFAULT '0', |
@@ -400,9 +400,9 @@ discard block |
||
400 | 400 | PRT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
401 | 401 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
402 | 402 | PRIMARY KEY (PRT_ID)"; |
403 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
404 | - $table_name = "esp_ticket"; |
|
405 | - $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
403 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
404 | + $table_name = "esp_ticket"; |
|
405 | + $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
406 | 406 | TTM_ID INT(10) UNSIGNED NOT NULL, |
407 | 407 | TKT_name VARCHAR(245) NOT NULL DEFAULT '', |
408 | 408 | TKT_description TEXT NOT NULL, |
@@ -423,10 +423,10 @@ discard block |
||
423 | 423 | TKT_parent INT(10) UNSIGNED DEFAULT '0', |
424 | 424 | TKT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
425 | 425 | PRIMARY KEY (TKT_ID)"; |
426 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
427 | - $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
428 | - $table_name = 'esp_question_group'; |
|
429 | - $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
426 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
427 | + $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
428 | + $table_name = 'esp_question_group'; |
|
429 | + $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
430 | 430 | QSG_name VARCHAR(255) NOT NULL, |
431 | 431 | QSG_identifier VARCHAR(100) NOT NULL, |
432 | 432 | QSG_desc TEXT NULL, |
@@ -438,133 +438,133 @@ discard block |
||
438 | 438 | QSG_wp_user BIGINT UNSIGNED NULL, |
439 | 439 | PRIMARY KEY (QSG_ID), |
440 | 440 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)'; |
441 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
442 | - $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
443 | - // (because many need to convert old string states to foreign keys into the states table) |
|
444 | - $script_4_1_defaults->insert_default_states(); |
|
445 | - $script_4_1_defaults->insert_default_countries(); |
|
446 | - // schema on price, price_types and tickets has changed so use the DEFAULT method in here instead of 4.1's and later. |
|
447 | - $this->insert_default_price_types(); |
|
448 | - $this->insert_default_prices(); |
|
449 | - $this->insert_default_tickets(); |
|
450 | - // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
451 | - EE_Config::instance()->update_espresso_config(false, true); |
|
452 | - return true; |
|
453 | - } |
|
441 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
442 | + $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
443 | + // (because many need to convert old string states to foreign keys into the states table) |
|
444 | + $script_4_1_defaults->insert_default_states(); |
|
445 | + $script_4_1_defaults->insert_default_countries(); |
|
446 | + // schema on price, price_types and tickets has changed so use the DEFAULT method in here instead of 4.1's and later. |
|
447 | + $this->insert_default_price_types(); |
|
448 | + $this->insert_default_prices(); |
|
449 | + $this->insert_default_tickets(); |
|
450 | + // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
451 | + EE_Config::instance()->update_espresso_config(false, true); |
|
452 | + return true; |
|
453 | + } |
|
454 | 454 | |
455 | 455 | |
456 | 456 | |
457 | - /** |
|
458 | - * @return boolean |
|
459 | - */ |
|
460 | - public function schema_changes_after_migration() |
|
461 | - { |
|
462 | - return true; |
|
463 | - } |
|
457 | + /** |
|
458 | + * @return boolean |
|
459 | + */ |
|
460 | + public function schema_changes_after_migration() |
|
461 | + { |
|
462 | + return true; |
|
463 | + } |
|
464 | 464 | |
465 | 465 | |
466 | 466 | |
467 | - public function migration_page_hooks() |
|
468 | - { |
|
469 | - } |
|
467 | + public function migration_page_hooks() |
|
468 | + { |
|
469 | + } |
|
470 | 470 | |
471 | 471 | |
472 | 472 | |
473 | - /** |
|
474 | - * insert_default_price_types |
|
475 | - * |
|
476 | - * @since 4.5.0 |
|
477 | - * @return void |
|
478 | - */ |
|
479 | - public function insert_default_price_types() |
|
480 | - { |
|
481 | - global $wpdb; |
|
482 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
483 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
484 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
485 | - $price_types_exist = $wpdb->get_var($SQL); |
|
486 | - if (! $price_types_exist) { |
|
487 | - $user_id = EEH_Activation::get_default_creator_id(); |
|
488 | - $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_wp_user, PRT_deleted ) VALUES |
|
473 | + /** |
|
474 | + * insert_default_price_types |
|
475 | + * |
|
476 | + * @since 4.5.0 |
|
477 | + * @return void |
|
478 | + */ |
|
479 | + public function insert_default_price_types() |
|
480 | + { |
|
481 | + global $wpdb; |
|
482 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
483 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
484 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
485 | + $price_types_exist = $wpdb->get_var($SQL); |
|
486 | + if (! $price_types_exist) { |
|
487 | + $user_id = EEH_Activation::get_default_creator_id(); |
|
488 | + $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_wp_user, PRT_deleted ) VALUES |
|
489 | 489 | (1, '" . __('Base Price', 'event_espresso') . "', 1, 0, 0, $user_id, 0), |
490 | 490 | (2, '" . __('Percent Discount', 'event_espresso') . "', 2, 1, 20, $user_id, 0), |
491 | 491 | (3, '" . __('Dollar Discount', 'event_espresso') . "', 2, 0, 30, $user_id, 0), |
492 | 492 | (4, '" . __('Percent Surcharge', 'event_espresso') . "', 3, 1, 40, $user_id, 0), |
493 | 493 | (5, '" . __('Dollar Surcharge', 'event_espresso') . "', 3, 0, 50, $user_id, 0);"; |
494 | - $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_price_types__SQL', $SQL); |
|
495 | - $wpdb->query($SQL); |
|
496 | - } |
|
497 | - } |
|
498 | - } |
|
494 | + $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_price_types__SQL', $SQL); |
|
495 | + $wpdb->query($SQL); |
|
496 | + } |
|
497 | + } |
|
498 | + } |
|
499 | 499 | |
500 | 500 | |
501 | 501 | |
502 | - /** |
|
503 | - * insert DEFAULT prices. |
|
504 | - * If we're INSTALLING 4.x CAF, then we add a few extra DEFAULT prices |
|
505 | - * when EEH_Activaion's initialize_db_content is called via ahook in |
|
506 | - * EE_Brewing_regular |
|
507 | - * |
|
508 | - * @since 4.5.0 |
|
509 | - * @return void |
|
510 | - */ |
|
511 | - public function insert_default_prices() |
|
512 | - { |
|
513 | - global $wpdb; |
|
514 | - $price_table = $wpdb->prefix . "esp_price"; |
|
515 | - if ($this->_get_table_analysis()->tableExists($price_table)) { |
|
516 | - $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
517 | - $prices_exist = $wpdb->get_var($SQL); |
|
518 | - if (! $prices_exist) { |
|
519 | - $user_id = EEH_Activation::get_default_creator_id(); |
|
520 | - $SQL = "INSERT INTO $price_table |
|
502 | + /** |
|
503 | + * insert DEFAULT prices. |
|
504 | + * If we're INSTALLING 4.x CAF, then we add a few extra DEFAULT prices |
|
505 | + * when EEH_Activaion's initialize_db_content is called via ahook in |
|
506 | + * EE_Brewing_regular |
|
507 | + * |
|
508 | + * @since 4.5.0 |
|
509 | + * @return void |
|
510 | + */ |
|
511 | + public function insert_default_prices() |
|
512 | + { |
|
513 | + global $wpdb; |
|
514 | + $price_table = $wpdb->prefix . "esp_price"; |
|
515 | + if ($this->_get_table_analysis()->tableExists($price_table)) { |
|
516 | + $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
517 | + $prices_exist = $wpdb->get_var($SQL); |
|
518 | + if (! $prices_exist) { |
|
519 | + $user_id = EEH_Activation::get_default_creator_id(); |
|
520 | + $SQL = "INSERT INTO $price_table |
|
521 | 521 | (PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc, PRC_is_default, PRC_overrides, PRC_wp_user, PRC_order, PRC_deleted, PRC_parent ) VALUES |
522 | 522 | (1, 1, '0.00', 'Free Admission', '', 1, NULL, $user_id, 0, 0, 0);"; |
523 | - $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_prices__SQL', $SQL); |
|
524 | - $wpdb->query($SQL); |
|
525 | - } |
|
526 | - } |
|
527 | - } |
|
523 | + $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_prices__SQL', $SQL); |
|
524 | + $wpdb->query($SQL); |
|
525 | + } |
|
526 | + } |
|
527 | + } |
|
528 | 528 | |
529 | 529 | |
530 | 530 | |
531 | - /** |
|
532 | - * insert DEFAULT ticket |
|
533 | - * Almost identical to EE_DMS_Core_4_3_0::insert_default_tickets, except is aware of the TKT_wp_user field |
|
534 | - * |
|
535 | - * @since 4.5.0 |
|
536 | - * @return void |
|
537 | - */ |
|
538 | - public function insert_default_tickets() |
|
539 | - { |
|
540 | - global $wpdb; |
|
541 | - $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
542 | - if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
543 | - $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
544 | - $tickets_exist = $wpdb->get_var($SQL); |
|
545 | - if (! $tickets_exist) { |
|
546 | - $user_id = EEH_Activation::get_default_creator_id(); |
|
547 | - $SQL = "INSERT INTO $ticket_table |
|
531 | + /** |
|
532 | + * insert DEFAULT ticket |
|
533 | + * Almost identical to EE_DMS_Core_4_3_0::insert_default_tickets, except is aware of the TKT_wp_user field |
|
534 | + * |
|
535 | + * @since 4.5.0 |
|
536 | + * @return void |
|
537 | + */ |
|
538 | + public function insert_default_tickets() |
|
539 | + { |
|
540 | + global $wpdb; |
|
541 | + $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
542 | + if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
543 | + $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
544 | + $tickets_exist = $wpdb->get_var($SQL); |
|
545 | + if (! $tickets_exist) { |
|
546 | + $user_id = EEH_Activation::get_default_creator_id(); |
|
547 | + $SQL = "INSERT INTO $ticket_table |
|
548 | 548 | ( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_required, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_wp_user, TKT_deleted ) VALUES |
549 | 549 | ( 1, 0, '" |
550 | - . __("Free Ticket", "event_espresso") |
|
551 | - . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, $user_id, 0);"; |
|
552 | - $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL', $SQL); |
|
553 | - $wpdb->query($SQL); |
|
554 | - } |
|
555 | - } |
|
556 | - $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
557 | - if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
558 | - $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
559 | - $ticket_prc_exist = $wpdb->get_var($SQL); |
|
560 | - if (! $ticket_prc_exist) { |
|
561 | - $SQL = "INSERT INTO $ticket_price_table |
|
550 | + . __("Free Ticket", "event_espresso") |
|
551 | + . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, $user_id, 0);"; |
|
552 | + $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL', $SQL); |
|
553 | + $wpdb->query($SQL); |
|
554 | + } |
|
555 | + } |
|
556 | + $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
557 | + if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
558 | + $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
559 | + $ticket_prc_exist = $wpdb->get_var($SQL); |
|
560 | + if (! $ticket_prc_exist) { |
|
561 | + $SQL = "INSERT INTO $ticket_price_table |
|
562 | 562 | ( TKP_ID, TKT_ID, PRC_ID ) VALUES |
563 | 563 | ( 1, 1, 1 ) |
564 | 564 | "; |
565 | - $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
566 | - $wpdb->query($SQL); |
|
567 | - } |
|
568 | - } |
|
569 | - } |
|
565 | + $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
566 | + $wpdb->query($SQL); |
|
567 | + } |
|
568 | + } |
|
569 | + } |
|
570 | 570 | } |
@@ -14,11 +14,11 @@ discard block |
||
14 | 14 | $stages = glob(EE_CORE . 'data_migration_scripts/4_3_0_stages/*'); |
15 | 15 | $class_to_filepath = array(); |
16 | 16 | if (! empty($stages)) { |
17 | - foreach ($stages as $filepath) { |
|
18 | - $matches = array(); |
|
19 | - preg_match('~4_3_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
20 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
21 | - } |
|
17 | + foreach ($stages as $filepath) { |
|
18 | + $matches = array(); |
|
19 | + preg_match('~4_3_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
20 | + $class_to_filepath[ $matches[1] ] = $filepath; |
|
21 | + } |
|
22 | 22 | } |
23 | 23 | // give addons a chance to autoload their stages too |
24 | 24 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_3_0__autoloaded_stages', $class_to_filepath); |
@@ -31,56 +31,56 @@ discard block |
||
31 | 31 | |
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * EE_DMS_Core_4_3_0 constructor. |
|
36 | - * |
|
37 | - * @param TableManager $table_manager |
|
38 | - * @param TableAnalysis $table_analysis |
|
39 | - */ |
|
40 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
41 | - { |
|
42 | - $this->_pretty_name = __("Data Update to Event Espresso 4.3.0", "event_espresso"); |
|
43 | - $this->_priority = 10; |
|
44 | - $this->_migration_stages = array( |
|
45 | - new EE_DMS_4_3_0_question_option_order(), |
|
46 | - new EE_DMS_4_3_0_event_message_templates(), |
|
47 | - ); |
|
48 | - parent::__construct($table_manager, $table_analysis); |
|
49 | - } |
|
34 | + /** |
|
35 | + * EE_DMS_Core_4_3_0 constructor. |
|
36 | + * |
|
37 | + * @param TableManager $table_manager |
|
38 | + * @param TableAnalysis $table_analysis |
|
39 | + */ |
|
40 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
41 | + { |
|
42 | + $this->_pretty_name = __("Data Update to Event Espresso 4.3.0", "event_espresso"); |
|
43 | + $this->_priority = 10; |
|
44 | + $this->_migration_stages = array( |
|
45 | + new EE_DMS_4_3_0_question_option_order(), |
|
46 | + new EE_DMS_4_3_0_event_message_templates(), |
|
47 | + ); |
|
48 | + parent::__construct($table_manager, $table_analysis); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | 52 | |
53 | - public function can_migrate_from_version($version_array) |
|
54 | - { |
|
55 | - $version_string = $version_array['Core']; |
|
56 | - if (version_compare($version_string, '4.3.0', '<=') && version_compare($version_string, '4.2.0', '>=')) { |
|
53 | + public function can_migrate_from_version($version_array) |
|
54 | + { |
|
55 | + $version_string = $version_array['Core']; |
|
56 | + if (version_compare($version_string, '4.3.0', '<=') && version_compare($version_string, '4.2.0', '>=')) { |
|
57 | 57 | // echo "$version_string can be migrated fro"; |
58 | - return true; |
|
59 | - } elseif (! $version_string) { |
|
58 | + return true; |
|
59 | + } elseif (! $version_string) { |
|
60 | 60 | // echo "no version string provided: $version_string"; |
61 | - // no version string provided... this must be pre 4.2 |
|
62 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
63 | - } else { |
|
61 | + // no version string provided... this must be pre 4.2 |
|
62 | + return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
63 | + } else { |
|
64 | 64 | // echo "$version_string doesnt apply"; |
65 | - return false; |
|
66 | - } |
|
67 | - } |
|
65 | + return false; |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | 70 | |
71 | - public function schema_changes_before_migration() |
|
72 | - { |
|
73 | - // relies on 4.1's EEH_Activation::create_table |
|
74 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
75 | - $table_name = 'esp_answer'; |
|
76 | - $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
71 | + public function schema_changes_before_migration() |
|
72 | + { |
|
73 | + // relies on 4.1's EEH_Activation::create_table |
|
74 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
75 | + $table_name = 'esp_answer'; |
|
76 | + $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
77 | 77 | REG_ID INT UNSIGNED NOT NULL, |
78 | 78 | QST_ID INT UNSIGNED NOT NULL, |
79 | 79 | ANS_value TEXT NOT NULL, |
80 | 80 | PRIMARY KEY (ANS_ID)"; |
81 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
82 | - $table_name = 'esp_attendee_meta'; |
|
83 | - $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
81 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
82 | + $table_name = 'esp_attendee_meta'; |
|
83 | + $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
84 | 84 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
85 | 85 | ATT_fname VARCHAR(45) NOT NULL, |
86 | 86 | ATT_lname VARCHAR(45) NOT NULL, |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | KEY ATT_fname (ATT_fname), |
97 | 97 | KEY ATT_lname (ATT_lname), |
98 | 98 | KEY ATT_email (ATT_email(191))"; |
99 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
100 | - $table_name = 'esp_country'; |
|
101 | - $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
99 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
100 | + $table_name = 'esp_country'; |
|
101 | + $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
102 | 102 | CNT_ISO3 VARCHAR(3) COLLATE utf8_bin NOT NULL, |
103 | 103 | RGN_ID TINYINT(3) UNSIGNED DEFAULT NULL, |
104 | 104 | CNT_name VARCHAR(45) COLLATE utf8_bin NOT NULL, |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | CNT_is_EU TINYINT(1) DEFAULT '0', |
115 | 115 | CNT_active TINYINT(1) DEFAULT '0', |
116 | 116 | PRIMARY KEY (CNT_ISO)"; |
117 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
118 | - $table_name = 'esp_datetime'; |
|
119 | - $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
117 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
118 | + $table_name = 'esp_datetime'; |
|
119 | + $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
120 | 120 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
121 | 121 | DTT_name VARCHAR(255) NOT NULL DEFAULT '', |
122 | 122 | DTT_description TEXT NOT NULL, |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | PRIMARY KEY (DTT_ID), |
132 | 132 | KEY EVT_ID (EVT_ID), |
133 | 133 | KEY DTT_is_primary (DTT_is_primary)"; |
134 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
135 | - $table_name = 'esp_event_meta'; |
|
136 | - $sql = " |
|
134 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
135 | + $table_name = 'esp_event_meta'; |
|
136 | + $sql = " |
|
137 | 137 | EVTM_ID INT NOT NULL AUTO_INCREMENT, |
138 | 138 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
139 | 139 | EVT_display_desc TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
@@ -148,31 +148,31 @@ discard block |
||
148 | 148 | EVT_external_URL VARCHAR(200) NULL, |
149 | 149 | EVT_donations TINYINT(1) NULL, |
150 | 150 | PRIMARY KEY (EVTM_ID)"; |
151 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | - $table_name = 'esp_event_question_group'; |
|
153 | - $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
151 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | + $table_name = 'esp_event_question_group'; |
|
153 | + $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
154 | 154 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
155 | 155 | QSG_ID INT UNSIGNED NOT NULL, |
156 | 156 | EQG_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
157 | 157 | PRIMARY KEY (EQG_ID)"; |
158 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
159 | - $table_name = 'esp_event_venue'; |
|
160 | - $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
158 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
159 | + $table_name = 'esp_event_venue'; |
|
160 | + $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
161 | 161 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
162 | 162 | VNU_ID BIGINT(20) UNSIGNED NOT NULL, |
163 | 163 | EVV_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
164 | 164 | PRIMARY KEY (EVV_ID)"; |
165 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
166 | - $table_name = 'esp_extra_meta'; |
|
167 | - $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
165 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
166 | + $table_name = 'esp_extra_meta'; |
|
167 | + $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
168 | 168 | OBJ_ID INT(11) DEFAULT NULL, |
169 | 169 | EXM_type VARCHAR(45) DEFAULT NULL, |
170 | 170 | EXM_key VARCHAR(45) DEFAULT NULL, |
171 | 171 | EXM_value TEXT, |
172 | 172 | PRIMARY KEY (EXM_ID)"; |
173 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
174 | - $table_name = 'esp_line_item'; |
|
175 | - $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
173 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
174 | + $table_name = 'esp_line_item'; |
|
175 | + $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
176 | 176 | LIN_code VARCHAR(245) NOT NULL DEFAULT '', |
177 | 177 | TXN_ID INT(11) DEFAULT NULL, |
178 | 178 | LIN_name VARCHAR(245) NOT NULL DEFAULT '', |
@@ -188,19 +188,19 @@ discard block |
||
188 | 188 | OBJ_ID INT(11) DEFAULT NULL, |
189 | 189 | OBJ_type VARCHAR(45)DEFAULT NULL, |
190 | 190 | PRIMARY KEY (LIN_ID)"; |
191 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
192 | - $table_name = 'esp_message_template'; |
|
193 | - $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
191 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
192 | + $table_name = 'esp_message_template'; |
|
193 | + $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
194 | 194 | GRP_ID INT(10) UNSIGNED NOT NULL, |
195 | 195 | MTP_context VARCHAR(50) NOT NULL, |
196 | 196 | MTP_template_field VARCHAR(30) NOT NULL, |
197 | 197 | MTP_content TEXT NOT NULL, |
198 | 198 | PRIMARY KEY (MTP_ID), |
199 | 199 | KEY GRP_ID (GRP_ID)"; |
200 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
201 | - $this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID'); |
|
202 | - $table_name = 'esp_message_template_group'; |
|
203 | - $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
200 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
201 | + $this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID'); |
|
202 | + $table_name = 'esp_message_template_group'; |
|
203 | + $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
204 | 204 | MTP_user_id INT(10) NOT NULL DEFAULT '1', |
205 | 205 | MTP_name VARCHAR(245) NOT NULL DEFAULT '', |
206 | 206 | MTP_description VARCHAR(245) NOT NULL DEFAULT '', |
@@ -212,17 +212,17 @@ discard block |
||
212 | 212 | MTP_is_active TINYINT(1) NOT NULL DEFAULT '1', |
213 | 213 | PRIMARY KEY (GRP_ID), |
214 | 214 | KEY MTP_user_id (MTP_user_id)"; |
215 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
216 | - $table_name = 'esp_event_message_template'; |
|
217 | - $sql = "EMT_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
215 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
216 | + $table_name = 'esp_event_message_template'; |
|
217 | + $sql = "EMT_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
218 | 218 | EVT_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, |
219 | 219 | GRP_ID INT(10) UNSIGNED NOT NULL DEFAULT 0, |
220 | 220 | PRIMARY KEY (EMT_ID), |
221 | 221 | KEY EVT_ID (EVT_ID), |
222 | 222 | KEY GRP_ID (GRP_ID)"; |
223 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | - $table_name = 'esp_payment'; |
|
225 | - $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
223 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | + $table_name = 'esp_payment'; |
|
225 | + $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
226 | 226 | TXN_ID INT(10) UNSIGNED DEFAULT NULL, |
227 | 227 | STS_ID VARCHAR(3) COLLATE utf8_bin DEFAULT NULL, |
228 | 228 | PAY_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -238,9 +238,9 @@ discard block |
||
238 | 238 | PRIMARY KEY (PAY_ID), |
239 | 239 | KEY TXN_ID (TXN_ID), |
240 | 240 | KEY PAY_timestamp (PAY_timestamp)"; |
241 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
242 | - $table_name = "esp_ticket"; |
|
243 | - $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
241 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
242 | + $table_name = "esp_ticket"; |
|
243 | + $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
244 | 244 | TTM_ID INT(10) UNSIGNED NOT NULL, |
245 | 245 | TKT_name VARCHAR(245) NOT NULL DEFAULT '', |
246 | 246 | TKT_description TEXT NOT NULL, |
@@ -260,28 +260,28 @@ discard block |
||
260 | 260 | TKT_parent INT(10) UNSIGNED DEFAULT '0', |
261 | 261 | TKT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
262 | 262 | PRIMARY KEY (TKT_ID)"; |
263 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
264 | - $table_name = "esp_ticket_price"; |
|
265 | - $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
263 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
264 | + $table_name = "esp_ticket_price"; |
|
265 | + $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
266 | 266 | TKT_ID INT(10) UNSIGNED NOT NULL, |
267 | 267 | PRC_ID INT(10) UNSIGNED NOT NULL, |
268 | 268 | PRIMARY KEY (TKP_ID)"; |
269 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
270 | - $table_name = "esp_datetime_ticket"; |
|
271 | - $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
269 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
270 | + $table_name = "esp_datetime_ticket"; |
|
271 | + $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
272 | 272 | DTT_ID INT(10) UNSIGNED NOT NULL, |
273 | 273 | TKT_ID INT(10) UNSIGNED NOT NULL, |
274 | 274 | PRIMARY KEY (DTK_ID)"; |
275 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
276 | - $table_name = "esp_ticket_template"; |
|
277 | - $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
275 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
276 | + $table_name = "esp_ticket_template"; |
|
277 | + $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
278 | 278 | TTM_name VARCHAR(45) NOT NULL, |
279 | 279 | TTM_description TEXT, |
280 | 280 | TTM_file VARCHAR(45), |
281 | 281 | PRIMARY KEY (TTM_ID)"; |
282 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
283 | - $table_name = "esp_price"; |
|
284 | - $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
282 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
283 | + $table_name = "esp_price"; |
|
284 | + $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
285 | 285 | PRT_ID TINYINT(3) UNSIGNED NOT NULL, |
286 | 286 | PRC_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
287 | 287 | PRC_name VARCHAR(245) NOT NULL, |
@@ -292,9 +292,9 @@ discard block |
||
292 | 292 | PRC_order TINYINT(3) UNSIGNED NOT NULL DEFAULT '0', |
293 | 293 | PRC_parent INT(10) UNSIGNED DEFAULT 0, |
294 | 294 | PRIMARY KEY (PRC_ID)"; |
295 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
296 | - $table_name = "esp_price_type"; |
|
297 | - $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
295 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
296 | + $table_name = "esp_price_type"; |
|
297 | + $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
298 | 298 | PRT_name VARCHAR(45) NOT NULL, |
299 | 299 | PBT_ID TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', |
300 | 300 | PRT_is_percent TINYINT(1) NOT NULL DEFAULT '0', |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | PRT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
303 | 303 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
304 | 304 | PRIMARY KEY (PRT_ID)"; |
305 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
306 | - $table_name = 'esp_question'; |
|
307 | - $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
305 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
306 | + $table_name = 'esp_question'; |
|
307 | + $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
308 | 308 | QST_display_text TEXT NOT NULL, |
309 | 309 | QST_admin_label VARCHAR(255) NOT NULL, |
310 | 310 | QST_system VARCHAR(25) DEFAULT NULL, |
@@ -316,10 +316,10 @@ discard block |
||
316 | 316 | QST_wp_user BIGINT UNSIGNED NULL, |
317 | 317 | QST_deleted TINYINT UNSIGNED NOT NULL DEFAULT 0, |
318 | 318 | PRIMARY KEY (QST_ID)'; |
319 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
320 | - $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
321 | - $table_name = 'esp_question_group'; |
|
322 | - $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
319 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
320 | + $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
321 | + $table_name = 'esp_question_group'; |
|
322 | + $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
323 | 323 | QSG_name VARCHAR(255) NOT NULL, |
324 | 324 | QSG_identifier VARCHAR(100) NOT NULL, |
325 | 325 | QSG_desc TEXT NULL, |
@@ -330,25 +330,25 @@ discard block |
||
330 | 330 | QSG_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
331 | 331 | PRIMARY KEY (QSG_ID), |
332 | 332 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)'; |
333 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
334 | - $table_name = 'esp_question_group_question'; |
|
335 | - $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
333 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
334 | + $table_name = 'esp_question_group_question'; |
|
335 | + $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
336 | 336 | QSG_ID INT UNSIGNED NOT NULL, |
337 | 337 | QST_ID INT UNSIGNED NOT NULL, |
338 | 338 | QGQ_order INT UNSIGNED NOT NULL DEFAULT 0, |
339 | 339 | PRIMARY KEY (QGQ_ID) "; |
340 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
341 | - $table_name = 'esp_question_option'; |
|
342 | - $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
340 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
341 | + $table_name = 'esp_question_option'; |
|
342 | + $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
343 | 343 | QSO_value VARCHAR(255) NOT NULL, |
344 | 344 | QSO_desc TEXT NOT NULL, |
345 | 345 | QST_ID INT UNSIGNED NOT NULL, |
346 | 346 | QSO_order INT UNSIGNED NOT NULL DEFAULT 0, |
347 | 347 | QSO_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
348 | 348 | PRIMARY KEY (QSO_ID)"; |
349 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
350 | - $table_name = 'esp_registration'; |
|
351 | - $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
349 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
350 | + $table_name = 'esp_registration'; |
|
351 | + $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
352 | 352 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
353 | 353 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
354 | 354 | TXN_ID INT(10) UNSIGNED NOT NULL, |
@@ -371,25 +371,25 @@ discard block |
||
371 | 371 | KEY STS_ID (STS_ID), |
372 | 372 | KEY REG_url_link (REG_url_link), |
373 | 373 | KEY REG_code (REG_code)"; |
374 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
375 | - $table_name = 'esp_checkin'; |
|
376 | - $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
374 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
375 | + $table_name = 'esp_checkin'; |
|
376 | + $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
377 | 377 | REG_ID INT(10) UNSIGNED NOT NULL, |
378 | 378 | DTT_ID INT(10) UNSIGNED NOT NULL, |
379 | 379 | CHK_in TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
380 | 380 | CHK_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
381 | 381 | PRIMARY KEY (CHK_ID)"; |
382 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
383 | - $table_name = 'esp_state'; |
|
384 | - $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
382 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
383 | + $table_name = 'esp_state'; |
|
384 | + $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
385 | 385 | CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
386 | 386 | STA_abbrev VARCHAR(6) COLLATE utf8_bin NOT NULL, |
387 | 387 | STA_name VARCHAR(100) COLLATE utf8_bin NOT NULL, |
388 | 388 | STA_active TINYINT(1) DEFAULT '1', |
389 | 389 | PRIMARY KEY (STA_ID)"; |
390 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
391 | - $table_name = 'esp_status'; |
|
392 | - $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
390 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
391 | + $table_name = 'esp_status'; |
|
392 | + $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
393 | 393 | STS_code VARCHAR(45) COLLATE utf8_bin NOT NULL, |
394 | 394 | STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL, |
395 | 395 | STS_can_edit TINYINT(1) NOT NULL DEFAULT 0, |
@@ -397,9 +397,9 @@ discard block |
||
397 | 397 | STS_open TINYINT(1) NOT NULL DEFAULT 1, |
398 | 398 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
399 | 399 | KEY STS_type (STS_type)"; |
400 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
401 | - $table_name = 'esp_transaction'; |
|
402 | - $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
400 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
401 | + $table_name = 'esp_transaction'; |
|
402 | + $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
403 | 403 | TXN_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
404 | 404 | TXN_total DECIMAL(10,3) DEFAULT '0.00', |
405 | 405 | TXN_paid DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
@@ -409,9 +409,9 @@ discard block |
||
409 | 409 | PRIMARY KEY (TXN_ID), |
410 | 410 | KEY TXN_timestamp (TXN_timestamp), |
411 | 411 | KEY STS_ID (STS_ID)"; |
412 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
413 | - $table_name = 'esp_venue_meta'; |
|
414 | - $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
412 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
413 | + $table_name = 'esp_venue_meta'; |
|
414 | + $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
415 | 415 | VNU_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, |
416 | 416 | VNU_address VARCHAR(255) DEFAULT NULL, |
417 | 417 | VNU_address2 VARCHAR(255) DEFAULT NULL, |
@@ -429,77 +429,77 @@ discard block |
||
429 | 429 | PRIMARY KEY (VNUM_ID), |
430 | 430 | KEY STA_ID (STA_ID), |
431 | 431 | KEY CNT_ISO (CNT_ISO)"; |
432 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
433 | - $script_with_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
434 | - // setting up the DEFAULT stats and countries is also essential for the data migrations to run |
|
435 | - // (because many need to convert old string states to foreign keys into the states table) |
|
436 | - $script_with_defaults->insert_default_states(); |
|
437 | - $script_with_defaults->insert_default_countries(); |
|
438 | - // setting up DEFAULT prices, price types, and tickets is also essential for the price migrations |
|
439 | - $script_with_defaults->insert_default_price_types(); |
|
440 | - $script_with_defaults->insert_default_prices(); |
|
441 | - // but the schema on the tickets table has changed since 4.1, so use our DEFAULT ticket method instead of 4.1's |
|
442 | - $this->insert_default_tickets(); |
|
443 | - // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
444 | - EE_Config::instance()->update_espresso_config(false, true); |
|
445 | - return true; |
|
446 | - } |
|
432 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
433 | + $script_with_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
434 | + // setting up the DEFAULT stats and countries is also essential for the data migrations to run |
|
435 | + // (because many need to convert old string states to foreign keys into the states table) |
|
436 | + $script_with_defaults->insert_default_states(); |
|
437 | + $script_with_defaults->insert_default_countries(); |
|
438 | + // setting up DEFAULT prices, price types, and tickets is also essential for the price migrations |
|
439 | + $script_with_defaults->insert_default_price_types(); |
|
440 | + $script_with_defaults->insert_default_prices(); |
|
441 | + // but the schema on the tickets table has changed since 4.1, so use our DEFAULT ticket method instead of 4.1's |
|
442 | + $this->insert_default_tickets(); |
|
443 | + // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
444 | + EE_Config::instance()->update_espresso_config(false, true); |
|
445 | + return true; |
|
446 | + } |
|
447 | 447 | |
448 | 448 | |
449 | 449 | |
450 | - /** |
|
451 | - * @return boolean |
|
452 | - */ |
|
453 | - public function schema_changes_after_migration() |
|
454 | - { |
|
455 | - return true; |
|
456 | - } |
|
450 | + /** |
|
451 | + * @return boolean |
|
452 | + */ |
|
453 | + public function schema_changes_after_migration() |
|
454 | + { |
|
455 | + return true; |
|
456 | + } |
|
457 | 457 | |
458 | 458 | |
459 | 459 | |
460 | - public function migration_page_hooks() |
|
461 | - { |
|
462 | - } |
|
460 | + public function migration_page_hooks() |
|
461 | + { |
|
462 | + } |
|
463 | 463 | |
464 | 464 | |
465 | 465 | |
466 | - /** |
|
467 | - * insert DEFAULT ticket |
|
468 | - * Almost identical to EE_DMS_Core_4_1_0::insert_default_tickets, except is aware of the TKT_required field |
|
469 | - * |
|
470 | - * @access public |
|
471 | - * @static |
|
472 | - * @return void |
|
473 | - */ |
|
474 | - public function insert_default_tickets() |
|
475 | - { |
|
476 | - global $wpdb; |
|
477 | - $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
478 | - if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
479 | - $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
480 | - $tickets_exist = $wpdb->get_var($SQL); |
|
481 | - if (! $tickets_exist) { |
|
482 | - $SQL = "INSERT INTO $ticket_table |
|
466 | + /** |
|
467 | + * insert DEFAULT ticket |
|
468 | + * Almost identical to EE_DMS_Core_4_1_0::insert_default_tickets, except is aware of the TKT_required field |
|
469 | + * |
|
470 | + * @access public |
|
471 | + * @static |
|
472 | + * @return void |
|
473 | + */ |
|
474 | + public function insert_default_tickets() |
|
475 | + { |
|
476 | + global $wpdb; |
|
477 | + $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
478 | + if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
479 | + $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
480 | + $tickets_exist = $wpdb->get_var($SQL); |
|
481 | + if (! $tickets_exist) { |
|
482 | + $SQL = "INSERT INTO $ticket_table |
|
483 | 483 | ( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_required, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_deleted ) VALUES |
484 | 484 | ( 1, 0, '" |
485 | - . __("Free Ticket", "event_espresso") |
|
486 | - . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);"; |
|
487 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL); |
|
488 | - $wpdb->query($SQL); |
|
489 | - } |
|
490 | - } |
|
491 | - $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
492 | - if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
493 | - $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
494 | - $ticket_prc_exist = $wpdb->get_var($SQL); |
|
495 | - if (! $ticket_prc_exist) { |
|
496 | - $SQL = "INSERT INTO $ticket_price_table |
|
485 | + . __("Free Ticket", "event_espresso") |
|
486 | + . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);"; |
|
487 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL); |
|
488 | + $wpdb->query($SQL); |
|
489 | + } |
|
490 | + } |
|
491 | + $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
492 | + if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
493 | + $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
494 | + $ticket_prc_exist = $wpdb->get_var($SQL); |
|
495 | + if (! $ticket_prc_exist) { |
|
496 | + $SQL = "INSERT INTO $ticket_price_table |
|
497 | 497 | ( TKP_ID, TKT_ID, PRC_ID ) VALUES |
498 | 498 | ( 1, 1, 1 ) |
499 | 499 | "; |
500 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
501 | - $wpdb->query($SQL); |
|
502 | - } |
|
503 | - } |
|
504 | - } |
|
500 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
501 | + $wpdb->query($SQL); |
|
502 | + } |
|
503 | + } |
|
504 | + } |
|
505 | 505 | } |
@@ -12,11 +12,11 @@ discard block |
||
12 | 12 | $stages = glob(EE_CORE . 'data_migration_scripts/4_1_0_stages/*'); |
13 | 13 | $class_to_filepath = array(); |
14 | 14 | if (! empty($stages)) { |
15 | - foreach ($stages as $filepath) { |
|
16 | - $matches = array(); |
|
17 | - preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
18 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
19 | - } |
|
15 | + foreach ($stages as $filepath) { |
|
16 | + $matches = array(); |
|
17 | + preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
18 | + $class_to_filepath[ $matches[1] ] = $filepath; |
|
19 | + } |
|
20 | 20 | } |
21 | 21 | // give addons a chance to autoload their stages too |
22 | 22 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_1_0__autoloaded_stages', $class_to_filepath); |
@@ -44,91 +44,91 @@ discard block |
||
44 | 44 | |
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * EE_DMS_Core_4_1_0 constructor. |
|
49 | - * |
|
50 | - * @param TableManager $table_manager |
|
51 | - * @param TableAnalysis $table_analysis |
|
52 | - */ |
|
53 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
54 | - { |
|
55 | - $this->_pretty_name = esc_html__("Data Migration from Event Espresso 3 to Event Espresso 4.1.0", "event_espresso"); |
|
56 | - $this->_priority = 10; |
|
57 | - $this->_migration_stages = array( |
|
58 | - new EE_DMS_4_1_0_org_options(), |
|
59 | - new EE_DMS_4_1_0_shortcodes(), |
|
60 | - new EE_DMS_4_1_0_gateways(), |
|
61 | - new EE_DMS_4_1_0_events(), |
|
62 | - new EE_DMS_4_1_0_prices(), |
|
63 | - new EE_DMS_4_1_0_category_details(), |
|
64 | - new EE_DMS_4_1_0_event_category(), |
|
65 | - new EE_DMS_4_1_0_venues(), |
|
66 | - new EE_DMS_4_1_0_event_venue(), |
|
67 | - new EE_DMS_4_1_0_question_groups(), |
|
68 | - new EE_DMS_4_1_0_questions(), |
|
69 | - new EE_DMS_4_1_0_question_group_question(), |
|
70 | - new EE_DMS_4_1_0_event_question_group(), |
|
71 | - new EE_DMS_4_1_0_attendees(), |
|
72 | - new EE_DMS_4_1_0_line_items(), |
|
73 | - new EE_DMS_4_1_0_answers(), |
|
74 | - new EE_DMS_4_1_0_checkins(), |
|
75 | - ); |
|
76 | - parent::__construct($table_manager, $table_analysis); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * Checks if this 3.1 Check-in table exists. If it doesn't we can't migrate Check-ins |
|
83 | - * |
|
84 | - * @global wpdb $wpdb |
|
85 | - * @return boolean |
|
86 | - */ |
|
87 | - private function _checkin_table_exists() |
|
88 | - { |
|
89 | - global $wpdb; |
|
90 | - $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
91 | - if ($results) { |
|
92 | - return true; |
|
93 | - } else { |
|
94 | - return false; |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - public function can_migrate_from_version($version_array) |
|
101 | - { |
|
102 | - $version_string = $version_array['Core']; |
|
103 | - if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
|
47 | + /** |
|
48 | + * EE_DMS_Core_4_1_0 constructor. |
|
49 | + * |
|
50 | + * @param TableManager $table_manager |
|
51 | + * @param TableAnalysis $table_analysis |
|
52 | + */ |
|
53 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
54 | + { |
|
55 | + $this->_pretty_name = esc_html__("Data Migration from Event Espresso 3 to Event Espresso 4.1.0", "event_espresso"); |
|
56 | + $this->_priority = 10; |
|
57 | + $this->_migration_stages = array( |
|
58 | + new EE_DMS_4_1_0_org_options(), |
|
59 | + new EE_DMS_4_1_0_shortcodes(), |
|
60 | + new EE_DMS_4_1_0_gateways(), |
|
61 | + new EE_DMS_4_1_0_events(), |
|
62 | + new EE_DMS_4_1_0_prices(), |
|
63 | + new EE_DMS_4_1_0_category_details(), |
|
64 | + new EE_DMS_4_1_0_event_category(), |
|
65 | + new EE_DMS_4_1_0_venues(), |
|
66 | + new EE_DMS_4_1_0_event_venue(), |
|
67 | + new EE_DMS_4_1_0_question_groups(), |
|
68 | + new EE_DMS_4_1_0_questions(), |
|
69 | + new EE_DMS_4_1_0_question_group_question(), |
|
70 | + new EE_DMS_4_1_0_event_question_group(), |
|
71 | + new EE_DMS_4_1_0_attendees(), |
|
72 | + new EE_DMS_4_1_0_line_items(), |
|
73 | + new EE_DMS_4_1_0_answers(), |
|
74 | + new EE_DMS_4_1_0_checkins(), |
|
75 | + ); |
|
76 | + parent::__construct($table_manager, $table_analysis); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * Checks if this 3.1 Check-in table exists. If it doesn't we can't migrate Check-ins |
|
83 | + * |
|
84 | + * @global wpdb $wpdb |
|
85 | + * @return boolean |
|
86 | + */ |
|
87 | + private function _checkin_table_exists() |
|
88 | + { |
|
89 | + global $wpdb; |
|
90 | + $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
91 | + if ($results) { |
|
92 | + return true; |
|
93 | + } else { |
|
94 | + return false; |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + public function can_migrate_from_version($version_array) |
|
101 | + { |
|
102 | + $version_string = $version_array['Core']; |
|
103 | + if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
|
104 | 104 | // echo "$version_string can be migrated fro"; |
105 | - return true; |
|
106 | - } elseif (! $version_string) { |
|
105 | + return true; |
|
106 | + } elseif (! $version_string) { |
|
107 | 107 | // echo "no version string provided: $version_string"; |
108 | - // no version string provided... this must be pre 4.1 |
|
109 | - // because since 4.1 we're |
|
110 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
111 | - } else { |
|
108 | + // no version string provided... this must be pre 4.1 |
|
109 | + // because since 4.1 we're |
|
110 | + return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
111 | + } else { |
|
112 | 112 | // echo "$version_string doesnt apply"; |
113 | - return false; |
|
114 | - } |
|
115 | - } |
|
113 | + return false; |
|
114 | + } |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | 118 | |
119 | - public function schema_changes_before_migration() |
|
120 | - { |
|
121 | - // relies on 4.1's EEH_Activation::create_table |
|
122 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
123 | - $table_name = 'esp_answer'; |
|
124 | - $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
119 | + public function schema_changes_before_migration() |
|
120 | + { |
|
121 | + // relies on 4.1's EEH_Activation::create_table |
|
122 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
123 | + $table_name = 'esp_answer'; |
|
124 | + $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
125 | 125 | REG_ID INT UNSIGNED NOT NULL, |
126 | 126 | QST_ID INT UNSIGNED NOT NULL, |
127 | 127 | ANS_value TEXT NOT NULL, |
128 | 128 | PRIMARY KEY (ANS_ID)"; |
129 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
130 | - $table_name = 'esp_attendee_meta'; |
|
131 | - $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
129 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
130 | + $table_name = 'esp_attendee_meta'; |
|
131 | + $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
132 | 132 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
133 | 133 | ATT_fname VARCHAR(45) NOT NULL, |
134 | 134 | ATT_lname VARCHAR(45) NOT NULL, |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | KEY ATT_fname (ATT_fname), |
145 | 145 | KEY ATT_lname (ATT_lname), |
146 | 146 | KEY ATT_email (ATT_email(191))"; |
147 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
148 | - $table_name = 'esp_country'; |
|
149 | - $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
147 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
148 | + $table_name = 'esp_country'; |
|
149 | + $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
150 | 150 | CNT_ISO3 VARCHAR(3) COLLATE utf8_bin NOT NULL, |
151 | 151 | RGN_ID TINYINT(3) UNSIGNED DEFAULT NULL, |
152 | 152 | CNT_name VARCHAR(45) COLLATE utf8_bin NOT NULL, |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | CNT_is_EU TINYINT(1) DEFAULT '0', |
163 | 163 | CNT_active TINYINT(1) DEFAULT '0', |
164 | 164 | PRIMARY KEY (CNT_ISO)"; |
165 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
166 | - $table_name = 'esp_datetime'; |
|
167 | - $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
165 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
166 | + $table_name = 'esp_datetime'; |
|
167 | + $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
168 | 168 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
169 | 169 | DTT_EVT_start DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
170 | 170 | DTT_EVT_end DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | PRIMARY KEY (DTT_ID), |
178 | 178 | KEY EVT_ID (EVT_ID), |
179 | 179 | KEY DTT_is_primary (DTT_is_primary)"; |
180 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
181 | - $table_name = 'esp_event_meta'; |
|
182 | - $sql = " |
|
180 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
181 | + $table_name = 'esp_event_meta'; |
|
182 | + $sql = " |
|
183 | 183 | EVTM_ID INT NOT NULL AUTO_INCREMENT, |
184 | 184 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
185 | 185 | EVT_display_desc TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
@@ -194,31 +194,31 @@ discard block |
||
194 | 194 | EVT_external_URL VARCHAR(200) NULL, |
195 | 195 | EVT_donations TINYINT(1) NULL, |
196 | 196 | PRIMARY KEY (EVTM_ID)"; |
197 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | - $table_name = 'esp_event_question_group'; |
|
199 | - $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
197 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | + $table_name = 'esp_event_question_group'; |
|
199 | + $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
200 | 200 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
201 | 201 | QSG_ID INT UNSIGNED NOT NULL, |
202 | 202 | EQG_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
203 | 203 | PRIMARY KEY (EQG_ID)"; |
204 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
205 | - $table_name = 'esp_event_venue'; |
|
206 | - $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
204 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
205 | + $table_name = 'esp_event_venue'; |
|
206 | + $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
207 | 207 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
208 | 208 | VNU_ID BIGINT(20) UNSIGNED NOT NULL, |
209 | 209 | EVV_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
210 | 210 | PRIMARY KEY (EVV_ID)"; |
211 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
212 | - $table_name = 'esp_extra_meta'; |
|
213 | - $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
211 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
212 | + $table_name = 'esp_extra_meta'; |
|
213 | + $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
214 | 214 | OBJ_ID INT(11) DEFAULT NULL, |
215 | 215 | EXM_type VARCHAR(45) DEFAULT NULL, |
216 | 216 | EXM_key VARCHAR(45) DEFAULT NULL, |
217 | 217 | EXM_value TEXT, |
218 | 218 | PRIMARY KEY (EXM_ID)"; |
219 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
220 | - $table_name = 'esp_line_item'; |
|
221 | - $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
219 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
220 | + $table_name = 'esp_line_item'; |
|
221 | + $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
222 | 222 | LIN_code VARCHAR(245) NOT NULL DEFAULT '', |
223 | 223 | TXN_ID INT(11) DEFAULT NULL, |
224 | 224 | LIN_name VARCHAR(245) NOT NULL DEFAULT '', |
@@ -234,18 +234,18 @@ discard block |
||
234 | 234 | OBJ_ID INT(11) DEFAULT NULL, |
235 | 235 | OBJ_type VARCHAR(45)DEFAULT NULL, |
236 | 236 | PRIMARY KEY (LIN_ID)"; |
237 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
238 | - $table_name = 'esp_message_template'; |
|
239 | - $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
237 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
238 | + $table_name = 'esp_message_template'; |
|
239 | + $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
240 | 240 | GRP_ID INT(10) UNSIGNED NOT NULL, |
241 | 241 | MTP_context VARCHAR(50) NOT NULL, |
242 | 242 | MTP_template_field VARCHAR(30) NOT NULL, |
243 | 243 | MTP_content TEXT NOT NULL, |
244 | 244 | PRIMARY KEY (MTP_ID), |
245 | 245 | KEY GRP_ID (GRP_ID)"; |
246 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
247 | - $table_name = 'esp_message_template_group'; |
|
248 | - $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
246 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
247 | + $table_name = 'esp_message_template_group'; |
|
248 | + $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
249 | 249 | EVT_ID BIGINT(20) UNSIGNED DEFAULT NULL, |
250 | 250 | MTP_user_id INT(10) NOT NULL DEFAULT '1', |
251 | 251 | MTP_messenger VARCHAR(30) NOT NULL, |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | PRIMARY KEY (GRP_ID), |
258 | 258 | KEY EVT_ID (EVT_ID), |
259 | 259 | KEY MTP_user_id (MTP_user_id)"; |
260 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
261 | - $table_name = 'esp_payment'; |
|
262 | - $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
260 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
261 | + $table_name = 'esp_payment'; |
|
262 | + $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
263 | 263 | TXN_ID INT(10) UNSIGNED DEFAULT NULL, |
264 | 264 | STS_ID VARCHAR(3) COLLATE utf8_bin DEFAULT NULL, |
265 | 265 | PAY_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -275,9 +275,9 @@ discard block |
||
275 | 275 | PRIMARY KEY (PAY_ID), |
276 | 276 | KEY TXN_ID (TXN_ID), |
277 | 277 | KEY PAY_timestamp (PAY_timestamp)"; |
278 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
279 | - $table_name = "esp_ticket"; |
|
280 | - $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
278 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
279 | + $table_name = "esp_ticket"; |
|
280 | + $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
281 | 281 | TTM_ID INT(10) UNSIGNED NOT NULL, |
282 | 282 | TKT_name VARCHAR(245) NOT NULL DEFAULT '', |
283 | 283 | TKT_description TEXT NOT NULL, |
@@ -296,28 +296,28 @@ discard block |
||
296 | 296 | TKT_parent INT(10) UNSIGNED DEFAULT '0', |
297 | 297 | TKT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
298 | 298 | PRIMARY KEY (TKT_ID)"; |
299 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
300 | - $table_name = "esp_ticket_price"; |
|
301 | - $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
299 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
300 | + $table_name = "esp_ticket_price"; |
|
301 | + $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
302 | 302 | TKT_ID INT(10) UNSIGNED NOT NULL, |
303 | 303 | PRC_ID INT(10) UNSIGNED NOT NULL, |
304 | 304 | PRIMARY KEY (TKP_ID)"; |
305 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
306 | - $table_name = "esp_datetime_ticket"; |
|
307 | - $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
305 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
306 | + $table_name = "esp_datetime_ticket"; |
|
307 | + $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
308 | 308 | DTT_ID INT(10) UNSIGNED NOT NULL, |
309 | 309 | TKT_ID INT(10) UNSIGNED NOT NULL, |
310 | 310 | PRIMARY KEY (DTK_ID)"; |
311 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
312 | - $table_name = "esp_ticket_template"; |
|
313 | - $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
311 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
312 | + $table_name = "esp_ticket_template"; |
|
313 | + $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
314 | 314 | TTM_name VARCHAR(45) NOT NULL, |
315 | 315 | TTM_description TEXT, |
316 | 316 | TTM_file VARCHAR(45), |
317 | 317 | PRIMARY KEY (TTM_ID)"; |
318 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
319 | - $table_name = "esp_price"; |
|
320 | - $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
318 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
319 | + $table_name = "esp_price"; |
|
320 | + $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
321 | 321 | PRT_ID TINYINT(3) UNSIGNED NOT NULL, |
322 | 322 | PRC_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
323 | 323 | PRC_name VARCHAR(245) NOT NULL, |
@@ -328,9 +328,9 @@ discard block |
||
328 | 328 | PRC_order TINYINT(3) UNSIGNED NOT NULL DEFAULT '0', |
329 | 329 | PRC_parent INT(10) UNSIGNED DEFAULT 0, |
330 | 330 | PRIMARY KEY (PRC_ID)"; |
331 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
332 | - $table_name = "esp_price_type"; |
|
333 | - $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
331 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
332 | + $table_name = "esp_price_type"; |
|
333 | + $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
334 | 334 | PRT_name VARCHAR(45) NOT NULL, |
335 | 335 | PBT_ID TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', |
336 | 336 | PRT_is_percent TINYINT(1) NOT NULL DEFAULT '0', |
@@ -338,9 +338,9 @@ discard block |
||
338 | 338 | PRT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
339 | 339 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
340 | 340 | PRIMARY KEY (PRT_ID)"; |
341 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
342 | - $table_name = 'esp_question'; |
|
343 | - $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
341 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
342 | + $table_name = 'esp_question'; |
|
343 | + $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
344 | 344 | QST_display_text TEXT NOT NULL, |
345 | 345 | QST_admin_label VARCHAR(255) NOT NULL, |
346 | 346 | QST_system VARCHAR(25) DEFAULT NULL, |
@@ -352,10 +352,10 @@ discard block |
||
352 | 352 | QST_wp_user BIGINT UNSIGNED NULL, |
353 | 353 | QST_deleted TINYINT UNSIGNED NOT NULL DEFAULT 0, |
354 | 354 | PRIMARY KEY (QST_ID)'; |
355 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
356 | - $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
357 | - $table_name = 'esp_question_group'; |
|
358 | - $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
355 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
356 | + $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
357 | + $table_name = 'esp_question_group'; |
|
358 | + $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
359 | 359 | QSG_name VARCHAR(255) NOT NULL, |
360 | 360 | QSG_identifier VARCHAR(100) NOT NULL, |
361 | 361 | QSG_desc TEXT NULL, |
@@ -366,23 +366,23 @@ discard block |
||
366 | 366 | QSG_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
367 | 367 | PRIMARY KEY (QSG_ID), |
368 | 368 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)'; |
369 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
370 | - $table_name = 'esp_question_group_question'; |
|
371 | - $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
369 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
370 | + $table_name = 'esp_question_group_question'; |
|
371 | + $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
372 | 372 | QSG_ID INT UNSIGNED NOT NULL, |
373 | 373 | QST_ID INT UNSIGNED NOT NULL, |
374 | 374 | PRIMARY KEY (QGQ_ID) "; |
375 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
376 | - $table_name = 'esp_question_option'; |
|
377 | - $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
375 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
376 | + $table_name = 'esp_question_option'; |
|
377 | + $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
378 | 378 | QSO_value VARCHAR(255) NOT NULL, |
379 | 379 | QSO_desc TEXT NOT NULL, |
380 | 380 | QST_ID INT UNSIGNED NOT NULL, |
381 | 381 | QSO_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
382 | 382 | PRIMARY KEY (QSO_ID)"; |
383 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
384 | - $table_name = 'esp_registration'; |
|
385 | - $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
383 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
384 | + $table_name = 'esp_registration'; |
|
385 | + $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
386 | 386 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
387 | 387 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
388 | 388 | TXN_ID INT(10) UNSIGNED NOT NULL, |
@@ -405,25 +405,25 @@ discard block |
||
405 | 405 | KEY STS_ID (STS_ID), |
406 | 406 | KEY REG_url_link (REG_url_link), |
407 | 407 | KEY REG_code (REG_code)"; |
408 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
409 | - $table_name = 'esp_checkin'; |
|
410 | - $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
408 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
409 | + $table_name = 'esp_checkin'; |
|
410 | + $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
411 | 411 | REG_ID INT(10) UNSIGNED NOT NULL, |
412 | 412 | DTT_ID INT(10) UNSIGNED NOT NULL, |
413 | 413 | CHK_in TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
414 | 414 | CHK_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
415 | 415 | PRIMARY KEY (CHK_ID)"; |
416 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
417 | - $table_name = 'esp_state'; |
|
418 | - $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
416 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
417 | + $table_name = 'esp_state'; |
|
418 | + $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
419 | 419 | CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
420 | 420 | STA_abbrev VARCHAR(6) COLLATE utf8_bin NOT NULL, |
421 | 421 | STA_name VARCHAR(100) COLLATE utf8_bin NOT NULL, |
422 | 422 | STA_active TINYINT(1) DEFAULT '1', |
423 | 423 | PRIMARY KEY (STA_ID)"; |
424 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
425 | - $table_name = 'esp_status'; |
|
426 | - $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
424 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
425 | + $table_name = 'esp_status'; |
|
426 | + $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
427 | 427 | STS_code VARCHAR(45) COLLATE utf8_bin NOT NULL, |
428 | 428 | STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL, |
429 | 429 | STS_can_edit TINYINT(1) NOT NULL DEFAULT 0, |
@@ -431,9 +431,9 @@ discard block |
||
431 | 431 | STS_open TINYINT(1) NOT NULL DEFAULT 1, |
432 | 432 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
433 | 433 | KEY STS_type (STS_type)"; |
434 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
435 | - $table_name = 'esp_transaction'; |
|
436 | - $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
434 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
435 | + $table_name = 'esp_transaction'; |
|
436 | + $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
437 | 437 | TXN_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
438 | 438 | TXN_total DECIMAL(10,3) DEFAULT '0.00', |
439 | 439 | TXN_paid DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
@@ -443,9 +443,9 @@ discard block |
||
443 | 443 | PRIMARY KEY (TXN_ID), |
444 | 444 | KEY TXN_timestamp (TXN_timestamp), |
445 | 445 | KEY STS_ID (STS_ID)"; |
446 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
447 | - $table_name = 'esp_venue_meta'; |
|
448 | - $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
446 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
447 | + $table_name = 'esp_venue_meta'; |
|
448 | + $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
449 | 449 | VNU_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, |
450 | 450 | VNU_address VARCHAR(255) DEFAULT NULL, |
451 | 451 | VNU_address2 VARCHAR(255) DEFAULT NULL, |
@@ -463,52 +463,52 @@ discard block |
||
463 | 463 | PRIMARY KEY (VNUM_ID), |
464 | 464 | KEY STA_ID (STA_ID), |
465 | 465 | KEY CNT_ISO (CNT_ISO)"; |
466 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
467 | - // setting up the DEFAULT stats and countries is also essential for the data migrations to run |
|
468 | - // (because many need to convert old string states to foreign keys into the states table) |
|
469 | - $this->insert_default_states(); |
|
470 | - $this->insert_default_countries(); |
|
471 | - // setting up DEFAULT prices, price types, and tickets is also essential for the price migrations |
|
472 | - $this->insert_default_price_types(); |
|
473 | - $this->insert_default_prices(); |
|
474 | - $this->insert_default_tickets(); |
|
475 | - // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
476 | - EE_Config::instance()->update_espresso_config(false, true); |
|
477 | - return true; |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * Yes we could have cleaned up the ee3 tables here. But just in case someone |
|
484 | - * didn't backup their DB, and decides they want ot keep using EE3, we'll |
|
485 | - * leave them for now. Mayeb remove them in 4.5 or something. |
|
486 | - * |
|
487 | - * @return boolean |
|
488 | - */ |
|
489 | - public function schema_changes_after_migration() |
|
490 | - { |
|
491 | - return true; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - |
|
496 | - /** |
|
497 | - * insert_default_states |
|
498 | - * |
|
499 | - * @access public |
|
500 | - * @static |
|
501 | - * @return void |
|
502 | - */ |
|
503 | - public function insert_default_states() |
|
504 | - { |
|
505 | - global $wpdb; |
|
506 | - $state_table = $wpdb->prefix . "esp_state"; |
|
507 | - if ($this->_get_table_analysis()->tableExists($state_table)) { |
|
508 | - $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
509 | - $states = $wpdb->get_var($SQL); |
|
510 | - if (! $states) { |
|
511 | - $SQL = "INSERT INTO " . $state_table . " |
|
466 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
467 | + // setting up the DEFAULT stats and countries is also essential for the data migrations to run |
|
468 | + // (because many need to convert old string states to foreign keys into the states table) |
|
469 | + $this->insert_default_states(); |
|
470 | + $this->insert_default_countries(); |
|
471 | + // setting up DEFAULT prices, price types, and tickets is also essential for the price migrations |
|
472 | + $this->insert_default_price_types(); |
|
473 | + $this->insert_default_prices(); |
|
474 | + $this->insert_default_tickets(); |
|
475 | + // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
476 | + EE_Config::instance()->update_espresso_config(false, true); |
|
477 | + return true; |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * Yes we could have cleaned up the ee3 tables here. But just in case someone |
|
484 | + * didn't backup their DB, and decides they want ot keep using EE3, we'll |
|
485 | + * leave them for now. Mayeb remove them in 4.5 or something. |
|
486 | + * |
|
487 | + * @return boolean |
|
488 | + */ |
|
489 | + public function schema_changes_after_migration() |
|
490 | + { |
|
491 | + return true; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + |
|
496 | + /** |
|
497 | + * insert_default_states |
|
498 | + * |
|
499 | + * @access public |
|
500 | + * @static |
|
501 | + * @return void |
|
502 | + */ |
|
503 | + public function insert_default_states() |
|
504 | + { |
|
505 | + global $wpdb; |
|
506 | + $state_table = $wpdb->prefix . "esp_state"; |
|
507 | + if ($this->_get_table_analysis()->tableExists($state_table)) { |
|
508 | + $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
509 | + $states = $wpdb->get_var($SQL); |
|
510 | + if (! $states) { |
|
511 | + $SQL = "INSERT INTO " . $state_table . " |
|
512 | 512 | (STA_ID, CNT_ISO, STA_abbrev, STA_name, STA_active) VALUES |
513 | 513 | (1, 'US', 'AK', 'Alaska', 1), |
514 | 514 | (2, 'US', 'AL', 'Alabama', 1), |
@@ -579,29 +579,29 @@ discard block |
||
579 | 579 | (67, 'CA', 'PE', 'Prince Edward Island', 1), |
580 | 580 | (68, 'CA', 'QC', 'Quebec', 1), |
581 | 581 | (69, 'CA', 'SK', 'Saskatchewan', 1);"; |
582 | - $wpdb->query($SQL); |
|
583 | - } |
|
584 | - } |
|
585 | - } |
|
586 | - |
|
587 | - |
|
588 | - |
|
589 | - /** |
|
590 | - * insert_default_countries |
|
591 | - * |
|
592 | - * @access public |
|
593 | - * @static |
|
594 | - * @return void |
|
595 | - */ |
|
596 | - public function insert_default_countries() |
|
597 | - { |
|
598 | - global $wpdb; |
|
599 | - $country_table = $wpdb->prefix . "esp_country"; |
|
600 | - if ($this->_get_table_analysis()->tableExists($country_table)) { |
|
601 | - $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
602 | - $countries = $wpdb->get_var($SQL); |
|
603 | - if (! $countries) { |
|
604 | - $SQL = "INSERT INTO " . $country_table . " |
|
582 | + $wpdb->query($SQL); |
|
583 | + } |
|
584 | + } |
|
585 | + } |
|
586 | + |
|
587 | + |
|
588 | + |
|
589 | + /** |
|
590 | + * insert_default_countries |
|
591 | + * |
|
592 | + * @access public |
|
593 | + * @static |
|
594 | + * @return void |
|
595 | + */ |
|
596 | + public function insert_default_countries() |
|
597 | + { |
|
598 | + global $wpdb; |
|
599 | + $country_table = $wpdb->prefix . "esp_country"; |
|
600 | + if ($this->_get_table_analysis()->tableExists($country_table)) { |
|
601 | + $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
602 | + $countries = $wpdb->get_var($SQL); |
|
603 | + if (! $countries) { |
|
604 | + $SQL = "INSERT INTO " . $country_table . " |
|
605 | 605 | (CNT_ISO, CNT_ISO3, RGN_ID, CNT_name, CNT_cur_code, CNT_cur_single, CNT_cur_plural, CNT_cur_sign, CNT_cur_sign_b4, CNT_cur_dec_plc, CNT_tel_code, CNT_is_EU, CNT_active) VALUES |
606 | 606 | ('AD', 'AND', 0, 'Andorra', 'EUR', 'Euro', 'Euros', '€', 1, 2, '+376', 0, 0), |
607 | 607 | ('AE', 'ARE', 0, 'United Arab Emirates', 'AED', 'Dirham', 'Dirhams', 'د.إ', 1, 2, '+971', 0, 0), |
@@ -829,984 +829,984 @@ discard block |
||
829 | 829 | ('ZA', 'ZAF', 0, 'South Africa', 'ZAR', 'Rand', 'Rands', 'R', 1, 2, '+27', 0, 0), |
830 | 830 | ('ZM', 'ZMB', 0, 'Zambia', 'ZMK', 'Kwacha', 'Kwachas', '', 1, 2, '+260', 0, 0), |
831 | 831 | ('ZW', 'ZWE', 0, 'Zimbabwe', 'ZWD', 'Dollar', 'Dollars', 'Z$', 1, 2, '+263', 0, 0);"; |
832 | - $wpdb->query($SQL); |
|
833 | - } |
|
834 | - } |
|
835 | - } |
|
836 | - |
|
837 | - |
|
838 | - |
|
839 | - /** |
|
840 | - * insert_default_price_types |
|
841 | - * |
|
842 | - * @access public |
|
843 | - * @static |
|
844 | - * @return void |
|
845 | - */ |
|
846 | - public function insert_default_price_types() |
|
847 | - { |
|
848 | - global $wpdb; |
|
849 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
850 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
851 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
852 | - $price_types_exist = $wpdb->get_var($SQL); |
|
853 | - if (! $price_types_exist) { |
|
854 | - $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
|
832 | + $wpdb->query($SQL); |
|
833 | + } |
|
834 | + } |
|
835 | + } |
|
836 | + |
|
837 | + |
|
838 | + |
|
839 | + /** |
|
840 | + * insert_default_price_types |
|
841 | + * |
|
842 | + * @access public |
|
843 | + * @static |
|
844 | + * @return void |
|
845 | + */ |
|
846 | + public function insert_default_price_types() |
|
847 | + { |
|
848 | + global $wpdb; |
|
849 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
850 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
851 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
852 | + $price_types_exist = $wpdb->get_var($SQL); |
|
853 | + if (! $price_types_exist) { |
|
854 | + $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
|
855 | 855 | (1, '" . esc_html__('Base Price', 'event_espresso') . "', 1, 0, 0, 0), |
856 | 856 | (2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2, 1, 20, 0), |
857 | 857 | (3, '" . esc_html__('Fixed Discount', 'event_espresso') . "', 2, 0, 30, 0), |
858 | 858 | (4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3, 1, 40, 0), |
859 | 859 | (5, '" . esc_html__('Fixed Surcharge', 'event_espresso') . "', 3, 0, 50, 0);"; |
860 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
|
861 | - $wpdb->query($SQL); |
|
862 | - } |
|
863 | - } |
|
864 | - } |
|
865 | - |
|
866 | - |
|
867 | - |
|
868 | - /** |
|
869 | - * insert_default_prices. We assume we're upgrading to regular here. |
|
870 | - * If we're INSTALLING 4.1 CAF, then we add a few extra DEFAULT prices |
|
871 | - * when EEH_Activaion's initialize_db_content is called via ahook in |
|
872 | - * EE_BRewing_regular |
|
873 | - * |
|
874 | - * @access public |
|
875 | - * @static |
|
876 | - * @return void |
|
877 | - */ |
|
878 | - public function insert_default_prices() |
|
879 | - { |
|
880 | - global $wpdb; |
|
881 | - $price_table = $wpdb->prefix . "esp_price"; |
|
882 | - if ($this->_get_table_analysis()->tableExists($price_table)) { |
|
883 | - $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
884 | - $prices_exist = $wpdb->get_var($SQL); |
|
885 | - if (! $prices_exist) { |
|
886 | - $SQL = "INSERT INTO $price_table |
|
860 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
|
861 | + $wpdb->query($SQL); |
|
862 | + } |
|
863 | + } |
|
864 | + } |
|
865 | + |
|
866 | + |
|
867 | + |
|
868 | + /** |
|
869 | + * insert_default_prices. We assume we're upgrading to regular here. |
|
870 | + * If we're INSTALLING 4.1 CAF, then we add a few extra DEFAULT prices |
|
871 | + * when EEH_Activaion's initialize_db_content is called via ahook in |
|
872 | + * EE_BRewing_regular |
|
873 | + * |
|
874 | + * @access public |
|
875 | + * @static |
|
876 | + * @return void |
|
877 | + */ |
|
878 | + public function insert_default_prices() |
|
879 | + { |
|
880 | + global $wpdb; |
|
881 | + $price_table = $wpdb->prefix . "esp_price"; |
|
882 | + if ($this->_get_table_analysis()->tableExists($price_table)) { |
|
883 | + $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
884 | + $prices_exist = $wpdb->get_var($SQL); |
|
885 | + if (! $prices_exist) { |
|
886 | + $SQL = "INSERT INTO $price_table |
|
887 | 887 | (PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc, PRC_is_default, PRC_overrides, PRC_order, PRC_deleted, PRC_parent ) VALUES |
888 | 888 | (1, 1, '0.00', 'Free Admission', '', 1, NULL, 0, 0, 0);"; |
889 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_prices__SQL', $SQL); |
|
890 | - $wpdb->query($SQL); |
|
891 | - } |
|
892 | - } |
|
893 | - } |
|
894 | - |
|
895 | - |
|
896 | - |
|
897 | - /** |
|
898 | - * insert DEFAULT ticket |
|
899 | - * |
|
900 | - * @access public |
|
901 | - * @static |
|
902 | - * @return void |
|
903 | - */ |
|
904 | - public function insert_default_tickets() |
|
905 | - { |
|
906 | - global $wpdb; |
|
907 | - $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
908 | - if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
909 | - $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
910 | - $tickets_exist = $wpdb->get_var($SQL); |
|
911 | - if (! $tickets_exist) { |
|
912 | - $SQL = "INSERT INTO $ticket_table |
|
889 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_prices__SQL', $SQL); |
|
890 | + $wpdb->query($SQL); |
|
891 | + } |
|
892 | + } |
|
893 | + } |
|
894 | + |
|
895 | + |
|
896 | + |
|
897 | + /** |
|
898 | + * insert DEFAULT ticket |
|
899 | + * |
|
900 | + * @access public |
|
901 | + * @static |
|
902 | + * @return void |
|
903 | + */ |
|
904 | + public function insert_default_tickets() |
|
905 | + { |
|
906 | + global $wpdb; |
|
907 | + $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
908 | + if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
909 | + $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
910 | + $tickets_exist = $wpdb->get_var($SQL); |
|
911 | + if (! $tickets_exist) { |
|
912 | + $SQL = "INSERT INTO $ticket_table |
|
913 | 913 | ( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_deleted ) VALUES |
914 | 914 | ( 1, 0, '" |
915 | - . esc_html__("Free Ticket", "event_espresso") |
|
916 | - . "', '', 100, 0, -1, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);"; |
|
917 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL); |
|
918 | - $wpdb->query($SQL); |
|
919 | - } |
|
920 | - } |
|
921 | - $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
922 | - if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
923 | - $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
924 | - $ticket_prc_exist = $wpdb->get_var($SQL); |
|
925 | - if (! $ticket_prc_exist) { |
|
926 | - $SQL = "INSERT INTO $ticket_price_table |
|
915 | + . esc_html__("Free Ticket", "event_espresso") |
|
916 | + . "', '', 100, 0, -1, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);"; |
|
917 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL); |
|
918 | + $wpdb->query($SQL); |
|
919 | + } |
|
920 | + } |
|
921 | + $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
922 | + if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
923 | + $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
924 | + $ticket_prc_exist = $wpdb->get_var($SQL); |
|
925 | + if (! $ticket_prc_exist) { |
|
926 | + $SQL = "INSERT INTO $ticket_price_table |
|
927 | 927 | ( TKP_ID, TKT_ID, PRC_ID ) VALUES |
928 | 928 | ( 1, 1, 1 ) |
929 | 929 | "; |
930 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
931 | - $wpdb->query($SQL); |
|
932 | - } |
|
933 | - } |
|
934 | - } |
|
935 | - |
|
936 | - |
|
937 | - |
|
938 | - /** |
|
939 | - * Gets a country entry as an array, or creates one if none is found. Much like EEM_Country::instance()->get_one(), |
|
940 | - * but is independent of outside code which can change in future versions of EE. Also, $country_name CAN be a 3.1 |
|
941 | - * country ID (int), a 2-letter ISO, 3-letter ISO, or name |
|
942 | - * |
|
943 | - * @global type $wpdb |
|
944 | - * @param string $country_name |
|
945 | - * @return array where keys are columns, values are column values |
|
946 | - */ |
|
947 | - public function get_or_create_country($country_name) |
|
948 | - { |
|
949 | - if (! $country_name) { |
|
950 | - throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso")); |
|
951 | - } |
|
952 | - global $wpdb; |
|
953 | - $country_table = $wpdb->prefix . "esp_country"; |
|
954 | - if (is_int($country_name)) { |
|
955 | - $country_name = $this->get_iso_from_3_1_country_id($country_name); |
|
956 | - } |
|
957 | - $country = $wpdb->get_row($wpdb->prepare("SELECT * FROM $country_table WHERE |
|
930 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
931 | + $wpdb->query($SQL); |
|
932 | + } |
|
933 | + } |
|
934 | + } |
|
935 | + |
|
936 | + |
|
937 | + |
|
938 | + /** |
|
939 | + * Gets a country entry as an array, or creates one if none is found. Much like EEM_Country::instance()->get_one(), |
|
940 | + * but is independent of outside code which can change in future versions of EE. Also, $country_name CAN be a 3.1 |
|
941 | + * country ID (int), a 2-letter ISO, 3-letter ISO, or name |
|
942 | + * |
|
943 | + * @global type $wpdb |
|
944 | + * @param string $country_name |
|
945 | + * @return array where keys are columns, values are column values |
|
946 | + */ |
|
947 | + public function get_or_create_country($country_name) |
|
948 | + { |
|
949 | + if (! $country_name) { |
|
950 | + throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso")); |
|
951 | + } |
|
952 | + global $wpdb; |
|
953 | + $country_table = $wpdb->prefix . "esp_country"; |
|
954 | + if (is_int($country_name)) { |
|
955 | + $country_name = $this->get_iso_from_3_1_country_id($country_name); |
|
956 | + } |
|
957 | + $country = $wpdb->get_row($wpdb->prepare("SELECT * FROM $country_table WHERE |
|
958 | 958 | CNT_ISO LIKE %s OR |
959 | 959 | CNT_ISO3 LIKE %s OR |
960 | 960 | CNT_name LIKE %s LIMIT 1", $country_name, $country_name, $country_name), ARRAY_A); |
961 | - if (! $country) { |
|
962 | - // insert a new one then |
|
963 | - $cols_n_values = array( |
|
964 | - 'CNT_ISO' => $this->_find_available_country_iso(2), |
|
965 | - 'CNT_ISO3' => $this->_find_available_country_iso(3), |
|
966 | - 'RGN_ID' => 0, |
|
967 | - 'CNT_name' => $country_name, |
|
968 | - 'CNT_cur_code' => 'USD', |
|
969 | - 'CNT_cur_single' => 'Dollar', |
|
970 | - 'CNT_cur_plural' => 'Dollars', |
|
971 | - 'CNT_cur_sign' => '$', |
|
972 | - 'CNT_cur_sign_b4' => true, |
|
973 | - 'CNT_cur_dec_plc' => 2, |
|
974 | - 'CNT_cur_dec_mrk' => '.', |
|
975 | - 'CNT_cur_thsnds' => ',', |
|
976 | - 'CNT_tel_code' => '+1', |
|
977 | - 'CNT_is_EU' => false, |
|
978 | - 'CNT_active' => true, |
|
979 | - ); |
|
980 | - $data_types = array( |
|
981 | - '%s',// CNT_ISO |
|
982 | - '%s',// CNT_ISO3 |
|
983 | - '%d',// RGN_ID |
|
984 | - '%s',// CNT_name |
|
985 | - '%s',// CNT_cur_code |
|
986 | - '%s',// CNT_cur_single |
|
987 | - '%s',// CNT_cur_plural |
|
988 | - '%s',// CNT_cur_sign |
|
989 | - '%d',// CNT_cur_sign_b4 |
|
990 | - '%d',// CNT_cur_dec_plc |
|
991 | - '%s',// CNT_cur_dec_mrk |
|
992 | - '%s',// CNT_cur_thsnds |
|
993 | - '%s',// CNT_tel_code |
|
994 | - '%d',// CNT_is_EU |
|
995 | - '%d',// CNT_active |
|
996 | - ); |
|
997 | - $success = $wpdb->insert( |
|
998 | - $country_table, |
|
999 | - $cols_n_values, |
|
1000 | - $data_types |
|
1001 | - ); |
|
1002 | - if (! $success) { |
|
1003 | - throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
1004 | - 'N/A', |
|
1005 | - array('country_id' => $country_name), |
|
1006 | - $country_table, |
|
1007 | - $cols_n_values, |
|
1008 | - $data_types |
|
1009 | - )); |
|
1010 | - } |
|
1011 | - $country = $cols_n_values; |
|
1012 | - } |
|
1013 | - return $country; |
|
1014 | - } |
|
1015 | - |
|
1016 | - |
|
1017 | - |
|
1018 | - /** |
|
1019 | - * finds a country iso which hasnt been used yet |
|
1020 | - * |
|
1021 | - * @global type $wpdb |
|
1022 | - * @return string |
|
1023 | - */ |
|
1024 | - private function _find_available_country_iso($num_letters = 2) |
|
1025 | - { |
|
1026 | - global $wpdb; |
|
1027 | - $country_table = $wpdb->prefix . "esp_country"; |
|
1028 | - $attempts = 0; |
|
1029 | - do { |
|
1030 | - $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
|
1031 | - $country_with_that_iso = $wpdb->get_var($wpdb->prepare("SELECT count(CNT_ISO) FROM " |
|
1032 | - . $country_table |
|
1033 | - . " WHERE CNT_ISO=%s", $current_iso)); |
|
1034 | - $attempts++; |
|
1035 | - // keep going until we find an available country code, or we arbitrarily |
|
1036 | - // decide we've tried this enough. Somehow they have way too many countries |
|
1037 | - // (probably because they're mis-using the EE3 country_id like a custom question) |
|
1038 | - } while (intval($country_with_that_iso) && $attempts < 200); |
|
1039 | - return $current_iso; |
|
1040 | - } |
|
1041 | - |
|
1042 | - |
|
1043 | - |
|
1044 | - /** |
|
1045 | - * Gets a state entry as an array, or creates one if none is found. Much like EEM_State::instance()->get_one(), but |
|
1046 | - * is independent of outside code which can change in future versions of EE |
|
1047 | - * |
|
1048 | - * @global type $wpdb |
|
1049 | - * @param string $state_name |
|
1050 | - * @return array where keys are columns, values are column values |
|
1051 | - */ |
|
1052 | - public function get_or_create_state($state_name, $country_name = '') |
|
1053 | - { |
|
1054 | - if (! $state_name) { |
|
1055 | - throw new EE_Error(esc_html__( |
|
1056 | - "Could not get-or-create state because no state name was provided", |
|
1057 | - "event_espresso" |
|
1058 | - )); |
|
1059 | - } |
|
1060 | - try { |
|
1061 | - $country = $this->get_or_create_country($country_name); |
|
1062 | - $country_iso = $country['CNT_ISO']; |
|
1063 | - } catch (EE_Error $e) { |
|
1064 | - $country_iso = $this->get_default_country_iso(); |
|
1065 | - } |
|
1066 | - global $wpdb; |
|
1067 | - $state_table = $wpdb->prefix . "esp_state"; |
|
1068 | - $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
|
961 | + if (! $country) { |
|
962 | + // insert a new one then |
|
963 | + $cols_n_values = array( |
|
964 | + 'CNT_ISO' => $this->_find_available_country_iso(2), |
|
965 | + 'CNT_ISO3' => $this->_find_available_country_iso(3), |
|
966 | + 'RGN_ID' => 0, |
|
967 | + 'CNT_name' => $country_name, |
|
968 | + 'CNT_cur_code' => 'USD', |
|
969 | + 'CNT_cur_single' => 'Dollar', |
|
970 | + 'CNT_cur_plural' => 'Dollars', |
|
971 | + 'CNT_cur_sign' => '$', |
|
972 | + 'CNT_cur_sign_b4' => true, |
|
973 | + 'CNT_cur_dec_plc' => 2, |
|
974 | + 'CNT_cur_dec_mrk' => '.', |
|
975 | + 'CNT_cur_thsnds' => ',', |
|
976 | + 'CNT_tel_code' => '+1', |
|
977 | + 'CNT_is_EU' => false, |
|
978 | + 'CNT_active' => true, |
|
979 | + ); |
|
980 | + $data_types = array( |
|
981 | + '%s',// CNT_ISO |
|
982 | + '%s',// CNT_ISO3 |
|
983 | + '%d',// RGN_ID |
|
984 | + '%s',// CNT_name |
|
985 | + '%s',// CNT_cur_code |
|
986 | + '%s',// CNT_cur_single |
|
987 | + '%s',// CNT_cur_plural |
|
988 | + '%s',// CNT_cur_sign |
|
989 | + '%d',// CNT_cur_sign_b4 |
|
990 | + '%d',// CNT_cur_dec_plc |
|
991 | + '%s',// CNT_cur_dec_mrk |
|
992 | + '%s',// CNT_cur_thsnds |
|
993 | + '%s',// CNT_tel_code |
|
994 | + '%d',// CNT_is_EU |
|
995 | + '%d',// CNT_active |
|
996 | + ); |
|
997 | + $success = $wpdb->insert( |
|
998 | + $country_table, |
|
999 | + $cols_n_values, |
|
1000 | + $data_types |
|
1001 | + ); |
|
1002 | + if (! $success) { |
|
1003 | + throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
1004 | + 'N/A', |
|
1005 | + array('country_id' => $country_name), |
|
1006 | + $country_table, |
|
1007 | + $cols_n_values, |
|
1008 | + $data_types |
|
1009 | + )); |
|
1010 | + } |
|
1011 | + $country = $cols_n_values; |
|
1012 | + } |
|
1013 | + return $country; |
|
1014 | + } |
|
1015 | + |
|
1016 | + |
|
1017 | + |
|
1018 | + /** |
|
1019 | + * finds a country iso which hasnt been used yet |
|
1020 | + * |
|
1021 | + * @global type $wpdb |
|
1022 | + * @return string |
|
1023 | + */ |
|
1024 | + private function _find_available_country_iso($num_letters = 2) |
|
1025 | + { |
|
1026 | + global $wpdb; |
|
1027 | + $country_table = $wpdb->prefix . "esp_country"; |
|
1028 | + $attempts = 0; |
|
1029 | + do { |
|
1030 | + $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
|
1031 | + $country_with_that_iso = $wpdb->get_var($wpdb->prepare("SELECT count(CNT_ISO) FROM " |
|
1032 | + . $country_table |
|
1033 | + . " WHERE CNT_ISO=%s", $current_iso)); |
|
1034 | + $attempts++; |
|
1035 | + // keep going until we find an available country code, or we arbitrarily |
|
1036 | + // decide we've tried this enough. Somehow they have way too many countries |
|
1037 | + // (probably because they're mis-using the EE3 country_id like a custom question) |
|
1038 | + } while (intval($country_with_that_iso) && $attempts < 200); |
|
1039 | + return $current_iso; |
|
1040 | + } |
|
1041 | + |
|
1042 | + |
|
1043 | + |
|
1044 | + /** |
|
1045 | + * Gets a state entry as an array, or creates one if none is found. Much like EEM_State::instance()->get_one(), but |
|
1046 | + * is independent of outside code which can change in future versions of EE |
|
1047 | + * |
|
1048 | + * @global type $wpdb |
|
1049 | + * @param string $state_name |
|
1050 | + * @return array where keys are columns, values are column values |
|
1051 | + */ |
|
1052 | + public function get_or_create_state($state_name, $country_name = '') |
|
1053 | + { |
|
1054 | + if (! $state_name) { |
|
1055 | + throw new EE_Error(esc_html__( |
|
1056 | + "Could not get-or-create state because no state name was provided", |
|
1057 | + "event_espresso" |
|
1058 | + )); |
|
1059 | + } |
|
1060 | + try { |
|
1061 | + $country = $this->get_or_create_country($country_name); |
|
1062 | + $country_iso = $country['CNT_ISO']; |
|
1063 | + } catch (EE_Error $e) { |
|
1064 | + $country_iso = $this->get_default_country_iso(); |
|
1065 | + } |
|
1066 | + global $wpdb; |
|
1067 | + $state_table = $wpdb->prefix . "esp_state"; |
|
1068 | + $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
|
1069 | 1069 | (STA_abbrev LIKE %s OR |
1070 | 1070 | STA_name LIKE %s) AND |
1071 | 1071 | CNT_ISO LIKE %s LIMIT 1", $state_name, $state_name, $country_iso), ARRAY_A); |
1072 | - if (! $state) { |
|
1073 | - // insert a new one then |
|
1074 | - $cols_n_values = array( |
|
1075 | - 'CNT_ISO' => $country_iso, |
|
1076 | - 'STA_abbrev' => substr($state_name, 0, 6), |
|
1077 | - 'STA_name' => $state_name, |
|
1078 | - 'STA_active' => true, |
|
1079 | - ); |
|
1080 | - $data_types = array( |
|
1081 | - '%s',// CNT_ISO |
|
1082 | - '%s',// STA_abbrev |
|
1083 | - '%s',// STA_name |
|
1084 | - '%d',// STA_active |
|
1085 | - ); |
|
1086 | - $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
|
1087 | - if (! $success) { |
|
1088 | - throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
1089 | - 'N/A', |
|
1090 | - array('state' => $state_name, 'country_id' => $country_name), |
|
1091 | - $state_table, |
|
1092 | - $cols_n_values, |
|
1093 | - $data_types |
|
1094 | - )); |
|
1095 | - } |
|
1096 | - $state = $cols_n_values; |
|
1097 | - $state['STA_ID'] = $wpdb->insert_id; |
|
1098 | - } |
|
1099 | - return $state; |
|
1100 | - } |
|
1101 | - |
|
1102 | - |
|
1103 | - |
|
1104 | - /** |
|
1105 | - * Fixes times like "5:00 PM" into the expected 24-hour format "17:00". |
|
1106 | - * THis is actually just copied from the 3.1 JSON API because it needed to do the exact same thing |
|
1107 | - * |
|
1108 | - * @param type $timeString |
|
1109 | - * @return string in the php DATETIME format: "G:i" (24-hour format hour with leading zeros, a colon, and minutes |
|
1110 | - * with leading zeros) |
|
1111 | - */ |
|
1112 | - public function convertTimeFromAMPM($timeString) |
|
1113 | - { |
|
1114 | - $matches = array(); |
|
1115 | - preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
|
1116 | - if (! $matches || count($matches) < 3) { |
|
1117 | - $hour = '00'; |
|
1118 | - $minutes = '00'; |
|
1119 | - } else { |
|
1120 | - $hour = intval($matches[1]); |
|
1121 | - $minutes = $matches[2]; |
|
1122 | - } |
|
1123 | - if (strpos($timeString, 'PM') || strpos($timeString, 'pm')) { |
|
1124 | - $hour = intval($hour) + 12; |
|
1125 | - } |
|
1126 | - $hour = str_pad("$hour", 2, '0', STR_PAD_LEFT); |
|
1127 | - $minutes = str_pad("$minutes", 2, '0', STR_PAD_LEFT); |
|
1128 | - return "$hour:$minutes"; |
|
1129 | - } |
|
1130 | - |
|
1131 | - |
|
1132 | - |
|
1133 | - /** |
|
1134 | - * Gets the ISO3 fora country given its 3.1 country ID. |
|
1135 | - * |
|
1136 | - * @param int $country_id |
|
1137 | - * @return string the country's ISO3 code |
|
1138 | - */ |
|
1139 | - public function get_iso_from_3_1_country_id($country_id) |
|
1140 | - { |
|
1141 | - $old_countries = array( |
|
1142 | - array(64, 'United States', 'US', 'USA', 1), |
|
1143 | - array(15, 'Australia', 'AU', 'AUS', 1), |
|
1144 | - array(39, 'Canada', 'CA', 'CAN', 1), |
|
1145 | - array(171, 'United Kingdom', 'GB', 'GBR', 1), |
|
1146 | - array(70, 'France', 'FR', 'FRA', 2), |
|
1147 | - array(111, 'Italy', 'IT', 'ITA', 2), |
|
1148 | - array(63, 'Spain', 'ES', 'ESP', 2), |
|
1149 | - array(1, 'Afghanistan', 'AF', 'AFG', 1), |
|
1150 | - array(2, 'Albania', 'AL', 'ALB', 1), |
|
1151 | - array(3, 'Germany', 'DE', 'DEU', 2), |
|
1152 | - array(198, 'Switzerland', 'CH', 'CHE', 1), |
|
1153 | - array(87, 'Netherlands', 'NL', 'NLD', 2), |
|
1154 | - array(197, 'Sweden', 'SE', 'SWE', 1), |
|
1155 | - array(230, 'Akrotiri and Dhekelia', 'CY', 'CYP', 2), |
|
1156 | - array(4, 'Andorra', 'AD', 'AND', 2), |
|
1157 | - array(5, 'Angola', 'AO', 'AGO', 1), |
|
1158 | - array(6, 'Anguilla', 'AI', 'AIA', 1), |
|
1159 | - array(7, 'Antarctica', 'AQ', 'ATA', 1), |
|
1160 | - array(8, 'Antigua and Barbuda', 'AG', 'ATG', 1), |
|
1161 | - array(10, 'Saudi Arabia', 'SA', 'SAU', 1), |
|
1162 | - array(11, 'Algeria', 'DZ', 'DZA', 1), |
|
1163 | - array(12, 'Argentina', 'AR', 'ARG', 1), |
|
1164 | - array(13, 'Armenia', 'AM', 'ARM', 1), |
|
1165 | - array(14, 'Aruba', 'AW', 'ABW', 1), |
|
1166 | - array(16, 'Austria', 'AT', 'AUT', 2), |
|
1167 | - array(17, 'Azerbaijan', 'AZ', 'AZE', 1), |
|
1168 | - array(18, 'Bahamas', 'BS', 'BHS', 1), |
|
1169 | - array(19, 'Bahrain', 'BH', 'BHR', 1), |
|
1170 | - array(20, 'Bangladesh', 'BD', 'BGD', 1), |
|
1171 | - array(21, 'Barbados', 'BB', 'BRB', 1), |
|
1172 | - array(22, 'Belgium ', 'BE', 'BEL', 2), |
|
1173 | - array(23, 'Belize', 'BZ', 'BLZ', 1), |
|
1174 | - array(24, 'Benin', 'BJ', 'BEN', 1), |
|
1175 | - array(25, 'Bermudas', 'BM', 'BMU', 1), |
|
1176 | - array(26, 'Belarus', 'BY', 'BLR', 1), |
|
1177 | - array(27, 'Bolivia', 'BO', 'BOL', 1), |
|
1178 | - array(28, 'Bosnia and Herzegovina', 'BA', 'BIH', 1), |
|
1179 | - array(29, 'Botswana', 'BW', 'BWA', 1), |
|
1180 | - array(96, 'Bouvet Island', 'BV', 'BVT', 1), |
|
1181 | - array(30, 'Brazil', 'BR', 'BRA', 1), |
|
1182 | - array(31, 'Brunei', 'BN', 'BRN', 1), |
|
1183 | - array(32, 'Bulgaria', 'BG', 'BGR', 1), |
|
1184 | - array(33, 'Burkina Faso', 'BF', 'BFA', 1), |
|
1185 | - array(34, 'Burundi', 'BI', 'BDI', 1), |
|
1186 | - array(35, 'Bhutan', 'BT', 'BTN', 1), |
|
1187 | - array(36, 'Cape Verde', 'CV', 'CPV', 1), |
|
1188 | - array(37, 'Cambodia', 'KH', 'KHM', 1), |
|
1189 | - array(38, 'Cameroon', 'CM', 'CMR', 1), |
|
1190 | - array(98, 'Cayman Islands', 'KY', 'CYM', 1), |
|
1191 | - array(172, 'Central African Republic', 'CF', 'CAF', 1), |
|
1192 | - array(40, 'Chad', 'TD', 'TCD', 1), |
|
1193 | - array(41, 'Chile', 'CL', 'CHL', 1), |
|
1194 | - array(42, 'China', 'CN', 'CHN', 1), |
|
1195 | - array(105, 'Christmas Island', 'CX', 'CXR', 1), |
|
1196 | - array(43, 'Cyprus', 'CY', 'CYP', 2), |
|
1197 | - array(99, 'Cocos Island', 'CC', 'CCK', 1), |
|
1198 | - array(100, 'Cook Islands', 'CK', 'COK', 1), |
|
1199 | - array(44, 'Colombia', 'CO', 'COL', 1), |
|
1200 | - array(45, 'Comoros', 'KM', 'COM', 1), |
|
1201 | - array(46, 'Congo', 'CG', 'COG', 1), |
|
1202 | - array(47, 'North Korea', 'KP', 'PRK', 1), |
|
1203 | - array(50, 'Costa Rica', 'CR', 'CRI', 1), |
|
1204 | - array(51, 'Croatia', 'HR', 'HRV', 1), |
|
1205 | - array(52, 'Cuba', 'CU', 'CUB', 1), |
|
1206 | - array(173, 'Czech Republic', 'CZ', 'CZE', 1), |
|
1207 | - array(53, 'Denmark', 'DK', 'DNK', 1), |
|
1208 | - array(54, 'Djibouti', 'DJ', 'DJI', 1), |
|
1209 | - array(55, 'Dominica', 'DM', 'DMA', 1), |
|
1210 | - array(174, 'Dominican Republic', 'DO', 'DOM', 1), |
|
1211 | - array(56, 'Ecuador', 'EC', 'ECU', 1), |
|
1212 | - array(57, 'Egypt', 'EG', 'EGY', 1), |
|
1213 | - array(58, 'El Salvador', 'SV', 'SLV', 1), |
|
1214 | - array(60, 'Eritrea', 'ER', 'ERI', 1), |
|
1215 | - array(61, 'Slovakia', 'SK', 'SVK', 2), |
|
1216 | - array(62, 'Slovenia', 'SI', 'SVN', 2), |
|
1217 | - array(65, 'Estonia', 'EE', 'EST', 2), |
|
1218 | - array(66, 'Ethiopia', 'ET', 'ETH', 1), |
|
1219 | - array(102, 'Faroe islands', 'FO', 'FRO', 1), |
|
1220 | - array(103, 'Falkland Islands', 'FK', 'FLK', 1), |
|
1221 | - array(67, 'Fiji', 'FJ', 'FJI', 1), |
|
1222 | - array(69, 'Finland', 'FI', 'FIN', 2), |
|
1223 | - array(71, 'Gabon', 'GA', 'GAB', 1), |
|
1224 | - array(72, 'Gambia', 'GM', 'GMB', 1), |
|
1225 | - array(73, 'Georgia', 'GE', 'GEO', 1), |
|
1226 | - array(74, 'Ghana', 'GH', 'GHA', 1), |
|
1227 | - array(75, 'Gibraltar', 'GI', 'GIB', 1), |
|
1228 | - array(76, 'Greece', 'GR', 'GRC', 2), |
|
1229 | - array(77, 'Grenada', 'GD', 'GRD', 1), |
|
1230 | - array(78, 'Greenland', 'GL', 'GRL', 1), |
|
1231 | - array(79, 'Guadeloupe', 'GP', 'GLP', 1), |
|
1232 | - array(80, 'Guam', 'GU', 'GUM', 1), |
|
1233 | - array(81, 'Guatemala', 'GT', 'GTM', 1), |
|
1234 | - array(82, 'Guinea', 'GN', 'GIN', 1), |
|
1235 | - array(83, 'Equatorial Guinea', 'GQ', 'GNQ', 1), |
|
1236 | - array(84, 'Guinea-Bissau', 'GW', 'GNB', 1), |
|
1237 | - array(85, 'Guyana', 'GY', 'GUY', 1), |
|
1238 | - array(86, 'Haiti', 'HT', 'HTI', 1), |
|
1239 | - array(88, 'Honduras', 'HN', 'HND', 1), |
|
1240 | - array(89, 'Hong Kong', 'HK', 'HKG', 1), |
|
1241 | - array(90, 'Hungary', 'HU', 'HUN', 1), |
|
1242 | - array(91, 'India', 'IN', 'IND', 1), |
|
1243 | - array(205, 'British Indian Ocean Territory', 'IO', 'IOT', 1), |
|
1244 | - array(92, 'Indonesia', 'ID', 'IDN', 1), |
|
1245 | - array(93, 'Iraq', 'IQ', 'IRQ', 1), |
|
1246 | - array(94, 'Iran', 'IR', 'IRN', 1), |
|
1247 | - array(95, 'Ireland', 'IE', 'IRL', 2), |
|
1248 | - array(97, 'Iceland', 'IS', 'ISL', 1), |
|
1249 | - array(110, 'Israel', 'IL', 'ISR', 1), |
|
1250 | - array(49, 'Ivory Coast ', 'CI', 'CIV', 1), |
|
1251 | - array(112, 'Jamaica', 'JM', 'JAM', 1), |
|
1252 | - array(113, 'Japan', 'JP', 'JPN', 1), |
|
1253 | - array(114, 'Jordan', 'JO', 'JOR', 1), |
|
1254 | - array(115, 'Kazakhstan', 'KZ', 'KAZ', 1), |
|
1255 | - array(116, 'Kenya', 'KE', 'KEN', 1), |
|
1256 | - array(117, 'Kyrgyzstan', 'KG', 'KGZ', 1), |
|
1257 | - array(118, 'Kiribati', 'KI', 'KIR', 1), |
|
1258 | - array(48, 'South Korea', 'KR', 'KOR', 1), |
|
1259 | - array(228, 'Kosovo', 'XK', 'XKV', 2), |
|
1260 | - // there is no official ISO code for Kosovo yet (http://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/) so using a temporary country code and a modified 3 character code for ISO code -- this should be updated if/when Kosovo gets its own ISO code |
|
1261 | - array(119, 'Kuwait', 'KW', 'KWT', 1), |
|
1262 | - array(120, 'Laos', 'LA', 'LAO', 1), |
|
1263 | - array(121, 'Latvia', 'LV', 'LVA', 2), |
|
1264 | - array(122, 'Lesotho', 'LS', 'LSO', 1), |
|
1265 | - array(123, 'Lebanon', 'LB', 'LBN', 1), |
|
1266 | - array(124, 'Liberia', 'LR', 'LBR', 1), |
|
1267 | - array(125, 'Libya', 'LY', 'LBY', 1), |
|
1268 | - array(126, 'Liechtenstein', 'LI', 'LIE', 1), |
|
1269 | - array(127, 'Lithuania', 'LT', 'LTU', 2), |
|
1270 | - array(128, 'Luxemburg', 'LU', 'LUX', 2), |
|
1271 | - array(129, 'Macao', 'MO', 'MAC', 1), |
|
1272 | - array(130, 'Macedonia', 'MK', 'MKD', 1), |
|
1273 | - array(131, 'Madagascar', 'MG', 'MDG', 1), |
|
1274 | - array(132, 'Malaysia', 'MY', 'MYS', 1), |
|
1275 | - array(133, 'Malawi', 'MW', 'MWI', 1), |
|
1276 | - array(134, 'Maldivas', 'MV', 'MDV', 1), |
|
1277 | - array(135, 'Mali', 'ML', 'MLI', 1), |
|
1278 | - array(136, 'Malta', 'MT', 'MLT', 2), |
|
1279 | - array(101, 'Northern Marianas', 'MP', 'MNP', 1), |
|
1280 | - array(137, 'Morocco', 'MA', 'MAR', 1), |
|
1281 | - array(104, 'Marshall islands', 'MH', 'MHL', 1), |
|
1282 | - array(138, 'Martinique', 'MQ', 'MTQ', 1), |
|
1283 | - array(139, 'Mauritius', 'MU', 'MUS', 1), |
|
1284 | - array(140, 'Mauritania', 'MR', 'MRT', 1), |
|
1285 | - array(141, 'Mayote', 'YT', 'MYT', 2), |
|
1286 | - array(142, 'Mexico', 'MX', 'MEX', 1), |
|
1287 | - array(143, 'Micronesia', 'FM', 'FSM', 1), |
|
1288 | - array(144, 'Moldova', 'MD', 'MDA', 1), |
|
1289 | - array(145, 'Monaco', 'MC', 'MCO', 2), |
|
1290 | - array(146, 'Mongolia', 'MN', 'MNG', 1), |
|
1291 | - array(147, 'Montserrat', 'MS', 'MSR', 1), |
|
1292 | - array(227, 'Montenegro', 'ME', 'MNE', 2), |
|
1293 | - array(148, 'Mozambique', 'MZ', 'MOZ', 1), |
|
1294 | - array(149, 'Myanmar', 'MM', 'MMR', 1), |
|
1295 | - array(150, 'Namibia', 'NA', 'NAM', 1), |
|
1296 | - array(151, 'Nauru', 'NR', 'NRU', 1), |
|
1297 | - array(152, 'Nepal', 'NP', 'NPL', 1), |
|
1298 | - array(9, 'Netherlands Antilles', 'AN', 'ANT', 1), |
|
1299 | - array(153, 'Nicaragua', 'NI', 'NIC', 1), |
|
1300 | - array(154, 'Niger', 'NE', 'NER', 1), |
|
1301 | - array(155, 'Nigeria', 'NG', 'NGA', 1), |
|
1302 | - array(156, 'Niue', 'NU', 'NIU', 1), |
|
1303 | - array(157, 'Norway', 'NO', 'NOR', 1), |
|
1304 | - array(158, 'New Caledonia', 'NC', 'NCL', 1), |
|
1305 | - array(159, 'New Zealand', 'NZ', 'NZL', 1), |
|
1306 | - array(160, 'Oman', 'OM', 'OMN', 1), |
|
1307 | - array(161, 'Pakistan', 'PK', 'PAK', 1), |
|
1308 | - array(162, 'Palau', 'PW', 'PLW', 1), |
|
1309 | - array(163, 'Panama', 'PA', 'PAN', 1), |
|
1310 | - array(164, 'Papua New Guinea', 'PG', 'PNG', 1), |
|
1311 | - array(165, 'Paraguay', 'PY', 'PRY', 1), |
|
1312 | - array(166, 'Peru', 'PE', 'PER', 1), |
|
1313 | - array(68, 'Philippines', 'PH', 'PHL', 1), |
|
1314 | - array(167, 'Poland', 'PL', 'POL', 1), |
|
1315 | - array(168, 'Portugal', 'PT', 'PRT', 2), |
|
1316 | - array(169, 'Puerto Rico', 'PR', 'PRI', 1), |
|
1317 | - array(170, 'Qatar', 'QA', 'QAT', 1), |
|
1318 | - array(176, 'Rwanda', 'RW', 'RWA', 1), |
|
1319 | - array(177, 'Romania', 'RO', 'ROM', 2), |
|
1320 | - array(178, 'Russia', 'RU', 'RUS', 1), |
|
1321 | - array(229, 'Saint Pierre and Miquelon', 'PM', 'SPM', 2), |
|
1322 | - array(180, 'Samoa', 'WS', 'WSM', 1), |
|
1323 | - array(181, 'American Samoa', 'AS', 'ASM', 1), |
|
1324 | - array(183, 'San Marino', 'SM', 'SMR', 2), |
|
1325 | - array(184, 'Saint Vincent and the Grenadines', 'VC', 'VCT', 1), |
|
1326 | - array(185, 'Saint Helena', 'SH', 'SHN', 1), |
|
1327 | - array(186, 'Saint Lucia', 'LC', 'LCA', 1), |
|
1328 | - array(188, 'Senegal', 'SN', 'SEN', 1), |
|
1329 | - array(189, 'Seychelles', 'SC', 'SYC', 1), |
|
1330 | - array(190, 'Sierra Leona', 'SL', 'SLE', 1), |
|
1331 | - array(191, 'Singapore', 'SG', 'SGP', 1), |
|
1332 | - array(192, 'Syria', 'SY', 'SYR', 1), |
|
1333 | - array(193, 'Somalia', 'SO', 'SOM', 1), |
|
1334 | - array(194, 'Sri Lanka', 'LK', 'LKA', 1), |
|
1335 | - array(195, 'South Africa', 'ZA', 'ZAF', 1), |
|
1336 | - array(196, 'Sudan', 'SD', 'SDN', 1), |
|
1337 | - array(199, 'Suriname', 'SR', 'SUR', 1), |
|
1338 | - array(200, 'Swaziland', 'SZ', 'SWZ', 1), |
|
1339 | - array(201, 'Thailand', 'TH', 'THA', 1), |
|
1340 | - array(202, 'Taiwan', 'TW', 'TWN', 1), |
|
1341 | - array(203, 'Tanzania', 'TZ', 'TZA', 1), |
|
1342 | - array(204, 'Tajikistan', 'TJ', 'TJK', 1), |
|
1343 | - array(206, 'Timor-Leste', 'TL', 'TLS', 1), |
|
1344 | - array(207, 'Togo', 'TG', 'TGO', 1), |
|
1345 | - array(208, 'Tokelau', 'TK', 'TKL', 1), |
|
1346 | - array(209, 'Tonga', 'TO', 'TON', 1), |
|
1347 | - array(210, 'Trinidad and Tobago', 'TT', 'TTO', 1), |
|
1348 | - array(211, 'Tunisia', 'TN', 'TUN', 1), |
|
1349 | - array(212, 'Turkmenistan', 'TM', 'TKM', 1), |
|
1350 | - array(213, 'Turkey', 'TR', 'TUR', 1), |
|
1351 | - array(214, 'Tuvalu', 'TV', 'TUV', 1), |
|
1352 | - array(215, 'Ukraine', 'UA', 'UKR', 1), |
|
1353 | - array(216, 'Uganda', 'UG', 'UGA', 1), |
|
1354 | - array(59, 'United Arab Emirates', 'AE', 'ARE', 1), |
|
1355 | - array(217, 'Uruguay', 'UY', 'URY', 1), |
|
1356 | - array(218, 'Uzbekistan', 'UZ', 'UZB', 1), |
|
1357 | - array(219, 'Vanuatu', 'VU', 'VUT', 1), |
|
1358 | - array(220, 'Vatican City', 'VA', 'VAT', 2), |
|
1359 | - array(221, 'Venezuela', 'VE', 'VEN', 1), |
|
1360 | - array(222, 'Vietnam', 'VN', 'VNM', 1), |
|
1361 | - array(108, 'Virgin Islands', 'VI', 'VIR', 1), |
|
1362 | - array(223, 'Yemen', 'YE', 'YEM', 1), |
|
1363 | - array(225, 'Zambia', 'ZM', 'ZMB', 1), |
|
1364 | - array(226, 'Zimbabwe', 'ZW', 'ZWE', 1), |
|
1365 | - ); |
|
1366 | - $country_iso = 'US'; |
|
1367 | - foreach ($old_countries as $country_array) { |
|
1368 | - // note: index 0 is the 3.1 country ID |
|
1369 | - if ($country_array[0] == $country_id) { |
|
1370 | - // note: index 2 is the ISO |
|
1371 | - $country_iso = $country_array[2]; |
|
1372 | - break; |
|
1373 | - } |
|
1374 | - } |
|
1375 | - return $country_iso; |
|
1376 | - } |
|
1377 | - |
|
1378 | - |
|
1379 | - |
|
1380 | - /** |
|
1381 | - * Gets the ISO3 for the |
|
1382 | - * |
|
1383 | - * @return string |
|
1384 | - */ |
|
1385 | - public function get_default_country_iso() |
|
1386 | - { |
|
1387 | - $old_org_options = get_option('events_organization_settings'); |
|
1388 | - $iso = $this->get_iso_from_3_1_country_id($old_org_options['organization_country']); |
|
1389 | - return $iso; |
|
1390 | - } |
|
1391 | - |
|
1392 | - |
|
1393 | - |
|
1394 | - /** |
|
1395 | - * Converst a 3.1 payment status to its equivalent 4.1 regisration status |
|
1396 | - * |
|
1397 | - * @param string $payment_status possible value for 3.1's evens_attendee.payment_status |
|
1398 | - * @param boolean $this_thing_required_pre_approval whether the thing we're considering (the general setting's |
|
1399 | - * DEFAULT payment status, the event's DEFAULT payment status, or |
|
1400 | - * the attendee's payment status) required pre-approval. |
|
1401 | - * @return string STS_ID for use in 4.1 |
|
1402 | - */ |
|
1403 | - public function convert_3_1_payment_status_to_4_1_STS_ID($payment_status, $this_thing_required_pre_approval = false) |
|
1404 | - { |
|
1405 | - // EE team can read the related discussion: https://app.asana.com/0/2400967562914/9418495544455 |
|
1406 | - if ($this_thing_required_pre_approval) { |
|
1407 | - return 'RNA'; |
|
1408 | - } else { |
|
1409 | - $mapping = $default_reg_stati_conversions = array( |
|
1410 | - 'Completed' => 'RAP', |
|
1411 | - '' => 'RPP', |
|
1412 | - 'Incomplete' => 'RPP', |
|
1413 | - 'Pending' => 'RAP', |
|
1414 | - // stati that only occurred on 3.1 attendees: |
|
1415 | - 'Payment Declined' => 'RPP', |
|
1416 | - 'Not Completed' => 'RPP', |
|
1417 | - 'Cancelled' => 'RPP', |
|
1418 | - 'Declined' => 'RPP', |
|
1419 | - ); |
|
1420 | - } |
|
1421 | - return isset($mapping[ $payment_status ]) ? $mapping[ $payment_status ] : 'RNA'; |
|
1422 | - } |
|
1423 | - |
|
1424 | - |
|
1425 | - |
|
1426 | - /** |
|
1427 | - * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
|
1428 | - * and sets it as the featured image on the CPT event |
|
1429 | - * |
|
1430 | - * @param type $old_event |
|
1431 | - * @param type $new_cpt_id |
|
1432 | - * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
|
1433 | - * @return boolean whether or not we had to do the big job of creating an image attachment |
|
1434 | - */ |
|
1435 | - public function convert_image_url_to_attachment_and_attach_to_post( |
|
1436 | - $guid, |
|
1437 | - $new_cpt_id, |
|
1438 | - EE_Data_Migration_Script_Stage $migration_stage |
|
1439 | - ) { |
|
1440 | - $created_attachment_post = false; |
|
1441 | - $guid = $this->_get_original_guid($guid); |
|
1442 | - if ($guid) { |
|
1443 | - // check for an existing attachment post with this guid |
|
1444 | - $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
|
1445 | - if (! $attachment_post_id) { |
|
1446 | - // post thumbnail with that GUID doesn't exist, we should create one |
|
1447 | - $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
|
1448 | - $created_attachment_post = true; |
|
1449 | - } |
|
1450 | - // double-check we actually have an attachment post |
|
1451 | - if ($attachment_post_id) { |
|
1452 | - update_post_meta($new_cpt_id, '_thumbnail_id', $attachment_post_id); |
|
1453 | - } else { |
|
1454 | - $migration_stage->add_error(sprintf(esc_html__( |
|
1455 | - "Could not update event image %s for CPT with ID %d, but attachments post ID is %d", |
|
1456 | - "event_espresso" |
|
1457 | - ), $guid, $new_cpt_id, $attachment_post_id)); |
|
1458 | - } |
|
1459 | - } |
|
1460 | - return $created_attachment_post; |
|
1461 | - } |
|
1462 | - |
|
1463 | - |
|
1464 | - |
|
1465 | - /** |
|
1466 | - * In 3.1, the event thumbnail image DOESN'T point to the orignal image, but instead |
|
1467 | - * to a large thumbnail (which has nearly the same GUID, except it adds "-{width}x{height}" before the filetype, |
|
1468 | - * or whatever dimensions it is. Eg 'http://mysite.com/image1-300x400.jpg' instead of |
|
1469 | - * 'http://mysite.com/image1.jpg' ). This function attempts to strip that off and get the original file, if it |
|
1470 | - * exists |
|
1471 | - * |
|
1472 | - * @param string $guid_in_old_event |
|
1473 | - * @return string either the original guid, or $guid_in_old_event if we couldn't figure out what the original was |
|
1474 | - */ |
|
1475 | - private function _get_original_guid($guid_in_old_event) |
|
1476 | - { |
|
1477 | - $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
|
1478 | - // do a head request to verify the file exists |
|
1479 | - $head_response = wp_remote_head($original_guid); |
|
1480 | - if (! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
1481 | - return $original_guid; |
|
1482 | - } else { |
|
1483 | - return $guid_in_old_event; |
|
1484 | - } |
|
1485 | - } |
|
1486 | - |
|
1487 | - |
|
1488 | - |
|
1489 | - /** |
|
1490 | - * Creates an image attachment post for the GUID. If the GUID points to a remote image, |
|
1491 | - * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
|
1492 | - * thumbnails) |
|
1493 | - * |
|
1494 | - * @param type $guid |
|
1495 | - * @param EE_Data_Migration_Script_Stage $migration_stage |
|
1496 | - * @return int |
|
1497 | - */ |
|
1498 | - private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
|
1499 | - { |
|
1500 | - if (! $guid) { |
|
1501 | - $migration_stage->add_error(sprintf(esc_html__( |
|
1502 | - "Cannot create image attachment for a blank GUID!", |
|
1503 | - "event_espresso" |
|
1504 | - ))); |
|
1505 | - return 0; |
|
1506 | - } |
|
1507 | - $wp_filetype = wp_check_filetype(basename($guid), null); |
|
1508 | - $wp_upload_dir = wp_upload_dir(); |
|
1509 | - // if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
|
1510 | - if (strpos($guid, $wp_upload_dir['url']) === false) { |
|
1511 | - // image is located remotely. download it and place it in the uploads directory |
|
1512 | - if (! is_readable($guid)) { |
|
1513 | - $migration_stage->add_error(sprintf(esc_html__( |
|
1514 | - "Could not create image attachment from non-existent file: %s", |
|
1515 | - "event_espresso" |
|
1516 | - ), $guid)); |
|
1517 | - return 0; |
|
1518 | - } |
|
1519 | - $contents = file_get_contents($guid); |
|
1520 | - if ($contents === false) { |
|
1521 | - $migration_stage->add_error(sprintf(esc_html__( |
|
1522 | - "Could not read image at %s, and therefore couldnt create an attachment post for it.", |
|
1523 | - "event_espresso" |
|
1524 | - ), $guid)); |
|
1525 | - return false; |
|
1526 | - } |
|
1527 | - $local_filepath = $wp_upload_dir['path'] . DS . basename($guid); |
|
1528 | - $savefile = fopen($local_filepath, 'w'); |
|
1529 | - fwrite($savefile, $contents); |
|
1530 | - fclose($savefile); |
|
1531 | - $guid = str_replace($wp_upload_dir['path'], $wp_upload_dir['url'], $local_filepath); |
|
1532 | - } else { |
|
1533 | - $local_filepath = str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $guid); |
|
1534 | - } |
|
1535 | - $attachment = array( |
|
1536 | - 'guid' => $guid, |
|
1537 | - 'post_mime_type' => $wp_filetype['type'], |
|
1538 | - 'post_title' => preg_replace('/\.[^.]+$/', '', basename($guid)), |
|
1539 | - 'post_content' => '', |
|
1540 | - 'post_status' => 'inherit', |
|
1541 | - ); |
|
1542 | - $attach_id = wp_insert_attachment($attachment, $guid); |
|
1543 | - if (! $attach_id) { |
|
1544 | - $migration_stage->add_error(sprintf(esc_html__( |
|
1545 | - "Could not create image attachment post from image '%s'. Attachment data was %s.", |
|
1546 | - "event_espresso" |
|
1547 | - ), $guid, $this->_json_encode($attachment))); |
|
1548 | - return $attach_id; |
|
1549 | - } |
|
1550 | - // you must first include the image.php file |
|
1551 | - // for the function wp_generate_attachment_metadata() to work |
|
1552 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
1553 | - $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
|
1554 | - if (! $attach_data) { |
|
1555 | - $migration_stage->add_error(sprintf(esc_html__( |
|
1556 | - "Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
|
1557 | - "event_espresso" |
|
1558 | - ), $attach_id, $local_filepath, $guid)); |
|
1559 | - return $attach_id; |
|
1560 | - } |
|
1561 | - $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
|
1562 | - if (! $metadata_save_result) { |
|
1563 | - $migration_stage->add_error(sprintf(esc_html__( |
|
1564 | - "Could not update attachment metadata for attachment %d with data %s", |
|
1565 | - "event_espresso" |
|
1566 | - ), $attach_id, $this->_json_encode($attach_data))); |
|
1567 | - } |
|
1568 | - return $attach_id; |
|
1569 | - } |
|
1570 | - |
|
1571 | - |
|
1572 | - |
|
1573 | - /** |
|
1574 | - * Finds the attachment post containing info about an image attachment given the GUID (link to the image itself), |
|
1575 | - * and returns its ID. |
|
1576 | - * |
|
1577 | - * @global type $wpdb |
|
1578 | - * @param string $guid |
|
1579 | - * @return int |
|
1580 | - */ |
|
1581 | - private function _get_image_attachment_id_by_GUID($guid) |
|
1582 | - { |
|
1583 | - global $wpdb; |
|
1584 | - $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid=%s LIMIT 1", $guid)); |
|
1585 | - return $attachment_id; |
|
1586 | - } |
|
1587 | - |
|
1588 | - |
|
1589 | - |
|
1590 | - /** |
|
1591 | - * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
|
1592 | - * (and optionally a timezone; if none is given, the wp DEFAULT is used) |
|
1593 | - * |
|
1594 | - * @param EE_Data_Migration_Script_base $stage |
|
1595 | - * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
|
1596 | - * UTC time for |
|
1597 | - * @param string $DATETIME_string |
|
1598 | - * @param string $timezone |
|
1599 | - * @return string |
|
1600 | - */ |
|
1601 | - public function convert_date_string_to_utc( |
|
1602 | - EE_Data_Migration_Script_Stage $stage, |
|
1603 | - $row_of_data, |
|
1604 | - $DATETIME_string, |
|
1605 | - $timezone = null |
|
1606 | - ) { |
|
1607 | - $original_tz = $timezone; |
|
1608 | - if (! $timezone) { |
|
1609 | - $timezone = $this->_get_wp_timezone(); |
|
1610 | - } |
|
1611 | - if (! $timezone) { |
|
1612 | - $stage->add_error(sprintf( |
|
1613 | - esc_html__("Could not find timezone given %s for %s", "event_espresso"), |
|
1614 | - $original_tz, |
|
1615 | - $row_of_data |
|
1616 | - )); |
|
1617 | - $timezone = 'UTC'; |
|
1618 | - } |
|
1619 | - try { |
|
1620 | - $date_obj = new DateTime($DATETIME_string, new DateTimeZone($timezone)); |
|
1621 | - EEH_DTT_Helper::setTimezone($date_obj, new DateTimeZone('UTC')); |
|
1622 | - } catch (Exception $e) { |
|
1623 | - $stage->add_error(sprintf(esc_html__( |
|
1624 | - "Could not convert time string '%s' using timezone '%s' into a proper DATETIME. Using current time instead.", |
|
1625 | - "event_espresso" |
|
1626 | - ), $DATETIME_string, $timezone)); |
|
1627 | - $date_obj = new DateTime(); |
|
1628 | - } |
|
1629 | - return $date_obj->format('Y-m-d H:i:s'); |
|
1630 | - } |
|
1631 | - |
|
1632 | - |
|
1633 | - |
|
1634 | - /** |
|
1635 | - * Gets the DEFAULT timezone string from wordpress (even if they set a gmt offset) |
|
1636 | - * |
|
1637 | - * @return string |
|
1638 | - */ |
|
1639 | - private function _get_wp_timezone() |
|
1640 | - { |
|
1641 | - $timezone = empty($timezone) ? get_option('timezone_string') : $timezone; |
|
1642 | - // if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter |
|
1643 | - if (empty($timezone)) { |
|
1644 | - // let's get a the WordPress UTC offset |
|
1645 | - $offset = get_option('gmt_offset'); |
|
1646 | - $timezone = $this->timezone_convert_to_string_from_offset($offset); |
|
1647 | - } |
|
1648 | - return $timezone; |
|
1649 | - } |
|
1650 | - |
|
1651 | - |
|
1652 | - |
|
1653 | - /** |
|
1654 | - * Gets the wordpress timezone string from a UTC offset |
|
1655 | - * |
|
1656 | - * @param int $offset |
|
1657 | - * @return boolean |
|
1658 | - */ |
|
1659 | - private function timezone_convert_to_string_from_offset($offset) |
|
1660 | - { |
|
1661 | - // shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did NOT work as expected - its not reliable |
|
1662 | - $offset *= 3600; // convert hour offset to seconds |
|
1663 | - $abbrarray = timezone_abbreviations_list(); |
|
1664 | - foreach ($abbrarray as $abbr) { |
|
1665 | - foreach ($abbr as $city) { |
|
1666 | - if ($city['offset'] == $offset) { |
|
1667 | - return $city['timezone_id']; |
|
1668 | - } |
|
1669 | - } |
|
1670 | - } |
|
1671 | - return false; |
|
1672 | - } |
|
1673 | - |
|
1674 | - |
|
1675 | - |
|
1676 | - public function migration_page_hooks() |
|
1677 | - { |
|
1678 | - add_filter( |
|
1679 | - 'FHEE__ee_migration_page__header', |
|
1680 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1681 | - 10, |
|
1682 | - 3 |
|
1683 | - ); |
|
1684 | - add_filter( |
|
1685 | - 'FHEE__ee_migration_page__p_after_header', |
|
1686 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1687 | - 10, |
|
1688 | - 2 |
|
1689 | - ); |
|
1690 | - add_filter( |
|
1691 | - 'FHEE__ee_migration_page__option_1_main', |
|
1692 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1693 | - 10, |
|
1694 | - 3 |
|
1695 | - ); |
|
1696 | - add_filter( |
|
1697 | - 'FHEE__ee_migration_page__option_1_button_text', |
|
1698 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1699 | - 10, |
|
1700 | - 3 |
|
1701 | - ); |
|
1702 | - add_action( |
|
1703 | - 'AHEE__ee_migration_page__option_1_extra_details', |
|
1704 | - array($this, '_migration_page_hook_option_1_extra_details'), |
|
1705 | - 10, |
|
1706 | - 3 |
|
1707 | - ); |
|
1708 | - add_filter( |
|
1709 | - 'FHEE__ee_migration_page__option_2_main', |
|
1710 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1711 | - 10, |
|
1712 | - 4 |
|
1713 | - ); |
|
1714 | - add_filter( |
|
1715 | - 'FHEE__ee_migration_page__option_2_button_text', |
|
1716 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1717 | - 10, |
|
1718 | - 2 |
|
1719 | - ); |
|
1720 | - add_filter( |
|
1721 | - 'FHEE__ee_migration_page__option_2_details', |
|
1722 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1723 | - 10, |
|
1724 | - 2 |
|
1725 | - ); |
|
1726 | - add_action( |
|
1727 | - 'AHEE__ee_migration_page__after_migration_options_table', |
|
1728 | - array($this, '_migration_page_hook_after_migration_options_table') |
|
1729 | - ); |
|
1730 | - add_filter( |
|
1731 | - 'FHEE__ee_migration_page__done_migration_header', |
|
1732 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1733 | - 10, |
|
1734 | - 2 |
|
1735 | - ); |
|
1736 | - add_filter( |
|
1737 | - 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
1738 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1739 | - 10, |
|
1740 | - 2 |
|
1741 | - ); |
|
1742 | - add_filter( |
|
1743 | - 'FHEE__ee_migration_page__migration_options_template', |
|
1744 | - array($this,'use_migration_options_from_ee3_template') |
|
1745 | - ); |
|
1746 | - } |
|
1747 | - |
|
1748 | - |
|
1749 | - |
|
1750 | - public function _migrate_page_hook_simplify_version_strings( |
|
1751 | - $old_content, |
|
1752 | - $current_db_state, |
|
1753 | - $next_db_state, |
|
1754 | - $ultimate_db_state = null |
|
1755 | - ) { |
|
1756 | - return str_replace( |
|
1757 | - array($current_db_state, $next_db_state, $ultimate_db_state), |
|
1758 | - array(esc_html__('EE3', 'event_espresso'), esc_html__('EE4', 'event_espresso'), esc_html__("EE4", 'event_espresso')), |
|
1759 | - $old_content |
|
1760 | - ); |
|
1761 | - } |
|
1762 | - |
|
1763 | - |
|
1764 | - |
|
1765 | - public function _migration_page_hook_simplify_next_db_state($old_content, $next_db_state) |
|
1766 | - { |
|
1767 | - return str_replace($next_db_state, esc_html__("EE4", 'event_espresso'), $old_content); |
|
1768 | - } |
|
1769 | - |
|
1770 | - |
|
1771 | - |
|
1772 | - public function _migration_page_hook_option_1_extra_details() |
|
1773 | - { |
|
1774 | - ?> |
|
1072 | + if (! $state) { |
|
1073 | + // insert a new one then |
|
1074 | + $cols_n_values = array( |
|
1075 | + 'CNT_ISO' => $country_iso, |
|
1076 | + 'STA_abbrev' => substr($state_name, 0, 6), |
|
1077 | + 'STA_name' => $state_name, |
|
1078 | + 'STA_active' => true, |
|
1079 | + ); |
|
1080 | + $data_types = array( |
|
1081 | + '%s',// CNT_ISO |
|
1082 | + '%s',// STA_abbrev |
|
1083 | + '%s',// STA_name |
|
1084 | + '%d',// STA_active |
|
1085 | + ); |
|
1086 | + $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
|
1087 | + if (! $success) { |
|
1088 | + throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
1089 | + 'N/A', |
|
1090 | + array('state' => $state_name, 'country_id' => $country_name), |
|
1091 | + $state_table, |
|
1092 | + $cols_n_values, |
|
1093 | + $data_types |
|
1094 | + )); |
|
1095 | + } |
|
1096 | + $state = $cols_n_values; |
|
1097 | + $state['STA_ID'] = $wpdb->insert_id; |
|
1098 | + } |
|
1099 | + return $state; |
|
1100 | + } |
|
1101 | + |
|
1102 | + |
|
1103 | + |
|
1104 | + /** |
|
1105 | + * Fixes times like "5:00 PM" into the expected 24-hour format "17:00". |
|
1106 | + * THis is actually just copied from the 3.1 JSON API because it needed to do the exact same thing |
|
1107 | + * |
|
1108 | + * @param type $timeString |
|
1109 | + * @return string in the php DATETIME format: "G:i" (24-hour format hour with leading zeros, a colon, and minutes |
|
1110 | + * with leading zeros) |
|
1111 | + */ |
|
1112 | + public function convertTimeFromAMPM($timeString) |
|
1113 | + { |
|
1114 | + $matches = array(); |
|
1115 | + preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
|
1116 | + if (! $matches || count($matches) < 3) { |
|
1117 | + $hour = '00'; |
|
1118 | + $minutes = '00'; |
|
1119 | + } else { |
|
1120 | + $hour = intval($matches[1]); |
|
1121 | + $minutes = $matches[2]; |
|
1122 | + } |
|
1123 | + if (strpos($timeString, 'PM') || strpos($timeString, 'pm')) { |
|
1124 | + $hour = intval($hour) + 12; |
|
1125 | + } |
|
1126 | + $hour = str_pad("$hour", 2, '0', STR_PAD_LEFT); |
|
1127 | + $minutes = str_pad("$minutes", 2, '0', STR_PAD_LEFT); |
|
1128 | + return "$hour:$minutes"; |
|
1129 | + } |
|
1130 | + |
|
1131 | + |
|
1132 | + |
|
1133 | + /** |
|
1134 | + * Gets the ISO3 fora country given its 3.1 country ID. |
|
1135 | + * |
|
1136 | + * @param int $country_id |
|
1137 | + * @return string the country's ISO3 code |
|
1138 | + */ |
|
1139 | + public function get_iso_from_3_1_country_id($country_id) |
|
1140 | + { |
|
1141 | + $old_countries = array( |
|
1142 | + array(64, 'United States', 'US', 'USA', 1), |
|
1143 | + array(15, 'Australia', 'AU', 'AUS', 1), |
|
1144 | + array(39, 'Canada', 'CA', 'CAN', 1), |
|
1145 | + array(171, 'United Kingdom', 'GB', 'GBR', 1), |
|
1146 | + array(70, 'France', 'FR', 'FRA', 2), |
|
1147 | + array(111, 'Italy', 'IT', 'ITA', 2), |
|
1148 | + array(63, 'Spain', 'ES', 'ESP', 2), |
|
1149 | + array(1, 'Afghanistan', 'AF', 'AFG', 1), |
|
1150 | + array(2, 'Albania', 'AL', 'ALB', 1), |
|
1151 | + array(3, 'Germany', 'DE', 'DEU', 2), |
|
1152 | + array(198, 'Switzerland', 'CH', 'CHE', 1), |
|
1153 | + array(87, 'Netherlands', 'NL', 'NLD', 2), |
|
1154 | + array(197, 'Sweden', 'SE', 'SWE', 1), |
|
1155 | + array(230, 'Akrotiri and Dhekelia', 'CY', 'CYP', 2), |
|
1156 | + array(4, 'Andorra', 'AD', 'AND', 2), |
|
1157 | + array(5, 'Angola', 'AO', 'AGO', 1), |
|
1158 | + array(6, 'Anguilla', 'AI', 'AIA', 1), |
|
1159 | + array(7, 'Antarctica', 'AQ', 'ATA', 1), |
|
1160 | + array(8, 'Antigua and Barbuda', 'AG', 'ATG', 1), |
|
1161 | + array(10, 'Saudi Arabia', 'SA', 'SAU', 1), |
|
1162 | + array(11, 'Algeria', 'DZ', 'DZA', 1), |
|
1163 | + array(12, 'Argentina', 'AR', 'ARG', 1), |
|
1164 | + array(13, 'Armenia', 'AM', 'ARM', 1), |
|
1165 | + array(14, 'Aruba', 'AW', 'ABW', 1), |
|
1166 | + array(16, 'Austria', 'AT', 'AUT', 2), |
|
1167 | + array(17, 'Azerbaijan', 'AZ', 'AZE', 1), |
|
1168 | + array(18, 'Bahamas', 'BS', 'BHS', 1), |
|
1169 | + array(19, 'Bahrain', 'BH', 'BHR', 1), |
|
1170 | + array(20, 'Bangladesh', 'BD', 'BGD', 1), |
|
1171 | + array(21, 'Barbados', 'BB', 'BRB', 1), |
|
1172 | + array(22, 'Belgium ', 'BE', 'BEL', 2), |
|
1173 | + array(23, 'Belize', 'BZ', 'BLZ', 1), |
|
1174 | + array(24, 'Benin', 'BJ', 'BEN', 1), |
|
1175 | + array(25, 'Bermudas', 'BM', 'BMU', 1), |
|
1176 | + array(26, 'Belarus', 'BY', 'BLR', 1), |
|
1177 | + array(27, 'Bolivia', 'BO', 'BOL', 1), |
|
1178 | + array(28, 'Bosnia and Herzegovina', 'BA', 'BIH', 1), |
|
1179 | + array(29, 'Botswana', 'BW', 'BWA', 1), |
|
1180 | + array(96, 'Bouvet Island', 'BV', 'BVT', 1), |
|
1181 | + array(30, 'Brazil', 'BR', 'BRA', 1), |
|
1182 | + array(31, 'Brunei', 'BN', 'BRN', 1), |
|
1183 | + array(32, 'Bulgaria', 'BG', 'BGR', 1), |
|
1184 | + array(33, 'Burkina Faso', 'BF', 'BFA', 1), |
|
1185 | + array(34, 'Burundi', 'BI', 'BDI', 1), |
|
1186 | + array(35, 'Bhutan', 'BT', 'BTN', 1), |
|
1187 | + array(36, 'Cape Verde', 'CV', 'CPV', 1), |
|
1188 | + array(37, 'Cambodia', 'KH', 'KHM', 1), |
|
1189 | + array(38, 'Cameroon', 'CM', 'CMR', 1), |
|
1190 | + array(98, 'Cayman Islands', 'KY', 'CYM', 1), |
|
1191 | + array(172, 'Central African Republic', 'CF', 'CAF', 1), |
|
1192 | + array(40, 'Chad', 'TD', 'TCD', 1), |
|
1193 | + array(41, 'Chile', 'CL', 'CHL', 1), |
|
1194 | + array(42, 'China', 'CN', 'CHN', 1), |
|
1195 | + array(105, 'Christmas Island', 'CX', 'CXR', 1), |
|
1196 | + array(43, 'Cyprus', 'CY', 'CYP', 2), |
|
1197 | + array(99, 'Cocos Island', 'CC', 'CCK', 1), |
|
1198 | + array(100, 'Cook Islands', 'CK', 'COK', 1), |
|
1199 | + array(44, 'Colombia', 'CO', 'COL', 1), |
|
1200 | + array(45, 'Comoros', 'KM', 'COM', 1), |
|
1201 | + array(46, 'Congo', 'CG', 'COG', 1), |
|
1202 | + array(47, 'North Korea', 'KP', 'PRK', 1), |
|
1203 | + array(50, 'Costa Rica', 'CR', 'CRI', 1), |
|
1204 | + array(51, 'Croatia', 'HR', 'HRV', 1), |
|
1205 | + array(52, 'Cuba', 'CU', 'CUB', 1), |
|
1206 | + array(173, 'Czech Republic', 'CZ', 'CZE', 1), |
|
1207 | + array(53, 'Denmark', 'DK', 'DNK', 1), |
|
1208 | + array(54, 'Djibouti', 'DJ', 'DJI', 1), |
|
1209 | + array(55, 'Dominica', 'DM', 'DMA', 1), |
|
1210 | + array(174, 'Dominican Republic', 'DO', 'DOM', 1), |
|
1211 | + array(56, 'Ecuador', 'EC', 'ECU', 1), |
|
1212 | + array(57, 'Egypt', 'EG', 'EGY', 1), |
|
1213 | + array(58, 'El Salvador', 'SV', 'SLV', 1), |
|
1214 | + array(60, 'Eritrea', 'ER', 'ERI', 1), |
|
1215 | + array(61, 'Slovakia', 'SK', 'SVK', 2), |
|
1216 | + array(62, 'Slovenia', 'SI', 'SVN', 2), |
|
1217 | + array(65, 'Estonia', 'EE', 'EST', 2), |
|
1218 | + array(66, 'Ethiopia', 'ET', 'ETH', 1), |
|
1219 | + array(102, 'Faroe islands', 'FO', 'FRO', 1), |
|
1220 | + array(103, 'Falkland Islands', 'FK', 'FLK', 1), |
|
1221 | + array(67, 'Fiji', 'FJ', 'FJI', 1), |
|
1222 | + array(69, 'Finland', 'FI', 'FIN', 2), |
|
1223 | + array(71, 'Gabon', 'GA', 'GAB', 1), |
|
1224 | + array(72, 'Gambia', 'GM', 'GMB', 1), |
|
1225 | + array(73, 'Georgia', 'GE', 'GEO', 1), |
|
1226 | + array(74, 'Ghana', 'GH', 'GHA', 1), |
|
1227 | + array(75, 'Gibraltar', 'GI', 'GIB', 1), |
|
1228 | + array(76, 'Greece', 'GR', 'GRC', 2), |
|
1229 | + array(77, 'Grenada', 'GD', 'GRD', 1), |
|
1230 | + array(78, 'Greenland', 'GL', 'GRL', 1), |
|
1231 | + array(79, 'Guadeloupe', 'GP', 'GLP', 1), |
|
1232 | + array(80, 'Guam', 'GU', 'GUM', 1), |
|
1233 | + array(81, 'Guatemala', 'GT', 'GTM', 1), |
|
1234 | + array(82, 'Guinea', 'GN', 'GIN', 1), |
|
1235 | + array(83, 'Equatorial Guinea', 'GQ', 'GNQ', 1), |
|
1236 | + array(84, 'Guinea-Bissau', 'GW', 'GNB', 1), |
|
1237 | + array(85, 'Guyana', 'GY', 'GUY', 1), |
|
1238 | + array(86, 'Haiti', 'HT', 'HTI', 1), |
|
1239 | + array(88, 'Honduras', 'HN', 'HND', 1), |
|
1240 | + array(89, 'Hong Kong', 'HK', 'HKG', 1), |
|
1241 | + array(90, 'Hungary', 'HU', 'HUN', 1), |
|
1242 | + array(91, 'India', 'IN', 'IND', 1), |
|
1243 | + array(205, 'British Indian Ocean Territory', 'IO', 'IOT', 1), |
|
1244 | + array(92, 'Indonesia', 'ID', 'IDN', 1), |
|
1245 | + array(93, 'Iraq', 'IQ', 'IRQ', 1), |
|
1246 | + array(94, 'Iran', 'IR', 'IRN', 1), |
|
1247 | + array(95, 'Ireland', 'IE', 'IRL', 2), |
|
1248 | + array(97, 'Iceland', 'IS', 'ISL', 1), |
|
1249 | + array(110, 'Israel', 'IL', 'ISR', 1), |
|
1250 | + array(49, 'Ivory Coast ', 'CI', 'CIV', 1), |
|
1251 | + array(112, 'Jamaica', 'JM', 'JAM', 1), |
|
1252 | + array(113, 'Japan', 'JP', 'JPN', 1), |
|
1253 | + array(114, 'Jordan', 'JO', 'JOR', 1), |
|
1254 | + array(115, 'Kazakhstan', 'KZ', 'KAZ', 1), |
|
1255 | + array(116, 'Kenya', 'KE', 'KEN', 1), |
|
1256 | + array(117, 'Kyrgyzstan', 'KG', 'KGZ', 1), |
|
1257 | + array(118, 'Kiribati', 'KI', 'KIR', 1), |
|
1258 | + array(48, 'South Korea', 'KR', 'KOR', 1), |
|
1259 | + array(228, 'Kosovo', 'XK', 'XKV', 2), |
|
1260 | + // there is no official ISO code for Kosovo yet (http://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/) so using a temporary country code and a modified 3 character code for ISO code -- this should be updated if/when Kosovo gets its own ISO code |
|
1261 | + array(119, 'Kuwait', 'KW', 'KWT', 1), |
|
1262 | + array(120, 'Laos', 'LA', 'LAO', 1), |
|
1263 | + array(121, 'Latvia', 'LV', 'LVA', 2), |
|
1264 | + array(122, 'Lesotho', 'LS', 'LSO', 1), |
|
1265 | + array(123, 'Lebanon', 'LB', 'LBN', 1), |
|
1266 | + array(124, 'Liberia', 'LR', 'LBR', 1), |
|
1267 | + array(125, 'Libya', 'LY', 'LBY', 1), |
|
1268 | + array(126, 'Liechtenstein', 'LI', 'LIE', 1), |
|
1269 | + array(127, 'Lithuania', 'LT', 'LTU', 2), |
|
1270 | + array(128, 'Luxemburg', 'LU', 'LUX', 2), |
|
1271 | + array(129, 'Macao', 'MO', 'MAC', 1), |
|
1272 | + array(130, 'Macedonia', 'MK', 'MKD', 1), |
|
1273 | + array(131, 'Madagascar', 'MG', 'MDG', 1), |
|
1274 | + array(132, 'Malaysia', 'MY', 'MYS', 1), |
|
1275 | + array(133, 'Malawi', 'MW', 'MWI', 1), |
|
1276 | + array(134, 'Maldivas', 'MV', 'MDV', 1), |
|
1277 | + array(135, 'Mali', 'ML', 'MLI', 1), |
|
1278 | + array(136, 'Malta', 'MT', 'MLT', 2), |
|
1279 | + array(101, 'Northern Marianas', 'MP', 'MNP', 1), |
|
1280 | + array(137, 'Morocco', 'MA', 'MAR', 1), |
|
1281 | + array(104, 'Marshall islands', 'MH', 'MHL', 1), |
|
1282 | + array(138, 'Martinique', 'MQ', 'MTQ', 1), |
|
1283 | + array(139, 'Mauritius', 'MU', 'MUS', 1), |
|
1284 | + array(140, 'Mauritania', 'MR', 'MRT', 1), |
|
1285 | + array(141, 'Mayote', 'YT', 'MYT', 2), |
|
1286 | + array(142, 'Mexico', 'MX', 'MEX', 1), |
|
1287 | + array(143, 'Micronesia', 'FM', 'FSM', 1), |
|
1288 | + array(144, 'Moldova', 'MD', 'MDA', 1), |
|
1289 | + array(145, 'Monaco', 'MC', 'MCO', 2), |
|
1290 | + array(146, 'Mongolia', 'MN', 'MNG', 1), |
|
1291 | + array(147, 'Montserrat', 'MS', 'MSR', 1), |
|
1292 | + array(227, 'Montenegro', 'ME', 'MNE', 2), |
|
1293 | + array(148, 'Mozambique', 'MZ', 'MOZ', 1), |
|
1294 | + array(149, 'Myanmar', 'MM', 'MMR', 1), |
|
1295 | + array(150, 'Namibia', 'NA', 'NAM', 1), |
|
1296 | + array(151, 'Nauru', 'NR', 'NRU', 1), |
|
1297 | + array(152, 'Nepal', 'NP', 'NPL', 1), |
|
1298 | + array(9, 'Netherlands Antilles', 'AN', 'ANT', 1), |
|
1299 | + array(153, 'Nicaragua', 'NI', 'NIC', 1), |
|
1300 | + array(154, 'Niger', 'NE', 'NER', 1), |
|
1301 | + array(155, 'Nigeria', 'NG', 'NGA', 1), |
|
1302 | + array(156, 'Niue', 'NU', 'NIU', 1), |
|
1303 | + array(157, 'Norway', 'NO', 'NOR', 1), |
|
1304 | + array(158, 'New Caledonia', 'NC', 'NCL', 1), |
|
1305 | + array(159, 'New Zealand', 'NZ', 'NZL', 1), |
|
1306 | + array(160, 'Oman', 'OM', 'OMN', 1), |
|
1307 | + array(161, 'Pakistan', 'PK', 'PAK', 1), |
|
1308 | + array(162, 'Palau', 'PW', 'PLW', 1), |
|
1309 | + array(163, 'Panama', 'PA', 'PAN', 1), |
|
1310 | + array(164, 'Papua New Guinea', 'PG', 'PNG', 1), |
|
1311 | + array(165, 'Paraguay', 'PY', 'PRY', 1), |
|
1312 | + array(166, 'Peru', 'PE', 'PER', 1), |
|
1313 | + array(68, 'Philippines', 'PH', 'PHL', 1), |
|
1314 | + array(167, 'Poland', 'PL', 'POL', 1), |
|
1315 | + array(168, 'Portugal', 'PT', 'PRT', 2), |
|
1316 | + array(169, 'Puerto Rico', 'PR', 'PRI', 1), |
|
1317 | + array(170, 'Qatar', 'QA', 'QAT', 1), |
|
1318 | + array(176, 'Rwanda', 'RW', 'RWA', 1), |
|
1319 | + array(177, 'Romania', 'RO', 'ROM', 2), |
|
1320 | + array(178, 'Russia', 'RU', 'RUS', 1), |
|
1321 | + array(229, 'Saint Pierre and Miquelon', 'PM', 'SPM', 2), |
|
1322 | + array(180, 'Samoa', 'WS', 'WSM', 1), |
|
1323 | + array(181, 'American Samoa', 'AS', 'ASM', 1), |
|
1324 | + array(183, 'San Marino', 'SM', 'SMR', 2), |
|
1325 | + array(184, 'Saint Vincent and the Grenadines', 'VC', 'VCT', 1), |
|
1326 | + array(185, 'Saint Helena', 'SH', 'SHN', 1), |
|
1327 | + array(186, 'Saint Lucia', 'LC', 'LCA', 1), |
|
1328 | + array(188, 'Senegal', 'SN', 'SEN', 1), |
|
1329 | + array(189, 'Seychelles', 'SC', 'SYC', 1), |
|
1330 | + array(190, 'Sierra Leona', 'SL', 'SLE', 1), |
|
1331 | + array(191, 'Singapore', 'SG', 'SGP', 1), |
|
1332 | + array(192, 'Syria', 'SY', 'SYR', 1), |
|
1333 | + array(193, 'Somalia', 'SO', 'SOM', 1), |
|
1334 | + array(194, 'Sri Lanka', 'LK', 'LKA', 1), |
|
1335 | + array(195, 'South Africa', 'ZA', 'ZAF', 1), |
|
1336 | + array(196, 'Sudan', 'SD', 'SDN', 1), |
|
1337 | + array(199, 'Suriname', 'SR', 'SUR', 1), |
|
1338 | + array(200, 'Swaziland', 'SZ', 'SWZ', 1), |
|
1339 | + array(201, 'Thailand', 'TH', 'THA', 1), |
|
1340 | + array(202, 'Taiwan', 'TW', 'TWN', 1), |
|
1341 | + array(203, 'Tanzania', 'TZ', 'TZA', 1), |
|
1342 | + array(204, 'Tajikistan', 'TJ', 'TJK', 1), |
|
1343 | + array(206, 'Timor-Leste', 'TL', 'TLS', 1), |
|
1344 | + array(207, 'Togo', 'TG', 'TGO', 1), |
|
1345 | + array(208, 'Tokelau', 'TK', 'TKL', 1), |
|
1346 | + array(209, 'Tonga', 'TO', 'TON', 1), |
|
1347 | + array(210, 'Trinidad and Tobago', 'TT', 'TTO', 1), |
|
1348 | + array(211, 'Tunisia', 'TN', 'TUN', 1), |
|
1349 | + array(212, 'Turkmenistan', 'TM', 'TKM', 1), |
|
1350 | + array(213, 'Turkey', 'TR', 'TUR', 1), |
|
1351 | + array(214, 'Tuvalu', 'TV', 'TUV', 1), |
|
1352 | + array(215, 'Ukraine', 'UA', 'UKR', 1), |
|
1353 | + array(216, 'Uganda', 'UG', 'UGA', 1), |
|
1354 | + array(59, 'United Arab Emirates', 'AE', 'ARE', 1), |
|
1355 | + array(217, 'Uruguay', 'UY', 'URY', 1), |
|
1356 | + array(218, 'Uzbekistan', 'UZ', 'UZB', 1), |
|
1357 | + array(219, 'Vanuatu', 'VU', 'VUT', 1), |
|
1358 | + array(220, 'Vatican City', 'VA', 'VAT', 2), |
|
1359 | + array(221, 'Venezuela', 'VE', 'VEN', 1), |
|
1360 | + array(222, 'Vietnam', 'VN', 'VNM', 1), |
|
1361 | + array(108, 'Virgin Islands', 'VI', 'VIR', 1), |
|
1362 | + array(223, 'Yemen', 'YE', 'YEM', 1), |
|
1363 | + array(225, 'Zambia', 'ZM', 'ZMB', 1), |
|
1364 | + array(226, 'Zimbabwe', 'ZW', 'ZWE', 1), |
|
1365 | + ); |
|
1366 | + $country_iso = 'US'; |
|
1367 | + foreach ($old_countries as $country_array) { |
|
1368 | + // note: index 0 is the 3.1 country ID |
|
1369 | + if ($country_array[0] == $country_id) { |
|
1370 | + // note: index 2 is the ISO |
|
1371 | + $country_iso = $country_array[2]; |
|
1372 | + break; |
|
1373 | + } |
|
1374 | + } |
|
1375 | + return $country_iso; |
|
1376 | + } |
|
1377 | + |
|
1378 | + |
|
1379 | + |
|
1380 | + /** |
|
1381 | + * Gets the ISO3 for the |
|
1382 | + * |
|
1383 | + * @return string |
|
1384 | + */ |
|
1385 | + public function get_default_country_iso() |
|
1386 | + { |
|
1387 | + $old_org_options = get_option('events_organization_settings'); |
|
1388 | + $iso = $this->get_iso_from_3_1_country_id($old_org_options['organization_country']); |
|
1389 | + return $iso; |
|
1390 | + } |
|
1391 | + |
|
1392 | + |
|
1393 | + |
|
1394 | + /** |
|
1395 | + * Converst a 3.1 payment status to its equivalent 4.1 regisration status |
|
1396 | + * |
|
1397 | + * @param string $payment_status possible value for 3.1's evens_attendee.payment_status |
|
1398 | + * @param boolean $this_thing_required_pre_approval whether the thing we're considering (the general setting's |
|
1399 | + * DEFAULT payment status, the event's DEFAULT payment status, or |
|
1400 | + * the attendee's payment status) required pre-approval. |
|
1401 | + * @return string STS_ID for use in 4.1 |
|
1402 | + */ |
|
1403 | + public function convert_3_1_payment_status_to_4_1_STS_ID($payment_status, $this_thing_required_pre_approval = false) |
|
1404 | + { |
|
1405 | + // EE team can read the related discussion: https://app.asana.com/0/2400967562914/9418495544455 |
|
1406 | + if ($this_thing_required_pre_approval) { |
|
1407 | + return 'RNA'; |
|
1408 | + } else { |
|
1409 | + $mapping = $default_reg_stati_conversions = array( |
|
1410 | + 'Completed' => 'RAP', |
|
1411 | + '' => 'RPP', |
|
1412 | + 'Incomplete' => 'RPP', |
|
1413 | + 'Pending' => 'RAP', |
|
1414 | + // stati that only occurred on 3.1 attendees: |
|
1415 | + 'Payment Declined' => 'RPP', |
|
1416 | + 'Not Completed' => 'RPP', |
|
1417 | + 'Cancelled' => 'RPP', |
|
1418 | + 'Declined' => 'RPP', |
|
1419 | + ); |
|
1420 | + } |
|
1421 | + return isset($mapping[ $payment_status ]) ? $mapping[ $payment_status ] : 'RNA'; |
|
1422 | + } |
|
1423 | + |
|
1424 | + |
|
1425 | + |
|
1426 | + /** |
|
1427 | + * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
|
1428 | + * and sets it as the featured image on the CPT event |
|
1429 | + * |
|
1430 | + * @param type $old_event |
|
1431 | + * @param type $new_cpt_id |
|
1432 | + * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
|
1433 | + * @return boolean whether or not we had to do the big job of creating an image attachment |
|
1434 | + */ |
|
1435 | + public function convert_image_url_to_attachment_and_attach_to_post( |
|
1436 | + $guid, |
|
1437 | + $new_cpt_id, |
|
1438 | + EE_Data_Migration_Script_Stage $migration_stage |
|
1439 | + ) { |
|
1440 | + $created_attachment_post = false; |
|
1441 | + $guid = $this->_get_original_guid($guid); |
|
1442 | + if ($guid) { |
|
1443 | + // check for an existing attachment post with this guid |
|
1444 | + $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
|
1445 | + if (! $attachment_post_id) { |
|
1446 | + // post thumbnail with that GUID doesn't exist, we should create one |
|
1447 | + $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
|
1448 | + $created_attachment_post = true; |
|
1449 | + } |
|
1450 | + // double-check we actually have an attachment post |
|
1451 | + if ($attachment_post_id) { |
|
1452 | + update_post_meta($new_cpt_id, '_thumbnail_id', $attachment_post_id); |
|
1453 | + } else { |
|
1454 | + $migration_stage->add_error(sprintf(esc_html__( |
|
1455 | + "Could not update event image %s for CPT with ID %d, but attachments post ID is %d", |
|
1456 | + "event_espresso" |
|
1457 | + ), $guid, $new_cpt_id, $attachment_post_id)); |
|
1458 | + } |
|
1459 | + } |
|
1460 | + return $created_attachment_post; |
|
1461 | + } |
|
1462 | + |
|
1463 | + |
|
1464 | + |
|
1465 | + /** |
|
1466 | + * In 3.1, the event thumbnail image DOESN'T point to the orignal image, but instead |
|
1467 | + * to a large thumbnail (which has nearly the same GUID, except it adds "-{width}x{height}" before the filetype, |
|
1468 | + * or whatever dimensions it is. Eg 'http://mysite.com/image1-300x400.jpg' instead of |
|
1469 | + * 'http://mysite.com/image1.jpg' ). This function attempts to strip that off and get the original file, if it |
|
1470 | + * exists |
|
1471 | + * |
|
1472 | + * @param string $guid_in_old_event |
|
1473 | + * @return string either the original guid, or $guid_in_old_event if we couldn't figure out what the original was |
|
1474 | + */ |
|
1475 | + private function _get_original_guid($guid_in_old_event) |
|
1476 | + { |
|
1477 | + $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
|
1478 | + // do a head request to verify the file exists |
|
1479 | + $head_response = wp_remote_head($original_guid); |
|
1480 | + if (! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
1481 | + return $original_guid; |
|
1482 | + } else { |
|
1483 | + return $guid_in_old_event; |
|
1484 | + } |
|
1485 | + } |
|
1486 | + |
|
1487 | + |
|
1488 | + |
|
1489 | + /** |
|
1490 | + * Creates an image attachment post for the GUID. If the GUID points to a remote image, |
|
1491 | + * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
|
1492 | + * thumbnails) |
|
1493 | + * |
|
1494 | + * @param type $guid |
|
1495 | + * @param EE_Data_Migration_Script_Stage $migration_stage |
|
1496 | + * @return int |
|
1497 | + */ |
|
1498 | + private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
|
1499 | + { |
|
1500 | + if (! $guid) { |
|
1501 | + $migration_stage->add_error(sprintf(esc_html__( |
|
1502 | + "Cannot create image attachment for a blank GUID!", |
|
1503 | + "event_espresso" |
|
1504 | + ))); |
|
1505 | + return 0; |
|
1506 | + } |
|
1507 | + $wp_filetype = wp_check_filetype(basename($guid), null); |
|
1508 | + $wp_upload_dir = wp_upload_dir(); |
|
1509 | + // if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
|
1510 | + if (strpos($guid, $wp_upload_dir['url']) === false) { |
|
1511 | + // image is located remotely. download it and place it in the uploads directory |
|
1512 | + if (! is_readable($guid)) { |
|
1513 | + $migration_stage->add_error(sprintf(esc_html__( |
|
1514 | + "Could not create image attachment from non-existent file: %s", |
|
1515 | + "event_espresso" |
|
1516 | + ), $guid)); |
|
1517 | + return 0; |
|
1518 | + } |
|
1519 | + $contents = file_get_contents($guid); |
|
1520 | + if ($contents === false) { |
|
1521 | + $migration_stage->add_error(sprintf(esc_html__( |
|
1522 | + "Could not read image at %s, and therefore couldnt create an attachment post for it.", |
|
1523 | + "event_espresso" |
|
1524 | + ), $guid)); |
|
1525 | + return false; |
|
1526 | + } |
|
1527 | + $local_filepath = $wp_upload_dir['path'] . DS . basename($guid); |
|
1528 | + $savefile = fopen($local_filepath, 'w'); |
|
1529 | + fwrite($savefile, $contents); |
|
1530 | + fclose($savefile); |
|
1531 | + $guid = str_replace($wp_upload_dir['path'], $wp_upload_dir['url'], $local_filepath); |
|
1532 | + } else { |
|
1533 | + $local_filepath = str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $guid); |
|
1534 | + } |
|
1535 | + $attachment = array( |
|
1536 | + 'guid' => $guid, |
|
1537 | + 'post_mime_type' => $wp_filetype['type'], |
|
1538 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($guid)), |
|
1539 | + 'post_content' => '', |
|
1540 | + 'post_status' => 'inherit', |
|
1541 | + ); |
|
1542 | + $attach_id = wp_insert_attachment($attachment, $guid); |
|
1543 | + if (! $attach_id) { |
|
1544 | + $migration_stage->add_error(sprintf(esc_html__( |
|
1545 | + "Could not create image attachment post from image '%s'. Attachment data was %s.", |
|
1546 | + "event_espresso" |
|
1547 | + ), $guid, $this->_json_encode($attachment))); |
|
1548 | + return $attach_id; |
|
1549 | + } |
|
1550 | + // you must first include the image.php file |
|
1551 | + // for the function wp_generate_attachment_metadata() to work |
|
1552 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
1553 | + $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
|
1554 | + if (! $attach_data) { |
|
1555 | + $migration_stage->add_error(sprintf(esc_html__( |
|
1556 | + "Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
|
1557 | + "event_espresso" |
|
1558 | + ), $attach_id, $local_filepath, $guid)); |
|
1559 | + return $attach_id; |
|
1560 | + } |
|
1561 | + $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
|
1562 | + if (! $metadata_save_result) { |
|
1563 | + $migration_stage->add_error(sprintf(esc_html__( |
|
1564 | + "Could not update attachment metadata for attachment %d with data %s", |
|
1565 | + "event_espresso" |
|
1566 | + ), $attach_id, $this->_json_encode($attach_data))); |
|
1567 | + } |
|
1568 | + return $attach_id; |
|
1569 | + } |
|
1570 | + |
|
1571 | + |
|
1572 | + |
|
1573 | + /** |
|
1574 | + * Finds the attachment post containing info about an image attachment given the GUID (link to the image itself), |
|
1575 | + * and returns its ID. |
|
1576 | + * |
|
1577 | + * @global type $wpdb |
|
1578 | + * @param string $guid |
|
1579 | + * @return int |
|
1580 | + */ |
|
1581 | + private function _get_image_attachment_id_by_GUID($guid) |
|
1582 | + { |
|
1583 | + global $wpdb; |
|
1584 | + $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid=%s LIMIT 1", $guid)); |
|
1585 | + return $attachment_id; |
|
1586 | + } |
|
1587 | + |
|
1588 | + |
|
1589 | + |
|
1590 | + /** |
|
1591 | + * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
|
1592 | + * (and optionally a timezone; if none is given, the wp DEFAULT is used) |
|
1593 | + * |
|
1594 | + * @param EE_Data_Migration_Script_base $stage |
|
1595 | + * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
|
1596 | + * UTC time for |
|
1597 | + * @param string $DATETIME_string |
|
1598 | + * @param string $timezone |
|
1599 | + * @return string |
|
1600 | + */ |
|
1601 | + public function convert_date_string_to_utc( |
|
1602 | + EE_Data_Migration_Script_Stage $stage, |
|
1603 | + $row_of_data, |
|
1604 | + $DATETIME_string, |
|
1605 | + $timezone = null |
|
1606 | + ) { |
|
1607 | + $original_tz = $timezone; |
|
1608 | + if (! $timezone) { |
|
1609 | + $timezone = $this->_get_wp_timezone(); |
|
1610 | + } |
|
1611 | + if (! $timezone) { |
|
1612 | + $stage->add_error(sprintf( |
|
1613 | + esc_html__("Could not find timezone given %s for %s", "event_espresso"), |
|
1614 | + $original_tz, |
|
1615 | + $row_of_data |
|
1616 | + )); |
|
1617 | + $timezone = 'UTC'; |
|
1618 | + } |
|
1619 | + try { |
|
1620 | + $date_obj = new DateTime($DATETIME_string, new DateTimeZone($timezone)); |
|
1621 | + EEH_DTT_Helper::setTimezone($date_obj, new DateTimeZone('UTC')); |
|
1622 | + } catch (Exception $e) { |
|
1623 | + $stage->add_error(sprintf(esc_html__( |
|
1624 | + "Could not convert time string '%s' using timezone '%s' into a proper DATETIME. Using current time instead.", |
|
1625 | + "event_espresso" |
|
1626 | + ), $DATETIME_string, $timezone)); |
|
1627 | + $date_obj = new DateTime(); |
|
1628 | + } |
|
1629 | + return $date_obj->format('Y-m-d H:i:s'); |
|
1630 | + } |
|
1631 | + |
|
1632 | + |
|
1633 | + |
|
1634 | + /** |
|
1635 | + * Gets the DEFAULT timezone string from wordpress (even if they set a gmt offset) |
|
1636 | + * |
|
1637 | + * @return string |
|
1638 | + */ |
|
1639 | + private function _get_wp_timezone() |
|
1640 | + { |
|
1641 | + $timezone = empty($timezone) ? get_option('timezone_string') : $timezone; |
|
1642 | + // if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter |
|
1643 | + if (empty($timezone)) { |
|
1644 | + // let's get a the WordPress UTC offset |
|
1645 | + $offset = get_option('gmt_offset'); |
|
1646 | + $timezone = $this->timezone_convert_to_string_from_offset($offset); |
|
1647 | + } |
|
1648 | + return $timezone; |
|
1649 | + } |
|
1650 | + |
|
1651 | + |
|
1652 | + |
|
1653 | + /** |
|
1654 | + * Gets the wordpress timezone string from a UTC offset |
|
1655 | + * |
|
1656 | + * @param int $offset |
|
1657 | + * @return boolean |
|
1658 | + */ |
|
1659 | + private function timezone_convert_to_string_from_offset($offset) |
|
1660 | + { |
|
1661 | + // shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did NOT work as expected - its not reliable |
|
1662 | + $offset *= 3600; // convert hour offset to seconds |
|
1663 | + $abbrarray = timezone_abbreviations_list(); |
|
1664 | + foreach ($abbrarray as $abbr) { |
|
1665 | + foreach ($abbr as $city) { |
|
1666 | + if ($city['offset'] == $offset) { |
|
1667 | + return $city['timezone_id']; |
|
1668 | + } |
|
1669 | + } |
|
1670 | + } |
|
1671 | + return false; |
|
1672 | + } |
|
1673 | + |
|
1674 | + |
|
1675 | + |
|
1676 | + public function migration_page_hooks() |
|
1677 | + { |
|
1678 | + add_filter( |
|
1679 | + 'FHEE__ee_migration_page__header', |
|
1680 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1681 | + 10, |
|
1682 | + 3 |
|
1683 | + ); |
|
1684 | + add_filter( |
|
1685 | + 'FHEE__ee_migration_page__p_after_header', |
|
1686 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1687 | + 10, |
|
1688 | + 2 |
|
1689 | + ); |
|
1690 | + add_filter( |
|
1691 | + 'FHEE__ee_migration_page__option_1_main', |
|
1692 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1693 | + 10, |
|
1694 | + 3 |
|
1695 | + ); |
|
1696 | + add_filter( |
|
1697 | + 'FHEE__ee_migration_page__option_1_button_text', |
|
1698 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1699 | + 10, |
|
1700 | + 3 |
|
1701 | + ); |
|
1702 | + add_action( |
|
1703 | + 'AHEE__ee_migration_page__option_1_extra_details', |
|
1704 | + array($this, '_migration_page_hook_option_1_extra_details'), |
|
1705 | + 10, |
|
1706 | + 3 |
|
1707 | + ); |
|
1708 | + add_filter( |
|
1709 | + 'FHEE__ee_migration_page__option_2_main', |
|
1710 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1711 | + 10, |
|
1712 | + 4 |
|
1713 | + ); |
|
1714 | + add_filter( |
|
1715 | + 'FHEE__ee_migration_page__option_2_button_text', |
|
1716 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1717 | + 10, |
|
1718 | + 2 |
|
1719 | + ); |
|
1720 | + add_filter( |
|
1721 | + 'FHEE__ee_migration_page__option_2_details', |
|
1722 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1723 | + 10, |
|
1724 | + 2 |
|
1725 | + ); |
|
1726 | + add_action( |
|
1727 | + 'AHEE__ee_migration_page__after_migration_options_table', |
|
1728 | + array($this, '_migration_page_hook_after_migration_options_table') |
|
1729 | + ); |
|
1730 | + add_filter( |
|
1731 | + 'FHEE__ee_migration_page__done_migration_header', |
|
1732 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1733 | + 10, |
|
1734 | + 2 |
|
1735 | + ); |
|
1736 | + add_filter( |
|
1737 | + 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
1738 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1739 | + 10, |
|
1740 | + 2 |
|
1741 | + ); |
|
1742 | + add_filter( |
|
1743 | + 'FHEE__ee_migration_page__migration_options_template', |
|
1744 | + array($this,'use_migration_options_from_ee3_template') |
|
1745 | + ); |
|
1746 | + } |
|
1747 | + |
|
1748 | + |
|
1749 | + |
|
1750 | + public function _migrate_page_hook_simplify_version_strings( |
|
1751 | + $old_content, |
|
1752 | + $current_db_state, |
|
1753 | + $next_db_state, |
|
1754 | + $ultimate_db_state = null |
|
1755 | + ) { |
|
1756 | + return str_replace( |
|
1757 | + array($current_db_state, $next_db_state, $ultimate_db_state), |
|
1758 | + array(esc_html__('EE3', 'event_espresso'), esc_html__('EE4', 'event_espresso'), esc_html__("EE4", 'event_espresso')), |
|
1759 | + $old_content |
|
1760 | + ); |
|
1761 | + } |
|
1762 | + |
|
1763 | + |
|
1764 | + |
|
1765 | + public function _migration_page_hook_simplify_next_db_state($old_content, $next_db_state) |
|
1766 | + { |
|
1767 | + return str_replace($next_db_state, esc_html__("EE4", 'event_espresso'), $old_content); |
|
1768 | + } |
|
1769 | + |
|
1770 | + |
|
1771 | + |
|
1772 | + public function _migration_page_hook_option_1_extra_details() |
|
1773 | + { |
|
1774 | + ?> |
|
1775 | 1775 | <p><?php printf(esc_html__( |
1776 | - "Note: many of your EE3 shortcodes will be changed to EE4 shortcodes during this migration (among many other things). Should you revert to EE3, then you should restore to your backup or manually change the EE4 shortcodes back to their EE3 equivalents", |
|
1777 | - "event_espresso" |
|
1778 | - )); ?></p><?php |
|
1779 | - } |
|
1776 | + "Note: many of your EE3 shortcodes will be changed to EE4 shortcodes during this migration (among many other things). Should you revert to EE3, then you should restore to your backup or manually change the EE4 shortcodes back to their EE3 equivalents", |
|
1777 | + "event_espresso" |
|
1778 | + )); ?></p><?php |
|
1779 | + } |
|
1780 | 1780 | |
1781 | 1781 | |
1782 | 1782 | |
1783 | - public function _migration_page_hook_after_migration_options_table() |
|
1784 | - { |
|
1785 | - ?><p class="ee-attention"> |
|
1783 | + public function _migration_page_hook_after_migration_options_table() |
|
1784 | + { |
|
1785 | + ?><p class="ee-attention"> |
|
1786 | 1786 | <strong><span class="reminder-spn"> |
1787 | 1787 | <?php _e( |
1788 | - "Important note to those using Event Espresso 3 addons: ", |
|
1789 | - "event_espresso" |
|
1790 | - ); ?></span></strong> |
|
1788 | + "Important note to those using Event Espresso 3 addons: ", |
|
1789 | + "event_espresso" |
|
1790 | + ); ?></span></strong> |
|
1791 | 1791 | <br/> |
1792 | 1792 | <?php _e( |
1793 | - "Unless an addon's description on our website explicitly states that it is compatible with EE4, you should consider it incompatible and know that it WILL NOT WORK correctly with this new version of Event Espresso 4 (EE4). As well, any data for incompatible addons will NOT BE MIGRATED until an updated EE4 compatible version of the addon is available. If you want, or need to keep using your EE3 addons, you should simply continue using EE3 until EE4 compatible versions of your addons become available. To continue using EE3 for now, just deactivate EE4 and reactivate EE3.", |
|
1794 | - "event_espresso" |
|
1795 | - ); ?> |
|
1793 | + "Unless an addon's description on our website explicitly states that it is compatible with EE4, you should consider it incompatible and know that it WILL NOT WORK correctly with this new version of Event Espresso 4 (EE4). As well, any data for incompatible addons will NOT BE MIGRATED until an updated EE4 compatible version of the addon is available. If you want, or need to keep using your EE3 addons, you should simply continue using EE3 until EE4 compatible versions of your addons become available. To continue using EE3 for now, just deactivate EE4 and reactivate EE3.", |
|
1794 | + "event_espresso" |
|
1795 | + ); ?> |
|
1796 | 1796 | </p><?php |
1797 | - } |
|
1797 | + } |
|
1798 | 1798 | |
1799 | 1799 | |
1800 | 1800 | |
1801 | - /** |
|
1802 | - * When showing the migration options, show more options and info than normal (ie, give folks the option |
|
1803 | - * to start using EE4 without migrating. From EE3 that's fine, because it doesn't actually remove any data, because |
|
1804 | - * EE4 doesn't have any yet. But when migrating from EE4 it would remove old data, so its not a great idea). |
|
1805 | - * @param $template_filepath |
|
1806 | - * @return string |
|
1807 | - */ |
|
1808 | - public function use_migration_options_from_ee3_template($template_filepath) |
|
1809 | - { |
|
1810 | - return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php'; |
|
1811 | - } |
|
1801 | + /** |
|
1802 | + * When showing the migration options, show more options and info than normal (ie, give folks the option |
|
1803 | + * to start using EE4 without migrating. From EE3 that's fine, because it doesn't actually remove any data, because |
|
1804 | + * EE4 doesn't have any yet. But when migrating from EE4 it would remove old data, so its not a great idea). |
|
1805 | + * @param $template_filepath |
|
1806 | + * @return string |
|
1807 | + */ |
|
1808 | + public function use_migration_options_from_ee3_template($template_filepath) |
|
1809 | + { |
|
1810 | + return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php'; |
|
1811 | + } |
|
1812 | 1812 | } |