@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | ), |
144 | 144 | ], |
145 | 145 | ]; |
146 | - $this->_model_relations = [ |
|
146 | + $this->_model_relations = [ |
|
147 | 147 | 'Registration' => new EE_Has_Many_Relation(), |
148 | 148 | 'Payment' => new EE_Has_Many_Relation(), |
149 | 149 | 'Status' => new EE_Belongs_To_Relation(), |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | ], |
212 | 212 | OBJECT, |
213 | 213 | [ |
214 | - 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
214 | + 'txnDate' => ['DATE('.$query_interval.')', '%s'], |
|
215 | 215 | 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
216 | 216 | ] |
217 | 217 | ); |
@@ -230,17 +230,17 @@ discard block |
||
230 | 230 | public function get_revenue_per_event_report($period = '-1 month') |
231 | 231 | { |
232 | 232 | global $wpdb; |
233 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
234 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
235 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
233 | + $transaction_table = $wpdb->prefix.'esp_transaction'; |
|
234 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
235 | + $registration_payment_table = $wpdb->prefix.'esp_registration_payment'; |
|
236 | 236 | $event_table = $wpdb->posts; |
237 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
237 | + $payment_table = $wpdb->prefix.'esp_payment'; |
|
238 | 238 | $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
239 | 239 | $approved_payment_status = EEM_Payment::status_id_approved; |
240 | 240 | $extra_event_on_join = ''; |
241 | 241 | // exclude events not authored by user if permissions in effect |
242 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
243 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
242 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
243 | + $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id(); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | return $wpdb->get_results( |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
319 | 319 | { |
320 | 320 | EE_Error::doing_it_wrong( |
321 | - __CLASS__ . '::' . __FUNCTION__, |
|
321 | + __CLASS__.'::'.__FUNCTION__, |
|
322 | 322 | sprintf( |
323 | 323 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
324 | 324 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | $time_to_leave_alone |
391 | 391 | ); |
392 | 392 | // now that we have the ids to delete |
393 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
393 | + if ( ! empty($txn_ids) && is_array($txn_ids)) { |
|
394 | 394 | // first, make sure these TXN's are removed the "ee_locked_transactions" array |
395 | 395 | EEM_Transaction::unset_locked_transactions($txn_ids); |
396 | 396 | |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | // let's get deleting... |
404 | 404 | // We got the ids from the original query to get them FROM |
405 | 405 | // the db (which is sanitized) so no need to prepare them again. |
406 | - $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
406 | + $query = $wpdb->prepare("DELETE FROM ".$this->table()." WHERE TXN_ID IN ( $format )", $txn_ids); |
|
407 | 407 | $deleted = $wpdb->query($query); |
408 | 408 | } |
409 | 409 | if ($deleted) { |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | $locked_transactions = get_option('ee_locked_transactions', []); |
428 | 428 | $update = false; |
429 | 429 | foreach ($transaction_IDs as $TXN_ID) { |
430 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
431 | - unset($locked_transactions[ $TXN_ID ]); |
|
430 | + if (isset($locked_transactions[$TXN_ID])) { |
|
431 | + unset($locked_transactions[$TXN_ID]); |
|
432 | 432 | $update = true; |
433 | 433 | } |
434 | 434 | } |
@@ -18,226 +18,226 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class EEM_Transaction extends EEM_Base |
20 | 20 | { |
21 | - // private instance of the Transaction object |
|
22 | - protected static $_instance; |
|
23 | - |
|
24 | - /** |
|
25 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
26 | - * but payment is pending. This is the state for transactions where payment is promised |
|
27 | - * from an offline gateway. |
|
28 | - */ |
|
29 | - // const open_status_code = 'TPN'; |
|
30 | - |
|
31 | - /** |
|
32 | - * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
33 | - * either due to a technical reason (server or computer crash during registration), |
|
34 | - * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
35 | - */ |
|
36 | - const failed_status_code = 'TFL'; |
|
37 | - |
|
38 | - /** |
|
39 | - * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
40 | - * either due to a technical reason (server or computer crash during registration), |
|
41 | - * or due to an abandoned cart after registrant chose not to complete the registration process |
|
42 | - * HOWEVER... |
|
43 | - * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
44 | - * registrant |
|
45 | - */ |
|
46 | - const abandoned_status_code = 'TAB'; |
|
47 | - |
|
48 | - /** |
|
49 | - * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
50 | - * meaning that monies are still owing: TXN_paid < TXN_total |
|
51 | - */ |
|
52 | - const incomplete_status_code = 'TIN'; |
|
53 | - |
|
54 | - /** |
|
55 | - * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
56 | - * meaning that NO monies are owing: TXN_paid == TXN_total |
|
57 | - */ |
|
58 | - const complete_status_code = 'TCM'; |
|
59 | - |
|
60 | - /** |
|
61 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
62 | - * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
63 | - */ |
|
64 | - const overpaid_status_code = 'TOP'; |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * private constructor to prevent direct creation |
|
69 | - * |
|
70 | - * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and |
|
71 | - * any incoming timezone data that gets saved). Note this just sends the timezone info |
|
72 | - * to the date time model field objects. Default is NULL (and will be assumed using |
|
73 | - * the set timezone in the 'timezone_string' wp option) |
|
74 | - * @throws EE_Error |
|
75 | - * @throws ReflectionException |
|
76 | - */ |
|
77 | - protected function __construct(?string $timezone = '') |
|
78 | - { |
|
79 | - $this->singular_item = esc_html__('Transaction', 'event_espresso'); |
|
80 | - $this->plural_item = esc_html__('Transactions', 'event_espresso'); |
|
81 | - |
|
82 | - $this->_tables = [ |
|
83 | - 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID'), |
|
84 | - ]; |
|
85 | - $this->_fields = [ |
|
86 | - 'TransactionTable' => [ |
|
87 | - 'TXN_ID' => new EE_Primary_Key_Int_Field( |
|
88 | - 'TXN_ID', esc_html__('Transaction ID', 'event_espresso') |
|
89 | - ), |
|
90 | - 'TXN_timestamp' => new EE_Datetime_Field( |
|
91 | - 'TXN_timestamp', |
|
92 | - esc_html__('date when transaction was created', 'event_espresso'), |
|
93 | - false, |
|
94 | - EE_Datetime_Field::now, |
|
95 | - $timezone |
|
96 | - ), |
|
97 | - 'TXN_total' => new EE_Money_Field( |
|
98 | - 'TXN_total', |
|
99 | - esc_html__('Total value of Transaction', 'event_espresso'), |
|
100 | - false, |
|
101 | - 0 |
|
102 | - ), |
|
103 | - 'TXN_paid' => new EE_Money_Field( |
|
104 | - 'TXN_paid', |
|
105 | - esc_html__('Amount paid towards transaction to date', 'event_espresso'), |
|
106 | - false, |
|
107 | - 0 |
|
108 | - ), |
|
109 | - 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
110 | - 'STS_ID', |
|
111 | - esc_html__('Status ID', 'event_espresso'), |
|
112 | - false, |
|
113 | - EEM_Transaction::failed_status_code, |
|
114 | - 'Status' |
|
115 | - ), |
|
116 | - 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
117 | - 'TXN_session_data', |
|
118 | - esc_html__('Serialized session data', 'event_espresso'), |
|
119 | - true, |
|
120 | - '' |
|
121 | - ), |
|
122 | - 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
123 | - 'TXN_hash_salt', |
|
124 | - esc_html__('Transaction Hash Salt', 'event_espresso'), |
|
125 | - true, |
|
126 | - '' |
|
127 | - ), |
|
128 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
129 | - 'PMD_ID', |
|
130 | - esc_html__("Last Used Payment Method", 'event_espresso'), |
|
131 | - true, |
|
132 | - null, |
|
133 | - 'Payment_Method' |
|
134 | - ), |
|
135 | - 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
136 | - 'TXN_reg_steps', |
|
137 | - esc_html__('Registration Steps', 'event_espresso'), |
|
138 | - false, |
|
139 | - [] |
|
140 | - ), |
|
141 | - ], |
|
142 | - ]; |
|
143 | - $this->_model_relations = [ |
|
144 | - 'Registration' => new EE_Has_Many_Relation(), |
|
145 | - 'Payment' => new EE_Has_Many_Relation(), |
|
146 | - 'Status' => new EE_Belongs_To_Relation(), |
|
147 | - 'Line_Item' => new EE_Has_Many_Relation(false), |
|
148 | - // you can delete a transaction without needing to delete its line items |
|
149 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
150 | - 'Message' => new EE_Has_Many_Relation(), |
|
151 | - ]; |
|
152 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
153 | - parent::__construct($timezone); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * txn_status_array |
|
159 | - * get list of transaction statuses |
|
160 | - * |
|
161 | - * @access public |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - public static function txn_status_array() |
|
165 | - { |
|
166 | - return apply_filters( |
|
167 | - 'FHEE__EEM_Transaction__txn_status_array', |
|
168 | - [ |
|
169 | - EEM_Transaction::overpaid_status_code, |
|
170 | - EEM_Transaction::complete_status_code, |
|
171 | - EEM_Transaction::incomplete_status_code, |
|
172 | - EEM_Transaction::abandoned_status_code, |
|
173 | - EEM_Transaction::failed_status_code, |
|
174 | - ] |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * get the revenue per day for the Transaction Admin page Reports Tab |
|
181 | - * |
|
182 | - * @access public |
|
183 | - * @param string $period |
|
184 | - * @return stdClass[] |
|
185 | - * @throws EE_Error |
|
186 | - * @throws EE_Error |
|
187 | - */ |
|
188 | - public function get_revenue_per_day_report($period = '-1 month') |
|
189 | - { |
|
190 | - $sql_date = $this->convert_datetime_for_query( |
|
191 | - 'TXN_timestamp', |
|
192 | - date('Y-m-d H:i:s', strtotime($period)), |
|
193 | - 'Y-m-d H:i:s', |
|
194 | - 'UTC' |
|
195 | - ); |
|
196 | - |
|
197 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
198 | - |
|
199 | - return $this->_get_all_wpdb_results( |
|
200 | - [ |
|
201 | - [ |
|
202 | - 'TXN_timestamp' => ['>=', $sql_date], |
|
203 | - ], |
|
204 | - 'group_by' => 'txnDate', |
|
205 | - 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
206 | - ], |
|
207 | - OBJECT, |
|
208 | - [ |
|
209 | - 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
210 | - 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
|
211 | - ] |
|
212 | - ); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * get the revenue per event for the Transaction Admin page Reports Tab |
|
218 | - * |
|
219 | - * @access public |
|
220 | - * @param string $period |
|
221 | - * @return EE_Transaction[] |
|
222 | - */ |
|
223 | - public function get_revenue_per_event_report($period = '-1 month') |
|
224 | - { |
|
225 | - global $wpdb; |
|
226 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
227 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
228 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
229 | - $event_table = $wpdb->posts; |
|
230 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
231 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
232 | - $approved_payment_status = EEM_Payment::status_id_approved; |
|
233 | - $extra_event_on_join = ''; |
|
234 | - // exclude events not authored by user if permissions in effect |
|
235 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
236 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
237 | - } |
|
238 | - |
|
239 | - return $wpdb->get_results( |
|
240 | - "SELECT |
|
21 | + // private instance of the Transaction object |
|
22 | + protected static $_instance; |
|
23 | + |
|
24 | + /** |
|
25 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
26 | + * but payment is pending. This is the state for transactions where payment is promised |
|
27 | + * from an offline gateway. |
|
28 | + */ |
|
29 | + // const open_status_code = 'TPN'; |
|
30 | + |
|
31 | + /** |
|
32 | + * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
33 | + * either due to a technical reason (server or computer crash during registration), |
|
34 | + * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
35 | + */ |
|
36 | + const failed_status_code = 'TFL'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
40 | + * either due to a technical reason (server or computer crash during registration), |
|
41 | + * or due to an abandoned cart after registrant chose not to complete the registration process |
|
42 | + * HOWEVER... |
|
43 | + * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
44 | + * registrant |
|
45 | + */ |
|
46 | + const abandoned_status_code = 'TAB'; |
|
47 | + |
|
48 | + /** |
|
49 | + * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
50 | + * meaning that monies are still owing: TXN_paid < TXN_total |
|
51 | + */ |
|
52 | + const incomplete_status_code = 'TIN'; |
|
53 | + |
|
54 | + /** |
|
55 | + * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
56 | + * meaning that NO monies are owing: TXN_paid == TXN_total |
|
57 | + */ |
|
58 | + const complete_status_code = 'TCM'; |
|
59 | + |
|
60 | + /** |
|
61 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
62 | + * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
63 | + */ |
|
64 | + const overpaid_status_code = 'TOP'; |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * private constructor to prevent direct creation |
|
69 | + * |
|
70 | + * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and |
|
71 | + * any incoming timezone data that gets saved). Note this just sends the timezone info |
|
72 | + * to the date time model field objects. Default is NULL (and will be assumed using |
|
73 | + * the set timezone in the 'timezone_string' wp option) |
|
74 | + * @throws EE_Error |
|
75 | + * @throws ReflectionException |
|
76 | + */ |
|
77 | + protected function __construct(?string $timezone = '') |
|
78 | + { |
|
79 | + $this->singular_item = esc_html__('Transaction', 'event_espresso'); |
|
80 | + $this->plural_item = esc_html__('Transactions', 'event_espresso'); |
|
81 | + |
|
82 | + $this->_tables = [ |
|
83 | + 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID'), |
|
84 | + ]; |
|
85 | + $this->_fields = [ |
|
86 | + 'TransactionTable' => [ |
|
87 | + 'TXN_ID' => new EE_Primary_Key_Int_Field( |
|
88 | + 'TXN_ID', esc_html__('Transaction ID', 'event_espresso') |
|
89 | + ), |
|
90 | + 'TXN_timestamp' => new EE_Datetime_Field( |
|
91 | + 'TXN_timestamp', |
|
92 | + esc_html__('date when transaction was created', 'event_espresso'), |
|
93 | + false, |
|
94 | + EE_Datetime_Field::now, |
|
95 | + $timezone |
|
96 | + ), |
|
97 | + 'TXN_total' => new EE_Money_Field( |
|
98 | + 'TXN_total', |
|
99 | + esc_html__('Total value of Transaction', 'event_espresso'), |
|
100 | + false, |
|
101 | + 0 |
|
102 | + ), |
|
103 | + 'TXN_paid' => new EE_Money_Field( |
|
104 | + 'TXN_paid', |
|
105 | + esc_html__('Amount paid towards transaction to date', 'event_espresso'), |
|
106 | + false, |
|
107 | + 0 |
|
108 | + ), |
|
109 | + 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
110 | + 'STS_ID', |
|
111 | + esc_html__('Status ID', 'event_espresso'), |
|
112 | + false, |
|
113 | + EEM_Transaction::failed_status_code, |
|
114 | + 'Status' |
|
115 | + ), |
|
116 | + 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
117 | + 'TXN_session_data', |
|
118 | + esc_html__('Serialized session data', 'event_espresso'), |
|
119 | + true, |
|
120 | + '' |
|
121 | + ), |
|
122 | + 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
123 | + 'TXN_hash_salt', |
|
124 | + esc_html__('Transaction Hash Salt', 'event_espresso'), |
|
125 | + true, |
|
126 | + '' |
|
127 | + ), |
|
128 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
129 | + 'PMD_ID', |
|
130 | + esc_html__("Last Used Payment Method", 'event_espresso'), |
|
131 | + true, |
|
132 | + null, |
|
133 | + 'Payment_Method' |
|
134 | + ), |
|
135 | + 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
136 | + 'TXN_reg_steps', |
|
137 | + esc_html__('Registration Steps', 'event_espresso'), |
|
138 | + false, |
|
139 | + [] |
|
140 | + ), |
|
141 | + ], |
|
142 | + ]; |
|
143 | + $this->_model_relations = [ |
|
144 | + 'Registration' => new EE_Has_Many_Relation(), |
|
145 | + 'Payment' => new EE_Has_Many_Relation(), |
|
146 | + 'Status' => new EE_Belongs_To_Relation(), |
|
147 | + 'Line_Item' => new EE_Has_Many_Relation(false), |
|
148 | + // you can delete a transaction without needing to delete its line items |
|
149 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
150 | + 'Message' => new EE_Has_Many_Relation(), |
|
151 | + ]; |
|
152 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
153 | + parent::__construct($timezone); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * txn_status_array |
|
159 | + * get list of transaction statuses |
|
160 | + * |
|
161 | + * @access public |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + public static function txn_status_array() |
|
165 | + { |
|
166 | + return apply_filters( |
|
167 | + 'FHEE__EEM_Transaction__txn_status_array', |
|
168 | + [ |
|
169 | + EEM_Transaction::overpaid_status_code, |
|
170 | + EEM_Transaction::complete_status_code, |
|
171 | + EEM_Transaction::incomplete_status_code, |
|
172 | + EEM_Transaction::abandoned_status_code, |
|
173 | + EEM_Transaction::failed_status_code, |
|
174 | + ] |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * get the revenue per day for the Transaction Admin page Reports Tab |
|
181 | + * |
|
182 | + * @access public |
|
183 | + * @param string $period |
|
184 | + * @return stdClass[] |
|
185 | + * @throws EE_Error |
|
186 | + * @throws EE_Error |
|
187 | + */ |
|
188 | + public function get_revenue_per_day_report($period = '-1 month') |
|
189 | + { |
|
190 | + $sql_date = $this->convert_datetime_for_query( |
|
191 | + 'TXN_timestamp', |
|
192 | + date('Y-m-d H:i:s', strtotime($period)), |
|
193 | + 'Y-m-d H:i:s', |
|
194 | + 'UTC' |
|
195 | + ); |
|
196 | + |
|
197 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
198 | + |
|
199 | + return $this->_get_all_wpdb_results( |
|
200 | + [ |
|
201 | + [ |
|
202 | + 'TXN_timestamp' => ['>=', $sql_date], |
|
203 | + ], |
|
204 | + 'group_by' => 'txnDate', |
|
205 | + 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
206 | + ], |
|
207 | + OBJECT, |
|
208 | + [ |
|
209 | + 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
210 | + 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
|
211 | + ] |
|
212 | + ); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * get the revenue per event for the Transaction Admin page Reports Tab |
|
218 | + * |
|
219 | + * @access public |
|
220 | + * @param string $period |
|
221 | + * @return EE_Transaction[] |
|
222 | + */ |
|
223 | + public function get_revenue_per_event_report($period = '-1 month') |
|
224 | + { |
|
225 | + global $wpdb; |
|
226 | + $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
227 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
228 | + $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
229 | + $event_table = $wpdb->posts; |
|
230 | + $payment_table = $wpdb->prefix . 'esp_payment'; |
|
231 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
232 | + $approved_payment_status = EEM_Payment::status_id_approved; |
|
233 | + $extra_event_on_join = ''; |
|
234 | + // exclude events not authored by user if permissions in effect |
|
235 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
236 | + $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
237 | + } |
|
238 | + |
|
239 | + return $wpdb->get_results( |
|
240 | + "SELECT |
|
241 | 241 | Transaction_Event.event_name AS event_name, |
242 | 242 | SUM(Transaction_Event.paid) AS revenue |
243 | 243 | FROM |
@@ -265,232 +265,232 @@ discard block |
||
265 | 265 | $extra_event_on_join |
266 | 266 | ) AS Transaction_Event |
267 | 267 | GROUP BY event_name" |
268 | - ); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
274 | - * request global variable. Either way, tries to find the current transaction (through |
|
275 | - * the registration pointed to by reg_url_link), if not returns null |
|
276 | - * |
|
277 | - * @param string $reg_url_link |
|
278 | - * @return EE_Transaction |
|
279 | - * @throws EE_Error |
|
280 | - */ |
|
281 | - public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
282 | - { |
|
283 | - if (empty($reg_url_link)) { |
|
284 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
285 | - $reg_url_link = $request->getRequestParam('e_reg_url_link'); |
|
286 | - } |
|
287 | - return $this->get_one( |
|
288 | - [ |
|
289 | - [ |
|
290 | - 'Registration.REG_url_link' => $reg_url_link, |
|
291 | - ], |
|
292 | - ] |
|
293 | - ); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Updates the provided EE_Transaction with all the applicable payments |
|
299 | - * (or fetch the EE_Transaction from its ID) |
|
300 | - * |
|
301 | - * @param EE_Transaction|int $transaction_obj_or_id |
|
302 | - * @param boolean $save_txn whether or not to save the transaction during this function call |
|
303 | - * @return array |
|
304 | - * @throws EE_Error |
|
305 | - * @throws ReflectionException |
|
306 | - * @deprecated |
|
307 | - */ |
|
308 | - public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
309 | - { |
|
310 | - EE_Error::doing_it_wrong( |
|
311 | - __CLASS__ . '::' . __FUNCTION__, |
|
312 | - sprintf( |
|
313 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
314 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
315 | - ), |
|
316 | - '4.6.0' |
|
317 | - ); |
|
318 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
319 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
320 | - |
|
321 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
322 | - $this->ensure_is_obj($transaction_obj_or_id) |
|
323 | - ); |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
329 | - * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
330 | - * and so we only use wpdb directly and only do minimal joins. |
|
331 | - * Transactions are considered "junk" if they're failed for longer than a week. |
|
332 | - * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
333 | - * it, it's probably not junk (regardless of what status it has). |
|
334 | - * The downside to this approach is that is addons are listening for object deletions |
|
335 | - * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
336 | - * to catch these types of deletions. |
|
337 | - * |
|
338 | - * @return int |
|
339 | - * @throws EE_Error |
|
340 | - * @throws EE_Error |
|
341 | - * @global WPDB $wpdb |
|
342 | - */ |
|
343 | - public function delete_junk_transactions() |
|
344 | - { |
|
345 | - global $wpdb; |
|
346 | - $deleted = false; |
|
347 | - $time_to_leave_alone = (int) apply_filters( |
|
348 | - 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
349 | - WEEK_IN_SECONDS |
|
350 | - ); |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
355 | - * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
356 | - * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
357 | - */ |
|
358 | - $ids_query = apply_filters( |
|
359 | - 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
360 | - [ |
|
361 | - 0 => [ |
|
362 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
363 | - 'Payment.PAY_ID' => ['IS NULL'], |
|
364 | - 'TXN_timestamp' => ['<', time() - $time_to_leave_alone], |
|
365 | - ], |
|
366 | - 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
367 | - 'limit' => 1000, |
|
368 | - ], |
|
369 | - $time_to_leave_alone |
|
370 | - ); |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
375 | - * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
376 | - */ |
|
377 | - $txn_ids = apply_filters( |
|
378 | - 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
379 | - EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
380 | - $time_to_leave_alone |
|
381 | - ); |
|
382 | - // now that we have the ids to delete |
|
383 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
384 | - // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
385 | - EEM_Transaction::unset_locked_transactions($txn_ids); |
|
386 | - |
|
387 | - // Create IDs placeholder. |
|
388 | - $placeholders = array_fill(0, count($txn_ids), '%d'); |
|
389 | - |
|
390 | - // Glue it together to use inside $wpdb->prepare. |
|
391 | - $format = implode(', ', $placeholders); |
|
392 | - |
|
393 | - // let's get deleting... |
|
394 | - // We got the ids from the original query to get them FROM |
|
395 | - // the db (which is sanitized) so no need to prepare them again. |
|
396 | - $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
397 | - $deleted = $wpdb->query($query); |
|
398 | - } |
|
399 | - if ($deleted) { |
|
400 | - /** |
|
401 | - * Allows code to do something after the transactions have been deleted. |
|
402 | - */ |
|
403 | - do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
404 | - } |
|
405 | - |
|
406 | - return $deleted; |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * @param array $transaction_IDs |
|
412 | - * @return bool |
|
413 | - */ |
|
414 | - public static function unset_locked_transactions(array $transaction_IDs) |
|
415 | - { |
|
416 | - $locked_transactions = get_option('ee_locked_transactions', []); |
|
417 | - $update = false; |
|
418 | - foreach ($transaction_IDs as $TXN_ID) { |
|
419 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
420 | - unset($locked_transactions[ $TXN_ID ]); |
|
421 | - $update = true; |
|
422 | - } |
|
423 | - } |
|
424 | - if ($update) { |
|
425 | - update_option('ee_locked_transactions', $locked_transactions); |
|
426 | - } |
|
427 | - |
|
428 | - return $update; |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * returns an array of EE_Transaction objects whose timestamp is greater than |
|
434 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
435 | - * |
|
436 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
437 | - * @throws EE_Error |
|
438 | - * @throws InvalidArgumentException |
|
439 | - * @throws InvalidDataTypeException |
|
440 | - * @throws InvalidInterfaceException |
|
441 | - */ |
|
442 | - public function get_transactions_in_progress() |
|
443 | - { |
|
444 | - return $this->_get_transactions_in_progress(); |
|
445 | - } |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * returns an array of EE_Transaction objects whose timestamp is less than |
|
450 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
451 | - * |
|
452 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
453 | - * @throws EE_Error |
|
454 | - * @throws InvalidArgumentException |
|
455 | - * @throws InvalidDataTypeException |
|
456 | - * @throws InvalidInterfaceException |
|
457 | - */ |
|
458 | - public function get_transactions_not_in_progress() |
|
459 | - { |
|
460 | - return $this->_get_transactions_in_progress('<='); |
|
461 | - } |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * @param string $comparison |
|
466 | - * @return EE_Transaction[] |
|
467 | - * @throws EE_Error |
|
468 | - * @throws InvalidArgumentException |
|
469 | - * @throws InvalidDataTypeException |
|
470 | - * @throws InvalidInterfaceException |
|
471 | - */ |
|
472 | - private function _get_transactions_in_progress($comparison = '>=') |
|
473 | - { |
|
474 | - $comparison = $comparison === '>=' || $comparison === '<=' |
|
475 | - ? $comparison |
|
476 | - : '>='; |
|
477 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
478 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
479 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
480 | - ); |
|
481 | - return $this->get_all( |
|
482 | - [ |
|
483 | - [ |
|
484 | - 'TXN_timestamp' => [ |
|
485 | - $comparison, |
|
486 | - $session_lifespan->expiration(), |
|
487 | - ], |
|
488 | - 'STS_ID' => [ |
|
489 | - '!=', |
|
490 | - EEM_Transaction::complete_status_code, |
|
491 | - ], |
|
492 | - ], |
|
493 | - ] |
|
494 | - ); |
|
495 | - } |
|
268 | + ); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
274 | + * request global variable. Either way, tries to find the current transaction (through |
|
275 | + * the registration pointed to by reg_url_link), if not returns null |
|
276 | + * |
|
277 | + * @param string $reg_url_link |
|
278 | + * @return EE_Transaction |
|
279 | + * @throws EE_Error |
|
280 | + */ |
|
281 | + public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
282 | + { |
|
283 | + if (empty($reg_url_link)) { |
|
284 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
285 | + $reg_url_link = $request->getRequestParam('e_reg_url_link'); |
|
286 | + } |
|
287 | + return $this->get_one( |
|
288 | + [ |
|
289 | + [ |
|
290 | + 'Registration.REG_url_link' => $reg_url_link, |
|
291 | + ], |
|
292 | + ] |
|
293 | + ); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Updates the provided EE_Transaction with all the applicable payments |
|
299 | + * (or fetch the EE_Transaction from its ID) |
|
300 | + * |
|
301 | + * @param EE_Transaction|int $transaction_obj_or_id |
|
302 | + * @param boolean $save_txn whether or not to save the transaction during this function call |
|
303 | + * @return array |
|
304 | + * @throws EE_Error |
|
305 | + * @throws ReflectionException |
|
306 | + * @deprecated |
|
307 | + */ |
|
308 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
309 | + { |
|
310 | + EE_Error::doing_it_wrong( |
|
311 | + __CLASS__ . '::' . __FUNCTION__, |
|
312 | + sprintf( |
|
313 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
314 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
315 | + ), |
|
316 | + '4.6.0' |
|
317 | + ); |
|
318 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
319 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
320 | + |
|
321 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
322 | + $this->ensure_is_obj($transaction_obj_or_id) |
|
323 | + ); |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
329 | + * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
330 | + * and so we only use wpdb directly and only do minimal joins. |
|
331 | + * Transactions are considered "junk" if they're failed for longer than a week. |
|
332 | + * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
333 | + * it, it's probably not junk (regardless of what status it has). |
|
334 | + * The downside to this approach is that is addons are listening for object deletions |
|
335 | + * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
336 | + * to catch these types of deletions. |
|
337 | + * |
|
338 | + * @return int |
|
339 | + * @throws EE_Error |
|
340 | + * @throws EE_Error |
|
341 | + * @global WPDB $wpdb |
|
342 | + */ |
|
343 | + public function delete_junk_transactions() |
|
344 | + { |
|
345 | + global $wpdb; |
|
346 | + $deleted = false; |
|
347 | + $time_to_leave_alone = (int) apply_filters( |
|
348 | + 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
349 | + WEEK_IN_SECONDS |
|
350 | + ); |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
355 | + * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
356 | + * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
357 | + */ |
|
358 | + $ids_query = apply_filters( |
|
359 | + 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
360 | + [ |
|
361 | + 0 => [ |
|
362 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
363 | + 'Payment.PAY_ID' => ['IS NULL'], |
|
364 | + 'TXN_timestamp' => ['<', time() - $time_to_leave_alone], |
|
365 | + ], |
|
366 | + 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
367 | + 'limit' => 1000, |
|
368 | + ], |
|
369 | + $time_to_leave_alone |
|
370 | + ); |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
375 | + * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
376 | + */ |
|
377 | + $txn_ids = apply_filters( |
|
378 | + 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
379 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
380 | + $time_to_leave_alone |
|
381 | + ); |
|
382 | + // now that we have the ids to delete |
|
383 | + if (! empty($txn_ids) && is_array($txn_ids)) { |
|
384 | + // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
385 | + EEM_Transaction::unset_locked_transactions($txn_ids); |
|
386 | + |
|
387 | + // Create IDs placeholder. |
|
388 | + $placeholders = array_fill(0, count($txn_ids), '%d'); |
|
389 | + |
|
390 | + // Glue it together to use inside $wpdb->prepare. |
|
391 | + $format = implode(', ', $placeholders); |
|
392 | + |
|
393 | + // let's get deleting... |
|
394 | + // We got the ids from the original query to get them FROM |
|
395 | + // the db (which is sanitized) so no need to prepare them again. |
|
396 | + $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
397 | + $deleted = $wpdb->query($query); |
|
398 | + } |
|
399 | + if ($deleted) { |
|
400 | + /** |
|
401 | + * Allows code to do something after the transactions have been deleted. |
|
402 | + */ |
|
403 | + do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
404 | + } |
|
405 | + |
|
406 | + return $deleted; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * @param array $transaction_IDs |
|
412 | + * @return bool |
|
413 | + */ |
|
414 | + public static function unset_locked_transactions(array $transaction_IDs) |
|
415 | + { |
|
416 | + $locked_transactions = get_option('ee_locked_transactions', []); |
|
417 | + $update = false; |
|
418 | + foreach ($transaction_IDs as $TXN_ID) { |
|
419 | + if (isset($locked_transactions[ $TXN_ID ])) { |
|
420 | + unset($locked_transactions[ $TXN_ID ]); |
|
421 | + $update = true; |
|
422 | + } |
|
423 | + } |
|
424 | + if ($update) { |
|
425 | + update_option('ee_locked_transactions', $locked_transactions); |
|
426 | + } |
|
427 | + |
|
428 | + return $update; |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * returns an array of EE_Transaction objects whose timestamp is greater than |
|
434 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
435 | + * |
|
436 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
437 | + * @throws EE_Error |
|
438 | + * @throws InvalidArgumentException |
|
439 | + * @throws InvalidDataTypeException |
|
440 | + * @throws InvalidInterfaceException |
|
441 | + */ |
|
442 | + public function get_transactions_in_progress() |
|
443 | + { |
|
444 | + return $this->_get_transactions_in_progress(); |
|
445 | + } |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * returns an array of EE_Transaction objects whose timestamp is less than |
|
450 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
451 | + * |
|
452 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
453 | + * @throws EE_Error |
|
454 | + * @throws InvalidArgumentException |
|
455 | + * @throws InvalidDataTypeException |
|
456 | + * @throws InvalidInterfaceException |
|
457 | + */ |
|
458 | + public function get_transactions_not_in_progress() |
|
459 | + { |
|
460 | + return $this->_get_transactions_in_progress('<='); |
|
461 | + } |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * @param string $comparison |
|
466 | + * @return EE_Transaction[] |
|
467 | + * @throws EE_Error |
|
468 | + * @throws InvalidArgumentException |
|
469 | + * @throws InvalidDataTypeException |
|
470 | + * @throws InvalidInterfaceException |
|
471 | + */ |
|
472 | + private function _get_transactions_in_progress($comparison = '>=') |
|
473 | + { |
|
474 | + $comparison = $comparison === '>=' || $comparison === '<=' |
|
475 | + ? $comparison |
|
476 | + : '>='; |
|
477 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
478 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
479 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
480 | + ); |
|
481 | + return $this->get_all( |
|
482 | + [ |
|
483 | + [ |
|
484 | + 'TXN_timestamp' => [ |
|
485 | + $comparison, |
|
486 | + $session_lifespan->expiration(), |
|
487 | + ], |
|
488 | + 'STS_ID' => [ |
|
489 | + '!=', |
|
490 | + EEM_Transaction::complete_status_code, |
|
491 | + ], |
|
492 | + ], |
|
493 | + ] |
|
494 | + ); |
|
495 | + } |
|
496 | 496 | } |
@@ -3,36 +3,36 @@ |
||
3 | 3 | class EE_Foreign_Key_Int_Field extends EE_Foreign_Key_Field_Base |
4 | 4 | { |
5 | 5 | |
6 | - /** |
|
7 | - * @param string $table_column name fo column for field |
|
8 | - * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
9 | - * @param boolean $nullable |
|
10 | - * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
11 | - * dbe a string |
|
12 | - * @param string|string[] $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
13 | - * "EEM_" |
|
14 | - */ |
|
15 | - public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
16 | - { |
|
17 | - parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
18 | - $this->setSchemaType('integer'); |
|
19 | - } |
|
6 | + /** |
|
7 | + * @param string $table_column name fo column for field |
|
8 | + * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
9 | + * @param boolean $nullable |
|
10 | + * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
11 | + * dbe a string |
|
12 | + * @param string|string[] $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
13 | + * "EEM_" |
|
14 | + */ |
|
15 | + public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
16 | + { |
|
17 | + parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
18 | + $this->setSchemaType('integer'); |
|
19 | + } |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
24 | - * @return int |
|
25 | - */ |
|
26 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
27 | - { |
|
28 | - if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
29 | - $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
30 | - } |
|
31 | - return absint($value_inputted_for_field_on_model_object); |
|
32 | - } |
|
22 | + /** |
|
23 | + * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
24 | + * @return int |
|
25 | + */ |
|
26 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
27 | + { |
|
28 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
29 | + $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
30 | + } |
|
31 | + return absint($value_inputted_for_field_on_model_object); |
|
32 | + } |
|
33 | 33 | |
34 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
35 | - { |
|
36 | - return intval($value_found_in_db_for_model_object); |
|
37 | - } |
|
34 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
35 | + { |
|
36 | + return intval($value_found_in_db_for_model_object); |
|
37 | + } |
|
38 | 38 | } |
@@ -13,39 +13,39 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_WP_User_Field extends EE_Foreign_Key_Int_Field |
15 | 15 | { |
16 | - /** |
|
17 | - * No need to provide a default or the model pointed to- the default is |
|
18 | - * always get_current_user_id() and the model pointed to is always WP_User |
|
19 | - * |
|
20 | - * @param string $table_column name fo column for field |
|
21 | - * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
22 | - * @param boolean $nullable |
|
23 | - */ |
|
24 | - public function __construct($table_column, $nicename, $nullable) |
|
25 | - { |
|
26 | - parent::__construct($table_column, $nicename, $nullable, null, 'WP_User'); |
|
27 | - } |
|
16 | + /** |
|
17 | + * No need to provide a default or the model pointed to- the default is |
|
18 | + * always get_current_user_id() and the model pointed to is always WP_User |
|
19 | + * |
|
20 | + * @param string $table_column name fo column for field |
|
21 | + * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
22 | + * @param boolean $nullable |
|
23 | + */ |
|
24 | + public function __construct($table_column, $nicename, $nullable) |
|
25 | + { |
|
26 | + parent::__construct($table_column, $nicename, $nullable, null, 'WP_User'); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Gets the default which is always the current user. This can't be set when initially |
|
31 | - * constructing the model field because that's done before $current_user is set |
|
32 | - * |
|
33 | - * @return mixed |
|
34 | - */ |
|
35 | - public function get_default_value() |
|
36 | - { |
|
37 | - if (did_action('init')) { |
|
38 | - return get_current_user_id(); |
|
39 | - } else { |
|
40 | - EE_Error::doing_it_wrong( |
|
41 | - 'EE_WP_User_Field::get_default_value', |
|
42 | - esc_html__( |
|
43 | - 'You cant get a default value for a wp_User_Field because the "init" action is called, because current_user global hasnt yet been setup. Consider doing your business logic on the "init" hook or later.', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - '4.6.20' |
|
47 | - ); |
|
48 | - return 1; |
|
49 | - } |
|
50 | - } |
|
29 | + /** |
|
30 | + * Gets the default which is always the current user. This can't be set when initially |
|
31 | + * constructing the model field because that's done before $current_user is set |
|
32 | + * |
|
33 | + * @return mixed |
|
34 | + */ |
|
35 | + public function get_default_value() |
|
36 | + { |
|
37 | + if (did_action('init')) { |
|
38 | + return get_current_user_id(); |
|
39 | + } else { |
|
40 | + EE_Error::doing_it_wrong( |
|
41 | + 'EE_WP_User_Field::get_default_value', |
|
42 | + esc_html__( |
|
43 | + 'You cant get a default value for a wp_User_Field because the "init" action is called, because current_user global hasnt yet been setup. Consider doing your business logic on the "init" hook or later.', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + '4.6.20' |
|
47 | + ); |
|
48 | + return 1; |
|
49 | + } |
|
50 | + } |
|
51 | 51 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | public static function instance() |
43 | 43 | { |
44 | 44 | // check if class object is instantiated |
45 | - if (! self::$_instance instanceof EE_Transaction_Payments) { |
|
45 | + if ( ! self::$_instance instanceof EE_Transaction_Payments) { |
|
46 | 46 | self::$_instance = new self(); |
47 | 47 | } |
48 | 48 | return self::$_instance; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true) |
62 | 62 | { |
63 | 63 | $total_line_item = $transaction->total_line_item(); |
64 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
64 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
65 | 65 | EE_Error::add_error( |
66 | 66 | sprintf( |
67 | 67 | esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'), |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true) |
101 | 101 | { |
102 | 102 | // verify transaction |
103 | - if (! $transaction instanceof EE_Transaction) { |
|
103 | + if ( ! $transaction instanceof EE_Transaction) { |
|
104 | 104 | EE_Error::add_error( |
105 | 105 | esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
106 | 106 | __FILE__, |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) { |
116 | 116 | $transaction->set_paid($total_paid); |
117 | 117 | // maybe update status, and make sure to save transaction if not done already |
118 | - if (! $transaction->update_status_based_on_total_paid($update_txn)) { |
|
118 | + if ( ! $transaction->update_status_based_on_total_paid($update_txn)) { |
|
119 | 119 | if ($update_txn) { |
120 | 120 | return $transaction->save() ? true : false; |
121 | 121 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $payment_status = EEM_Payment::status_id_approved |
145 | 145 | ) { |
146 | 146 | // verify transaction |
147 | - if (! $transaction instanceof EE_Transaction) { |
|
147 | + if ( ! $transaction instanceof EE_Transaction) { |
|
148 | 148 | EE_Error::add_error( |
149 | 149 | esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
150 | 150 | __FILE__, |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | public function delete_payment_and_update_transaction(EE_Payment $payment) |
178 | 178 | { |
179 | 179 | // verify payment |
180 | - if (! $payment instanceof EE_Payment) { |
|
180 | + if ( ! $payment instanceof EE_Payment) { |
|
181 | 181 | EE_Error::add_error( |
182 | 182 | esc_html__('A valid Payment object was not received.', 'event_espresso'), |
183 | 183 | __FILE__, |
@@ -186,10 +186,10 @@ discard block |
||
186 | 186 | ); |
187 | 187 | return false; |
188 | 188 | } |
189 | - if (! $this->delete_registration_payments_and_update_registrations($payment)) { |
|
189 | + if ( ! $this->delete_registration_payments_and_update_registrations($payment)) { |
|
190 | 190 | return false; |
191 | 191 | } |
192 | - if (! $payment->delete()) { |
|
192 | + if ( ! $payment->delete()) { |
|
193 | 193 | EE_Error::add_error( |
194 | 194 | esc_html__('The payment could not be deleted.', 'event_espresso'), |
195 | 195 | __FILE__, |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | |
214 | 214 | // if this fails, that just means that the transaction didn't get its status changed and/or updated. |
215 | 215 | // however the payment was still deleted. |
216 | - if (! $this->calculate_total_payments_and_update_status($transaction)) { |
|
216 | + if ( ! $this->calculate_total_payments_and_update_status($transaction)) { |
|
217 | 217 | EE_Error::add_attention( |
218 | 218 | esc_html__( |
219 | 219 | 'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..', |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | $reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params |
256 | 256 | : array(array('PAY_ID' => $payment->ID())); |
257 | 257 | $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params); |
258 | - if (! empty($registration_payments)) { |
|
258 | + if ( ! empty($registration_payments)) { |
|
259 | 259 | foreach ($registration_payments as $registration_payment) { |
260 | 260 | if ($registration_payment instanceof EE_Registration_Payment) { |
261 | 261 | $amount_paid = $registration_payment->amount(); |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true) |
322 | 322 | { |
323 | 323 | EE_Error::doing_it_wrong( |
324 | - __CLASS__ . '::' . __FUNCTION__, |
|
324 | + __CLASS__.'::'.__FUNCTION__, |
|
325 | 325 | sprintf( |
326 | 326 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
327 | 327 | 'EE_Transaction::update_status_based_on_total_paid()' |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | '5.0.0' |
331 | 331 | ); |
332 | 332 | // verify transaction |
333 | - if (! $transaction instanceof EE_Transaction) { |
|
333 | + if ( ! $transaction instanceof EE_Transaction) { |
|
334 | 334 | EE_Error::add_error( |
335 | 335 | esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
336 | 336 | __FILE__, |
@@ -14,424 +14,424 @@ |
||
14 | 14 | */ |
15 | 15 | class EE_Transaction_Payments |
16 | 16 | { |
17 | - /** |
|
18 | - * @var EE_Transaction_Payments $_instance |
|
19 | - * @access private |
|
20 | - */ |
|
21 | - private static $_instance; |
|
22 | - |
|
23 | - /** |
|
24 | - * @deprecated |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $_old_txn_status; |
|
28 | - |
|
29 | - /** |
|
30 | - * @deprecated |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $_new_txn_status; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @singleton method used to instantiate class object |
|
38 | - * @access public |
|
39 | - * @return EE_Transaction_Payments instance |
|
40 | - */ |
|
41 | - public static function instance() |
|
42 | - { |
|
43 | - // check if class object is instantiated |
|
44 | - if (! self::$_instance instanceof EE_Transaction_Payments) { |
|
45 | - self::$_instance = new self(); |
|
46 | - } |
|
47 | - return self::$_instance; |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * recalculate_transaction_total |
|
53 | - * |
|
54 | - * @access private |
|
55 | - * @param EE_Transaction $transaction |
|
56 | - * @param bool $update_txn |
|
57 | - * @return bool true if TXN total was updated, false if not |
|
58 | - * @throws \EE_Error |
|
59 | - */ |
|
60 | - public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true) |
|
61 | - { |
|
62 | - $total_line_item = $transaction->total_line_item(); |
|
63 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
64 | - EE_Error::add_error( |
|
65 | - sprintf( |
|
66 | - esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'), |
|
67 | - $transaction->ID() |
|
68 | - ), |
|
69 | - __FILE__, |
|
70 | - __FUNCTION__, |
|
71 | - __LINE__ |
|
72 | - ); |
|
73 | - return false; |
|
74 | - } |
|
75 | - $new_total = $total_line_item->recalculate_total_including_taxes(); |
|
76 | - $transaction->set_total($new_total); |
|
77 | - if ($update_txn) { |
|
78 | - return $transaction->save() ? true : false; |
|
79 | - } |
|
80 | - return false; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Updates the provided EE_Transaction with all the applicable payments |
|
86 | - * returns a boolean for whether the TXN was saved to the db |
|
87 | - * (meaning a status change occurred) |
|
88 | - * or not saved (which could **still** mean that |
|
89 | - * the TXN status changed, but just was not yet saved). |
|
90 | - * So if passing a value of false for the $update_txn param, |
|
91 | - * then client code needs to take responsibility for saving the TXN |
|
92 | - * regardless of what happens within EE_Transaction_Payments; |
|
93 | - * |
|
94 | - * @param EE_Transaction /int $transaction_obj_or_id EE_Transaction or its ID |
|
95 | - * @param boolean $update_txn whether to save the TXN |
|
96 | - * @return boolean whether the TXN was saved |
|
97 | - * @throws \EE_Error |
|
98 | - */ |
|
99 | - public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true) |
|
100 | - { |
|
101 | - // verify transaction |
|
102 | - if (! $transaction instanceof EE_Transaction) { |
|
103 | - EE_Error::add_error( |
|
104 | - esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
|
105 | - __FILE__, |
|
106 | - __FUNCTION__, |
|
107 | - __LINE__ |
|
108 | - ); |
|
109 | - return false; |
|
110 | - } |
|
111 | - // calculate total paid |
|
112 | - $total_paid = $this->recalculate_total_payments_for_transaction($transaction); |
|
113 | - // if total paid has changed |
|
114 | - if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) { |
|
115 | - $transaction->set_paid($total_paid); |
|
116 | - // maybe update status, and make sure to save transaction if not done already |
|
117 | - if (! $transaction->update_status_based_on_total_paid($update_txn)) { |
|
118 | - if ($update_txn) { |
|
119 | - return $transaction->save() ? true : false; |
|
120 | - } |
|
121 | - } else { |
|
122 | - // the status got updated and was saved by |
|
123 | - // update_transaction_status_based_on_total_paid() |
|
124 | - return true; |
|
125 | - } |
|
126 | - } |
|
127 | - return false; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * recalculate_total_payments_for_transaction |
|
133 | - * |
|
134 | - * @access public |
|
135 | - * @param EE_Transaction $transaction |
|
136 | - * @param string $payment_status One of EEM_Payment's statuses, like 'PAP' (Approved). |
|
137 | - * By default, searches for approved payments |
|
138 | - * @return float|false float on success, false on fail |
|
139 | - * @throws \EE_Error |
|
140 | - */ |
|
141 | - public function recalculate_total_payments_for_transaction( |
|
142 | - EE_Transaction $transaction, |
|
143 | - $payment_status = EEM_Payment::status_id_approved |
|
144 | - ) { |
|
145 | - // verify transaction |
|
146 | - if (! $transaction instanceof EE_Transaction) { |
|
147 | - EE_Error::add_error( |
|
148 | - esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
|
149 | - __FILE__, |
|
150 | - __FUNCTION__, |
|
151 | - __LINE__ |
|
152 | - ); |
|
153 | - return false; |
|
154 | - } |
|
155 | - // ensure Payment model is loaded |
|
156 | - EE_Registry::instance()->load_model('Payment'); |
|
157 | - // calls EEM_Base::sum() |
|
158 | - return EEM_Payment::instance()->sum( |
|
159 | - // query params |
|
160 | - array(array('TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status)), |
|
161 | - // field to sum |
|
162 | - 'PAY_amount' |
|
163 | - ); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * delete_payment_and_update_transaction |
|
169 | - * Before deleting the selected payment, we fetch it's transaction, |
|
170 | - * then delete the payment, and update the transactions' amount paid. |
|
171 | - * |
|
172 | - * @param EE_Payment $payment |
|
173 | - * @return boolean |
|
174 | - * @throws \EE_Error |
|
175 | - */ |
|
176 | - public function delete_payment_and_update_transaction(EE_Payment $payment) |
|
177 | - { |
|
178 | - // verify payment |
|
179 | - if (! $payment instanceof EE_Payment) { |
|
180 | - EE_Error::add_error( |
|
181 | - esc_html__('A valid Payment object was not received.', 'event_espresso'), |
|
182 | - __FILE__, |
|
183 | - __FUNCTION__, |
|
184 | - __LINE__ |
|
185 | - ); |
|
186 | - return false; |
|
187 | - } |
|
188 | - if (! $this->delete_registration_payments_and_update_registrations($payment)) { |
|
189 | - return false; |
|
190 | - } |
|
191 | - if (! $payment->delete()) { |
|
192 | - EE_Error::add_error( |
|
193 | - esc_html__('The payment could not be deleted.', 'event_espresso'), |
|
194 | - __FILE__, |
|
195 | - __FUNCTION__, |
|
196 | - __LINE__ |
|
197 | - ); |
|
198 | - return false; |
|
199 | - } |
|
200 | - |
|
201 | - $transaction = $payment->transaction(); |
|
202 | - $TXN_status = $transaction->status_ID(); |
|
203 | - if ( |
|
204 | - $TXN_status === EEM_Transaction::abandoned_status_code |
|
205 | - || $TXN_status === EEM_Transaction::failed_status_code |
|
206 | - || $payment->amount() === 0 |
|
207 | - ) { |
|
208 | - EE_Error::add_success(esc_html__('The Payment was successfully deleted.', 'event_espresso')); |
|
209 | - return true; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - // if this fails, that just means that the transaction didn't get its status changed and/or updated. |
|
214 | - // however the payment was still deleted. |
|
215 | - if (! $this->calculate_total_payments_and_update_status($transaction)) { |
|
216 | - EE_Error::add_attention( |
|
217 | - esc_html__( |
|
218 | - 'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..', |
|
219 | - 'event_espresso' |
|
220 | - ), |
|
221 | - __FILE__, |
|
222 | - __FUNCTION__, |
|
223 | - __LINE__ |
|
224 | - ); |
|
225 | - return true; |
|
226 | - } |
|
227 | - |
|
228 | - EE_Error::add_success( |
|
229 | - esc_html__( |
|
230 | - 'The Payment was successfully deleted, and the Transaction has been updated accordingly.', |
|
231 | - 'event_espresso' |
|
232 | - ) |
|
233 | - ); |
|
234 | - return true; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * delete_registration_payments_and_update_registrations |
|
240 | - * |
|
241 | - * removes all registration payment records associated with a payment |
|
242 | - * and subtracts their amounts from the corresponding registrations REG_paid field |
|
243 | - * |
|
244 | - * @param EE_Payment $payment |
|
245 | - * @param array $reg_payment_query_params |
|
246 | - * @return bool |
|
247 | - * @throws \EE_Error |
|
248 | - */ |
|
249 | - public function delete_registration_payments_and_update_registrations( |
|
250 | - EE_Payment $payment, |
|
251 | - $reg_payment_query_params = array() |
|
252 | - ) { |
|
253 | - $save_payment = false; |
|
254 | - $reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params |
|
255 | - : array(array('PAY_ID' => $payment->ID())); |
|
256 | - $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params); |
|
257 | - if (! empty($registration_payments)) { |
|
258 | - foreach ($registration_payments as $registration_payment) { |
|
259 | - if ($registration_payment instanceof EE_Registration_Payment) { |
|
260 | - $amount_paid = $registration_payment->amount(); |
|
261 | - $registration = $registration_payment->registration(); |
|
262 | - if ($registration instanceof EE_Registration) { |
|
263 | - $registration->set_paid($registration->paid() - $amount_paid); |
|
264 | - if ($registration->save() !== false) { |
|
265 | - $registration_payment->delete_permanently(); |
|
266 | - $save_payment = true; |
|
267 | - } |
|
268 | - } else { |
|
269 | - EE_Error::add_error( |
|
270 | - sprintf( |
|
271 | - esc_html__( |
|
272 | - 'An invalid Registration object was associated with Registration Payment ID# %1$d.', |
|
273 | - 'event_espresso' |
|
274 | - ), |
|
275 | - $registration_payment->ID() |
|
276 | - ), |
|
277 | - __FILE__, |
|
278 | - __FUNCTION__, |
|
279 | - __LINE__ |
|
280 | - ); |
|
281 | - return false; |
|
282 | - } |
|
283 | - } else { |
|
284 | - EE_Error::add_error( |
|
285 | - sprintf( |
|
286 | - esc_html__( |
|
287 | - 'An invalid Registration Payment object was associated with payment ID# %1$d.', |
|
288 | - 'event_espresso' |
|
289 | - ), |
|
290 | - $payment->ID() |
|
291 | - ), |
|
292 | - __FILE__, |
|
293 | - __FUNCTION__, |
|
294 | - __LINE__ |
|
295 | - ); |
|
296 | - return false; |
|
297 | - } |
|
298 | - } |
|
299 | - } |
|
300 | - if ($save_payment) { |
|
301 | - $payment->save(); |
|
302 | - } |
|
303 | - return true; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - |
|
308 | - /********************************** DEPRECATED METHODS **********************************/ |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * possibly toggles TXN status |
|
313 | - * |
|
314 | - * @deprecated 4.9.1 |
|
315 | - * @param EE_Transaction $transaction |
|
316 | - * @param boolean $update_txn whether to save the TXN |
|
317 | - * @return boolean whether the TXN was saved |
|
318 | - * @throws \EE_Error |
|
319 | - */ |
|
320 | - public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true) |
|
321 | - { |
|
322 | - EE_Error::doing_it_wrong( |
|
323 | - __CLASS__ . '::' . __FUNCTION__, |
|
324 | - sprintf( |
|
325 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
326 | - 'EE_Transaction::update_status_based_on_total_paid()' |
|
327 | - ), |
|
328 | - '4.9.1', |
|
329 | - '5.0.0' |
|
330 | - ); |
|
331 | - // verify transaction |
|
332 | - if (! $transaction instanceof EE_Transaction) { |
|
333 | - EE_Error::add_error( |
|
334 | - esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
|
335 | - __FILE__, |
|
336 | - __FUNCTION__, |
|
337 | - __LINE__ |
|
338 | - ); |
|
339 | - return false; |
|
340 | - } |
|
341 | - // set transaction status based on comparison of TXN_paid vs TXN_total |
|
342 | - return $transaction->update_status_based_on_total_paid($update_txn); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * @deprecated 4.9.12 |
|
348 | - * @return string |
|
349 | - */ |
|
350 | - public function old_txn_status() |
|
351 | - { |
|
352 | - EE_Error::doing_it_wrong( |
|
353 | - __METHOD__, |
|
354 | - esc_html__( |
|
355 | - 'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.', |
|
356 | - 'event_espresso' |
|
357 | - ), |
|
358 | - '4.9.12' |
|
359 | - ); |
|
360 | - return $this->_old_txn_status; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * @deprecated 4.9.12 |
|
366 | - * @param string $old_txn_status |
|
367 | - */ |
|
368 | - public function set_old_txn_status($old_txn_status) |
|
369 | - { |
|
370 | - EE_Error::doing_it_wrong( |
|
371 | - __METHOD__, |
|
372 | - esc_html__( |
|
373 | - 'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.', |
|
374 | - 'event_espresso' |
|
375 | - ), |
|
376 | - '4.9.12' |
|
377 | - ); |
|
378 | - // only set the first time |
|
379 | - if ($this->_old_txn_status === null) { |
|
380 | - $this->_old_txn_status = $old_txn_status; |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * @deprecated 4.9.12 |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function new_txn_status() |
|
390 | - { |
|
391 | - EE_Error::doing_it_wrong( |
|
392 | - __METHOD__, |
|
393 | - esc_html__( |
|
394 | - 'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.', |
|
395 | - 'event_espresso' |
|
396 | - ), |
|
397 | - '4.9.12' |
|
398 | - ); |
|
399 | - return $this->_new_txn_status; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * @deprecated 4.9.12 |
|
405 | - * @param string $new_txn_status |
|
406 | - */ |
|
407 | - public function set_new_txn_status($new_txn_status) |
|
408 | - { |
|
409 | - EE_Error::doing_it_wrong( |
|
410 | - __METHOD__, |
|
411 | - esc_html__( |
|
412 | - 'This logic has been removed. Please just use \EE_Transaction::set_status() instead.', |
|
413 | - 'event_espresso' |
|
414 | - ), |
|
415 | - '4.9.12' |
|
416 | - ); |
|
417 | - $this->_new_txn_status = $new_txn_status; |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * @deprecated 4.9.12 |
|
423 | - * @return bool |
|
424 | - */ |
|
425 | - public function txn_status_updated() |
|
426 | - { |
|
427 | - EE_Error::doing_it_wrong( |
|
428 | - __METHOD__, |
|
429 | - esc_html__( |
|
430 | - 'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.', |
|
431 | - 'event_espresso' |
|
432 | - ), |
|
433 | - '4.9.12' |
|
434 | - ); |
|
435 | - return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false; |
|
436 | - } |
|
17 | + /** |
|
18 | + * @var EE_Transaction_Payments $_instance |
|
19 | + * @access private |
|
20 | + */ |
|
21 | + private static $_instance; |
|
22 | + |
|
23 | + /** |
|
24 | + * @deprecated |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $_old_txn_status; |
|
28 | + |
|
29 | + /** |
|
30 | + * @deprecated |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $_new_txn_status; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @singleton method used to instantiate class object |
|
38 | + * @access public |
|
39 | + * @return EE_Transaction_Payments instance |
|
40 | + */ |
|
41 | + public static function instance() |
|
42 | + { |
|
43 | + // check if class object is instantiated |
|
44 | + if (! self::$_instance instanceof EE_Transaction_Payments) { |
|
45 | + self::$_instance = new self(); |
|
46 | + } |
|
47 | + return self::$_instance; |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * recalculate_transaction_total |
|
53 | + * |
|
54 | + * @access private |
|
55 | + * @param EE_Transaction $transaction |
|
56 | + * @param bool $update_txn |
|
57 | + * @return bool true if TXN total was updated, false if not |
|
58 | + * @throws \EE_Error |
|
59 | + */ |
|
60 | + public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true) |
|
61 | + { |
|
62 | + $total_line_item = $transaction->total_line_item(); |
|
63 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
64 | + EE_Error::add_error( |
|
65 | + sprintf( |
|
66 | + esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'), |
|
67 | + $transaction->ID() |
|
68 | + ), |
|
69 | + __FILE__, |
|
70 | + __FUNCTION__, |
|
71 | + __LINE__ |
|
72 | + ); |
|
73 | + return false; |
|
74 | + } |
|
75 | + $new_total = $total_line_item->recalculate_total_including_taxes(); |
|
76 | + $transaction->set_total($new_total); |
|
77 | + if ($update_txn) { |
|
78 | + return $transaction->save() ? true : false; |
|
79 | + } |
|
80 | + return false; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Updates the provided EE_Transaction with all the applicable payments |
|
86 | + * returns a boolean for whether the TXN was saved to the db |
|
87 | + * (meaning a status change occurred) |
|
88 | + * or not saved (which could **still** mean that |
|
89 | + * the TXN status changed, but just was not yet saved). |
|
90 | + * So if passing a value of false for the $update_txn param, |
|
91 | + * then client code needs to take responsibility for saving the TXN |
|
92 | + * regardless of what happens within EE_Transaction_Payments; |
|
93 | + * |
|
94 | + * @param EE_Transaction /int $transaction_obj_or_id EE_Transaction or its ID |
|
95 | + * @param boolean $update_txn whether to save the TXN |
|
96 | + * @return boolean whether the TXN was saved |
|
97 | + * @throws \EE_Error |
|
98 | + */ |
|
99 | + public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true) |
|
100 | + { |
|
101 | + // verify transaction |
|
102 | + if (! $transaction instanceof EE_Transaction) { |
|
103 | + EE_Error::add_error( |
|
104 | + esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
|
105 | + __FILE__, |
|
106 | + __FUNCTION__, |
|
107 | + __LINE__ |
|
108 | + ); |
|
109 | + return false; |
|
110 | + } |
|
111 | + // calculate total paid |
|
112 | + $total_paid = $this->recalculate_total_payments_for_transaction($transaction); |
|
113 | + // if total paid has changed |
|
114 | + if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) { |
|
115 | + $transaction->set_paid($total_paid); |
|
116 | + // maybe update status, and make sure to save transaction if not done already |
|
117 | + if (! $transaction->update_status_based_on_total_paid($update_txn)) { |
|
118 | + if ($update_txn) { |
|
119 | + return $transaction->save() ? true : false; |
|
120 | + } |
|
121 | + } else { |
|
122 | + // the status got updated and was saved by |
|
123 | + // update_transaction_status_based_on_total_paid() |
|
124 | + return true; |
|
125 | + } |
|
126 | + } |
|
127 | + return false; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * recalculate_total_payments_for_transaction |
|
133 | + * |
|
134 | + * @access public |
|
135 | + * @param EE_Transaction $transaction |
|
136 | + * @param string $payment_status One of EEM_Payment's statuses, like 'PAP' (Approved). |
|
137 | + * By default, searches for approved payments |
|
138 | + * @return float|false float on success, false on fail |
|
139 | + * @throws \EE_Error |
|
140 | + */ |
|
141 | + public function recalculate_total_payments_for_transaction( |
|
142 | + EE_Transaction $transaction, |
|
143 | + $payment_status = EEM_Payment::status_id_approved |
|
144 | + ) { |
|
145 | + // verify transaction |
|
146 | + if (! $transaction instanceof EE_Transaction) { |
|
147 | + EE_Error::add_error( |
|
148 | + esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
|
149 | + __FILE__, |
|
150 | + __FUNCTION__, |
|
151 | + __LINE__ |
|
152 | + ); |
|
153 | + return false; |
|
154 | + } |
|
155 | + // ensure Payment model is loaded |
|
156 | + EE_Registry::instance()->load_model('Payment'); |
|
157 | + // calls EEM_Base::sum() |
|
158 | + return EEM_Payment::instance()->sum( |
|
159 | + // query params |
|
160 | + array(array('TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status)), |
|
161 | + // field to sum |
|
162 | + 'PAY_amount' |
|
163 | + ); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * delete_payment_and_update_transaction |
|
169 | + * Before deleting the selected payment, we fetch it's transaction, |
|
170 | + * then delete the payment, and update the transactions' amount paid. |
|
171 | + * |
|
172 | + * @param EE_Payment $payment |
|
173 | + * @return boolean |
|
174 | + * @throws \EE_Error |
|
175 | + */ |
|
176 | + public function delete_payment_and_update_transaction(EE_Payment $payment) |
|
177 | + { |
|
178 | + // verify payment |
|
179 | + if (! $payment instanceof EE_Payment) { |
|
180 | + EE_Error::add_error( |
|
181 | + esc_html__('A valid Payment object was not received.', 'event_espresso'), |
|
182 | + __FILE__, |
|
183 | + __FUNCTION__, |
|
184 | + __LINE__ |
|
185 | + ); |
|
186 | + return false; |
|
187 | + } |
|
188 | + if (! $this->delete_registration_payments_and_update_registrations($payment)) { |
|
189 | + return false; |
|
190 | + } |
|
191 | + if (! $payment->delete()) { |
|
192 | + EE_Error::add_error( |
|
193 | + esc_html__('The payment could not be deleted.', 'event_espresso'), |
|
194 | + __FILE__, |
|
195 | + __FUNCTION__, |
|
196 | + __LINE__ |
|
197 | + ); |
|
198 | + return false; |
|
199 | + } |
|
200 | + |
|
201 | + $transaction = $payment->transaction(); |
|
202 | + $TXN_status = $transaction->status_ID(); |
|
203 | + if ( |
|
204 | + $TXN_status === EEM_Transaction::abandoned_status_code |
|
205 | + || $TXN_status === EEM_Transaction::failed_status_code |
|
206 | + || $payment->amount() === 0 |
|
207 | + ) { |
|
208 | + EE_Error::add_success(esc_html__('The Payment was successfully deleted.', 'event_espresso')); |
|
209 | + return true; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + // if this fails, that just means that the transaction didn't get its status changed and/or updated. |
|
214 | + // however the payment was still deleted. |
|
215 | + if (! $this->calculate_total_payments_and_update_status($transaction)) { |
|
216 | + EE_Error::add_attention( |
|
217 | + esc_html__( |
|
218 | + 'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..', |
|
219 | + 'event_espresso' |
|
220 | + ), |
|
221 | + __FILE__, |
|
222 | + __FUNCTION__, |
|
223 | + __LINE__ |
|
224 | + ); |
|
225 | + return true; |
|
226 | + } |
|
227 | + |
|
228 | + EE_Error::add_success( |
|
229 | + esc_html__( |
|
230 | + 'The Payment was successfully deleted, and the Transaction has been updated accordingly.', |
|
231 | + 'event_espresso' |
|
232 | + ) |
|
233 | + ); |
|
234 | + return true; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * delete_registration_payments_and_update_registrations |
|
240 | + * |
|
241 | + * removes all registration payment records associated with a payment |
|
242 | + * and subtracts their amounts from the corresponding registrations REG_paid field |
|
243 | + * |
|
244 | + * @param EE_Payment $payment |
|
245 | + * @param array $reg_payment_query_params |
|
246 | + * @return bool |
|
247 | + * @throws \EE_Error |
|
248 | + */ |
|
249 | + public function delete_registration_payments_and_update_registrations( |
|
250 | + EE_Payment $payment, |
|
251 | + $reg_payment_query_params = array() |
|
252 | + ) { |
|
253 | + $save_payment = false; |
|
254 | + $reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params |
|
255 | + : array(array('PAY_ID' => $payment->ID())); |
|
256 | + $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params); |
|
257 | + if (! empty($registration_payments)) { |
|
258 | + foreach ($registration_payments as $registration_payment) { |
|
259 | + if ($registration_payment instanceof EE_Registration_Payment) { |
|
260 | + $amount_paid = $registration_payment->amount(); |
|
261 | + $registration = $registration_payment->registration(); |
|
262 | + if ($registration instanceof EE_Registration) { |
|
263 | + $registration->set_paid($registration->paid() - $amount_paid); |
|
264 | + if ($registration->save() !== false) { |
|
265 | + $registration_payment->delete_permanently(); |
|
266 | + $save_payment = true; |
|
267 | + } |
|
268 | + } else { |
|
269 | + EE_Error::add_error( |
|
270 | + sprintf( |
|
271 | + esc_html__( |
|
272 | + 'An invalid Registration object was associated with Registration Payment ID# %1$d.', |
|
273 | + 'event_espresso' |
|
274 | + ), |
|
275 | + $registration_payment->ID() |
|
276 | + ), |
|
277 | + __FILE__, |
|
278 | + __FUNCTION__, |
|
279 | + __LINE__ |
|
280 | + ); |
|
281 | + return false; |
|
282 | + } |
|
283 | + } else { |
|
284 | + EE_Error::add_error( |
|
285 | + sprintf( |
|
286 | + esc_html__( |
|
287 | + 'An invalid Registration Payment object was associated with payment ID# %1$d.', |
|
288 | + 'event_espresso' |
|
289 | + ), |
|
290 | + $payment->ID() |
|
291 | + ), |
|
292 | + __FILE__, |
|
293 | + __FUNCTION__, |
|
294 | + __LINE__ |
|
295 | + ); |
|
296 | + return false; |
|
297 | + } |
|
298 | + } |
|
299 | + } |
|
300 | + if ($save_payment) { |
|
301 | + $payment->save(); |
|
302 | + } |
|
303 | + return true; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + |
|
308 | + /********************************** DEPRECATED METHODS **********************************/ |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * possibly toggles TXN status |
|
313 | + * |
|
314 | + * @deprecated 4.9.1 |
|
315 | + * @param EE_Transaction $transaction |
|
316 | + * @param boolean $update_txn whether to save the TXN |
|
317 | + * @return boolean whether the TXN was saved |
|
318 | + * @throws \EE_Error |
|
319 | + */ |
|
320 | + public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true) |
|
321 | + { |
|
322 | + EE_Error::doing_it_wrong( |
|
323 | + __CLASS__ . '::' . __FUNCTION__, |
|
324 | + sprintf( |
|
325 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
326 | + 'EE_Transaction::update_status_based_on_total_paid()' |
|
327 | + ), |
|
328 | + '4.9.1', |
|
329 | + '5.0.0' |
|
330 | + ); |
|
331 | + // verify transaction |
|
332 | + if (! $transaction instanceof EE_Transaction) { |
|
333 | + EE_Error::add_error( |
|
334 | + esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
|
335 | + __FILE__, |
|
336 | + __FUNCTION__, |
|
337 | + __LINE__ |
|
338 | + ); |
|
339 | + return false; |
|
340 | + } |
|
341 | + // set transaction status based on comparison of TXN_paid vs TXN_total |
|
342 | + return $transaction->update_status_based_on_total_paid($update_txn); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * @deprecated 4.9.12 |
|
348 | + * @return string |
|
349 | + */ |
|
350 | + public function old_txn_status() |
|
351 | + { |
|
352 | + EE_Error::doing_it_wrong( |
|
353 | + __METHOD__, |
|
354 | + esc_html__( |
|
355 | + 'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.', |
|
356 | + 'event_espresso' |
|
357 | + ), |
|
358 | + '4.9.12' |
|
359 | + ); |
|
360 | + return $this->_old_txn_status; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * @deprecated 4.9.12 |
|
366 | + * @param string $old_txn_status |
|
367 | + */ |
|
368 | + public function set_old_txn_status($old_txn_status) |
|
369 | + { |
|
370 | + EE_Error::doing_it_wrong( |
|
371 | + __METHOD__, |
|
372 | + esc_html__( |
|
373 | + 'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.', |
|
374 | + 'event_espresso' |
|
375 | + ), |
|
376 | + '4.9.12' |
|
377 | + ); |
|
378 | + // only set the first time |
|
379 | + if ($this->_old_txn_status === null) { |
|
380 | + $this->_old_txn_status = $old_txn_status; |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * @deprecated 4.9.12 |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function new_txn_status() |
|
390 | + { |
|
391 | + EE_Error::doing_it_wrong( |
|
392 | + __METHOD__, |
|
393 | + esc_html__( |
|
394 | + 'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.', |
|
395 | + 'event_espresso' |
|
396 | + ), |
|
397 | + '4.9.12' |
|
398 | + ); |
|
399 | + return $this->_new_txn_status; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * @deprecated 4.9.12 |
|
405 | + * @param string $new_txn_status |
|
406 | + */ |
|
407 | + public function set_new_txn_status($new_txn_status) |
|
408 | + { |
|
409 | + EE_Error::doing_it_wrong( |
|
410 | + __METHOD__, |
|
411 | + esc_html__( |
|
412 | + 'This logic has been removed. Please just use \EE_Transaction::set_status() instead.', |
|
413 | + 'event_espresso' |
|
414 | + ), |
|
415 | + '4.9.12' |
|
416 | + ); |
|
417 | + $this->_new_txn_status = $new_txn_status; |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * @deprecated 4.9.12 |
|
423 | + * @return bool |
|
424 | + */ |
|
425 | + public function txn_status_updated() |
|
426 | + { |
|
427 | + EE_Error::doing_it_wrong( |
|
428 | + __METHOD__, |
|
429 | + esc_html__( |
|
430 | + 'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.', |
|
431 | + 'event_espresso' |
|
432 | + ), |
|
433 | + '4.9.12' |
|
434 | + ); |
|
435 | + return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false; |
|
436 | + } |
|
437 | 437 | } |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | if ($TKT_ID) { |
60 | 60 | $ticket = $this->ticket_model->get_one_by_ID($TKT_ID); |
61 | 61 | if ($ticket instanceof EE_Ticket) { |
62 | - $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> '; |
|
62 | + $ticket_details = '<span class="ee-ticket-name">'.$ticket->name().'</span> '; |
|
63 | 63 | $ticket_details .= ! $ticket->is_free() |
64 | - ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>' |
|
64 | + ? '<span class="ee-ticket-price">'.$ticket->pretty_price().'</span>' |
|
65 | 65 | : '<span class="reg-overview-free-event-spn">' |
66 | 66 | . esc_html__('free', 'event_espresso') |
67 | 67 | . '</span>'; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $text .= ' '; |
79 | 79 | $text .= '<span class="drk-grey-text" style="font-size:.9em;">'; |
80 | 80 | $text .= '<span class="dashicons dashicons-tickets-alt"></span>'; |
81 | - $text .= $ticket_details . '</span></h3>'; |
|
81 | + $text .= $ticket_details.'</span></h3>'; |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | return $text; |
@@ -22,64 +22,64 @@ |
||
22 | 22 | */ |
23 | 23 | class TicketFilterHeader extends AdminPageHeaderDecorator |
24 | 24 | { |
25 | - /** |
|
26 | - * @var EEM_Ticket $ticket_model |
|
27 | - */ |
|
28 | - private $ticket_model; |
|
25 | + /** |
|
26 | + * @var EEM_Ticket $ticket_model |
|
27 | + */ |
|
28 | + private $ticket_model; |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * TicketFilterHeader constructor. |
|
33 | - * |
|
34 | - * @param RequestInterface $request |
|
35 | - * @param EEM_Ticket $ticket_model |
|
36 | - */ |
|
37 | - public function __construct(RequestInterface $request, EEM_Ticket $ticket_model) |
|
38 | - { |
|
39 | - parent::__construct($request); |
|
40 | - $this->ticket_model = $ticket_model; |
|
41 | - } |
|
31 | + /** |
|
32 | + * TicketFilterHeader constructor. |
|
33 | + * |
|
34 | + * @param RequestInterface $request |
|
35 | + * @param EEM_Ticket $ticket_model |
|
36 | + */ |
|
37 | + public function __construct(RequestInterface $request, EEM_Ticket $ticket_model) |
|
38 | + { |
|
39 | + parent::__construct($request); |
|
40 | + $this->ticket_model = $ticket_model; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @param string $text |
|
46 | - * @return string |
|
47 | - * @throws EE_Error |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - * @throws InvalidInterfaceException |
|
50 | - * @throws InvalidArgumentException |
|
51 | - * @throws ReflectionException |
|
52 | - * @since 4.10.2.p |
|
53 | - */ |
|
54 | - public function getHeaderText($text = '') |
|
55 | - { |
|
56 | - $TKT_ID = $this->request->getRequestParam('TKT_ID'); |
|
57 | - $TKT_ID = $this->request->getRequestParam('ticket_id', $TKT_ID, 'int'); |
|
58 | - if ($TKT_ID) { |
|
59 | - $ticket = $this->ticket_model->get_one_by_ID($TKT_ID); |
|
60 | - if ($ticket instanceof EE_Ticket) { |
|
61 | - $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> '; |
|
62 | - $ticket_details .= ! $ticket->is_free() |
|
63 | - ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>' |
|
64 | - : '<span class="reg-overview-free-event-spn">' |
|
65 | - . esc_html__('free', 'event_espresso') |
|
66 | - . '</span>'; |
|
67 | - // remove the closing h3 heading tag if it exists |
|
68 | - $text = str_replace( |
|
69 | - '</h3>', |
|
70 | - '', |
|
71 | - $text |
|
72 | - ); |
|
73 | - if (empty($text)) { |
|
74 | - $text = '<h3 style="line-height:1.5em;">'; |
|
75 | - $text .= esc_html__('Viewing registrations for ticket:', 'event_espresso'); |
|
76 | - } |
|
77 | - $text .= ' '; |
|
78 | - $text .= '<span class="drk-grey-text" style="font-size:.9em;">'; |
|
79 | - $text .= '<span class="dashicons dashicons-tickets-alt"></span>'; |
|
80 | - $text .= $ticket_details . '</span></h3>'; |
|
81 | - } |
|
82 | - } |
|
83 | - return $text; |
|
84 | - } |
|
44 | + /** |
|
45 | + * @param string $text |
|
46 | + * @return string |
|
47 | + * @throws EE_Error |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + * @throws InvalidInterfaceException |
|
50 | + * @throws InvalidArgumentException |
|
51 | + * @throws ReflectionException |
|
52 | + * @since 4.10.2.p |
|
53 | + */ |
|
54 | + public function getHeaderText($text = '') |
|
55 | + { |
|
56 | + $TKT_ID = $this->request->getRequestParam('TKT_ID'); |
|
57 | + $TKT_ID = $this->request->getRequestParam('ticket_id', $TKT_ID, 'int'); |
|
58 | + if ($TKT_ID) { |
|
59 | + $ticket = $this->ticket_model->get_one_by_ID($TKT_ID); |
|
60 | + if ($ticket instanceof EE_Ticket) { |
|
61 | + $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> '; |
|
62 | + $ticket_details .= ! $ticket->is_free() |
|
63 | + ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>' |
|
64 | + : '<span class="reg-overview-free-event-spn">' |
|
65 | + . esc_html__('free', 'event_espresso') |
|
66 | + . '</span>'; |
|
67 | + // remove the closing h3 heading tag if it exists |
|
68 | + $text = str_replace( |
|
69 | + '</h3>', |
|
70 | + '', |
|
71 | + $text |
|
72 | + ); |
|
73 | + if (empty($text)) { |
|
74 | + $text = '<h3 style="line-height:1.5em;">'; |
|
75 | + $text .= esc_html__('Viewing registrations for ticket:', 'event_espresso'); |
|
76 | + } |
|
77 | + $text .= ' '; |
|
78 | + $text .= '<span class="drk-grey-text" style="font-size:.9em;">'; |
|
79 | + $text .= '<span class="dashicons dashicons-tickets-alt"></span>'; |
|
80 | + $text .= $ticket_details . '</span></h3>'; |
|
81 | + } |
|
82 | + } |
|
83 | + return $text; |
|
84 | + } |
|
85 | 85 | } |
@@ -67,12 +67,12 @@ discard block |
||
67 | 67 | public function heartbeatResponse($response = array(), $data = array()) |
68 | 68 | { |
69 | 69 | // does this heartbeat contain our data ? |
70 | - if (! isset($data[ $this->heartbeat ])) { |
|
70 | + if ( ! isset($data[$this->heartbeat])) { |
|
71 | 71 | return $response; |
72 | 72 | } |
73 | 73 | // check for reg_url_link in the incoming heartbeat data |
74 | - if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) { |
|
75 | - $response[ $this->heartbeat ] = array( |
|
74 | + if ( ! isset($data[$this->heartbeat]['e_reg_url_link'])) { |
|
75 | + $response[$this->heartbeat] = array( |
|
76 | 76 | 'errors' => ! empty($notices['errors']) |
77 | 77 | ? $notices['errors'] |
78 | 78 | : esc_html__( |
@@ -85,22 +85,22 @@ discard block |
||
85 | 85 | // kk heartbeat has our data |
86 | 86 | $response = $this->initializeThankYouPageAndTransaction($response, $data); |
87 | 87 | // if something went wrong... |
88 | - if (isset($response[ $this->heartbeat ]['errors'])) { |
|
88 | + if (isset($response[$this->heartbeat]['errors'])) { |
|
89 | 89 | return $response; |
90 | 90 | } |
91 | 91 | // grab transient of Transaction's status |
92 | - $txn_status = isset($data[ $this->heartbeat ]['txn_status']) |
|
93 | - ? $data[ $this->heartbeat ]['txn_status'] |
|
92 | + $txn_status = isset($data[$this->heartbeat]['txn_status']) |
|
93 | + ? $data[$this->heartbeat]['txn_status'] |
|
94 | 94 | : null; |
95 | 95 | $response = $this->getTransactionDetails($txn_status, $response, $data); |
96 | 96 | // no payment data yet? |
97 | - if (isset($response[ $this->heartbeat ]['still_waiting'])) { |
|
97 | + if (isset($response[$this->heartbeat]['still_waiting'])) { |
|
98 | 98 | return $response; |
99 | 99 | } |
100 | 100 | // TXN is happening so let's get the payments now |
101 | 101 | // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked |
102 | - $since = isset($data[ $this->heartbeat ]['get_payments_since']) |
|
103 | - ? $data[ $this->heartbeat ]['get_payments_since'] |
|
102 | + $since = isset($data[$this->heartbeat]['get_payments_since']) |
|
103 | + ? $data[$this->heartbeat]['get_payments_since'] |
|
104 | 104 | : 0; |
105 | 105 | return $this->paymentDetails($response, $since); |
106 | 106 | } |
@@ -117,18 +117,18 @@ discard block |
||
117 | 117 | */ |
118 | 118 | private function initializeThankYouPageAndTransaction($response, $data) |
119 | 119 | { |
120 | - require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php'; |
|
120 | + require_once EE_MODULES.'thank_you_page/EED_Thank_You_Page.module.php'; |
|
121 | 121 | // set_definitions, instantiate the thank you page class, and get the ball rolling |
122 | 122 | EED_Thank_You_Page::set_definitions(); |
123 | 123 | $this->thank_you_page = EED_Thank_You_Page::instance(); |
124 | - $this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']); |
|
124 | + $this->thank_you_page->set_reg_url_link($data[$this->heartbeat]['e_reg_url_link']); |
|
125 | 125 | $this->thank_you_page->init(); |
126 | 126 | // get TXN |
127 | 127 | $transaction = $this->thank_you_page->get_txn(); |
128 | 128 | // no TXN? then get out |
129 | - if (! $transaction instanceof EE_Transaction) { |
|
129 | + if ( ! $transaction instanceof EE_Transaction) { |
|
130 | 130 | $notices = EE_Error::get_notices(); |
131 | - $response[ $this->heartbeat ] = array( |
|
131 | + $response[$this->heartbeat] = array( |
|
132 | 132 | 'errors' => ! empty($notices['errors']) |
133 | 133 | ? $notices['errors'] |
134 | 134 | : sprintf( |
@@ -173,12 +173,12 @@ discard block |
||
173 | 173 | case EEM_Transaction::failed_status_code: |
174 | 174 | default: |
175 | 175 | // keep on waiting... |
176 | - return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
176 | + return $this->updateServerWaitTime($data[$this->heartbeat]); |
|
177 | 177 | } |
178 | 178 | // or is the TXN still failed (never been updated) ??? |
179 | 179 | } elseif ($this->transaction->failed()) { |
180 | 180 | // keep on waiting... |
181 | - return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
181 | + return $this->updateServerWaitTime($data[$this->heartbeat]); |
|
182 | 182 | } |
183 | 183 | return $response; |
184 | 184 | } |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | */ |
197 | 197 | private function setTransactionDetails($response, $status_only = false) |
198 | 198 | { |
199 | - if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) { |
|
200 | - $response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details(); |
|
199 | + if ( ! $status_only && ! isset($response[$this->heartbeat]['transaction_details'])) { |
|
200 | + $response[$this->heartbeat]['transaction_details'] = $this->thank_you_page->get_transaction_details(); |
|
201 | 201 | } |
202 | - if (! isset($response[ $this->heartbeat ]['txn_status'])) { |
|
203 | - $response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID(); |
|
202 | + if ( ! isset($response[$this->heartbeat]['txn_status'])) { |
|
203 | + $response[$this->heartbeat]['txn_status'] = $this->transaction->status_ID(); |
|
204 | 204 | } |
205 | 205 | return $response; |
206 | 206 | } |
@@ -221,19 +221,19 @@ discard block |
||
221 | 221 | // then check for payments |
222 | 222 | $payments = $this->thank_you_page->get_txn_payments($since); |
223 | 223 | // has a payment been processed ? |
224 | - if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
224 | + if ( ! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
225 | 225 | if ($since) { |
226 | - $response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments); |
|
226 | + $response[$this->heartbeat]['new_payments'] = $this->thank_you_page->get_new_payments($payments); |
|
227 | 227 | $response = $this->setTransactionDetails($response); |
228 | 228 | } else { |
229 | - $response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details( |
|
229 | + $response[$this->heartbeat]['payment_details'] = $this->thank_you_page->get_payment_details( |
|
230 | 230 | $payments |
231 | 231 | ); |
232 | 232 | } |
233 | 233 | // reset time to check for payments |
234 | - $response[ $this->heartbeat ]['get_payments_since'] = time(); |
|
234 | + $response[$this->heartbeat]['get_payments_since'] = time(); |
|
235 | 235 | } else { |
236 | - $response[ $this->heartbeat ]['get_payments_since'] = $since; |
|
236 | + $response[$this->heartbeat]['get_payments_since'] = $since; |
|
237 | 237 | } |
238 | 238 | return $response; |
239 | 239 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | */ |
252 | 252 | private function updateServerWaitTime($thank_you_page_data) |
253 | 253 | { |
254 | - $response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access']) |
|
254 | + $response[$this->heartbeat]['still_waiting'] = isset($thank_you_page_data['initial_access']) |
|
255 | 255 | ? time() - $thank_you_page_data['initial_access'] |
256 | 256 | : 0; |
257 | 257 | $response = $this->setTransactionDetails($response, true); |
@@ -21,239 +21,239 @@ |
||
21 | 21 | */ |
22 | 22 | class ThankYouPageIpnMonitor |
23 | 23 | { |
24 | - /** |
|
25 | - * @var string $heartbeat |
|
26 | - */ |
|
27 | - private $heartbeat; |
|
24 | + /** |
|
25 | + * @var string $heartbeat |
|
26 | + */ |
|
27 | + private $heartbeat; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var EED_Thank_You_Page $thank_you_page |
|
31 | - */ |
|
32 | - private $thank_you_page; |
|
29 | + /** |
|
30 | + * @var EED_Thank_You_Page $thank_you_page |
|
31 | + */ |
|
32 | + private $thank_you_page; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var EE_Transaction $transaction |
|
36 | - */ |
|
37 | - private $transaction; |
|
34 | + /** |
|
35 | + * @var EE_Transaction $transaction |
|
36 | + */ |
|
37 | + private $transaction; |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * EventEditorHeartbeat constructor. |
|
42 | - */ |
|
43 | - public function __construct() |
|
44 | - { |
|
45 | - $this->heartbeat = WordpressHeartbeat::RESPONSE_KEY_THANK_YOU_PAGE; |
|
46 | - add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3); |
|
47 | - add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3); |
|
48 | - } |
|
40 | + /** |
|
41 | + * EventEditorHeartbeat constructor. |
|
42 | + */ |
|
43 | + public function __construct() |
|
44 | + { |
|
45 | + $this->heartbeat = WordpressHeartbeat::RESPONSE_KEY_THANK_YOU_PAGE; |
|
46 | + add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3); |
|
47 | + add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * thank_you_page_IPN_monitor |
|
53 | - * this basically just pulls the TXN based on the reg_url_link sent from the server, |
|
54 | - * then checks that the TXN status is not failed, and that no other errors have been generated. |
|
55 | - * it also calculates the IPN wait time since the Thank You page was first loaded |
|
56 | - * |
|
57 | - * @param array $response |
|
58 | - * @param array $data |
|
59 | - * @return array |
|
60 | - * @throws EE_Error |
|
61 | - * @throws InvalidArgumentException |
|
62 | - * @throws InvalidDataTypeException |
|
63 | - * @throws InvalidInterfaceException |
|
64 | - * @throws ReflectionException |
|
65 | - */ |
|
66 | - public function heartbeatResponse($response = array(), $data = array()) |
|
67 | - { |
|
68 | - // does this heartbeat contain our data ? |
|
69 | - if (! isset($data[ $this->heartbeat ])) { |
|
70 | - return $response; |
|
71 | - } |
|
72 | - // check for reg_url_link in the incoming heartbeat data |
|
73 | - if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) { |
|
74 | - $response[ $this->heartbeat ] = array( |
|
75 | - 'errors' => ! empty($notices['errors']) |
|
76 | - ? $notices['errors'] |
|
77 | - : esc_html__( |
|
78 | - 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
79 | - 'event_espresso' |
|
80 | - ), |
|
81 | - ); |
|
82 | - return $response; |
|
83 | - } |
|
84 | - // kk heartbeat has our data |
|
85 | - $response = $this->initializeThankYouPageAndTransaction($response, $data); |
|
86 | - // if something went wrong... |
|
87 | - if (isset($response[ $this->heartbeat ]['errors'])) { |
|
88 | - return $response; |
|
89 | - } |
|
90 | - // grab transient of Transaction's status |
|
91 | - $txn_status = isset($data[ $this->heartbeat ]['txn_status']) |
|
92 | - ? $data[ $this->heartbeat ]['txn_status'] |
|
93 | - : null; |
|
94 | - $response = $this->getTransactionDetails($txn_status, $response, $data); |
|
95 | - // no payment data yet? |
|
96 | - if (isset($response[ $this->heartbeat ]['still_waiting'])) { |
|
97 | - return $response; |
|
98 | - } |
|
99 | - // TXN is happening so let's get the payments now |
|
100 | - // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked |
|
101 | - $since = isset($data[ $this->heartbeat ]['get_payments_since']) |
|
102 | - ? $data[ $this->heartbeat ]['get_payments_since'] |
|
103 | - : 0; |
|
104 | - return $this->paymentDetails($response, $since); |
|
105 | - } |
|
51 | + /** |
|
52 | + * thank_you_page_IPN_monitor |
|
53 | + * this basically just pulls the TXN based on the reg_url_link sent from the server, |
|
54 | + * then checks that the TXN status is not failed, and that no other errors have been generated. |
|
55 | + * it also calculates the IPN wait time since the Thank You page was first loaded |
|
56 | + * |
|
57 | + * @param array $response |
|
58 | + * @param array $data |
|
59 | + * @return array |
|
60 | + * @throws EE_Error |
|
61 | + * @throws InvalidArgumentException |
|
62 | + * @throws InvalidDataTypeException |
|
63 | + * @throws InvalidInterfaceException |
|
64 | + * @throws ReflectionException |
|
65 | + */ |
|
66 | + public function heartbeatResponse($response = array(), $data = array()) |
|
67 | + { |
|
68 | + // does this heartbeat contain our data ? |
|
69 | + if (! isset($data[ $this->heartbeat ])) { |
|
70 | + return $response; |
|
71 | + } |
|
72 | + // check for reg_url_link in the incoming heartbeat data |
|
73 | + if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) { |
|
74 | + $response[ $this->heartbeat ] = array( |
|
75 | + 'errors' => ! empty($notices['errors']) |
|
76 | + ? $notices['errors'] |
|
77 | + : esc_html__( |
|
78 | + 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
79 | + 'event_espresso' |
|
80 | + ), |
|
81 | + ); |
|
82 | + return $response; |
|
83 | + } |
|
84 | + // kk heartbeat has our data |
|
85 | + $response = $this->initializeThankYouPageAndTransaction($response, $data); |
|
86 | + // if something went wrong... |
|
87 | + if (isset($response[ $this->heartbeat ]['errors'])) { |
|
88 | + return $response; |
|
89 | + } |
|
90 | + // grab transient of Transaction's status |
|
91 | + $txn_status = isset($data[ $this->heartbeat ]['txn_status']) |
|
92 | + ? $data[ $this->heartbeat ]['txn_status'] |
|
93 | + : null; |
|
94 | + $response = $this->getTransactionDetails($txn_status, $response, $data); |
|
95 | + // no payment data yet? |
|
96 | + if (isset($response[ $this->heartbeat ]['still_waiting'])) { |
|
97 | + return $response; |
|
98 | + } |
|
99 | + // TXN is happening so let's get the payments now |
|
100 | + // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked |
|
101 | + $since = isset($data[ $this->heartbeat ]['get_payments_since']) |
|
102 | + ? $data[ $this->heartbeat ]['get_payments_since'] |
|
103 | + : 0; |
|
104 | + return $this->paymentDetails($response, $since); |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | - /** |
|
109 | - * @param array $response |
|
110 | - * @param array $data |
|
111 | - * @return array |
|
112 | - * @throws EE_Error |
|
113 | - * @throws InvalidArgumentException |
|
114 | - * @throws InvalidDataTypeException |
|
115 | - * @throws InvalidInterfaceException |
|
116 | - */ |
|
117 | - private function initializeThankYouPageAndTransaction($response, $data) |
|
118 | - { |
|
119 | - require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php'; |
|
120 | - // set_definitions, instantiate the thank you page class, and get the ball rolling |
|
121 | - EED_Thank_You_Page::set_definitions(); |
|
122 | - $this->thank_you_page = EED_Thank_You_Page::instance(); |
|
123 | - $this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']); |
|
124 | - $this->thank_you_page->init(); |
|
125 | - // get TXN |
|
126 | - $transaction = $this->thank_you_page->get_txn(); |
|
127 | - // no TXN? then get out |
|
128 | - if (! $transaction instanceof EE_Transaction) { |
|
129 | - $notices = EE_Error::get_notices(); |
|
130 | - $response[ $this->heartbeat ] = array( |
|
131 | - 'errors' => ! empty($notices['errors']) |
|
132 | - ? $notices['errors'] |
|
133 | - : sprintf( |
|
134 | - esc_html__( |
|
135 | - 'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)', |
|
136 | - 'event_espresso' |
|
137 | - ), |
|
138 | - __LINE__ |
|
139 | - ), |
|
140 | - ); |
|
141 | - return $response; |
|
142 | - } |
|
143 | - $this->transaction = $transaction; |
|
144 | - return $response; |
|
145 | - } |
|
108 | + /** |
|
109 | + * @param array $response |
|
110 | + * @param array $data |
|
111 | + * @return array |
|
112 | + * @throws EE_Error |
|
113 | + * @throws InvalidArgumentException |
|
114 | + * @throws InvalidDataTypeException |
|
115 | + * @throws InvalidInterfaceException |
|
116 | + */ |
|
117 | + private function initializeThankYouPageAndTransaction($response, $data) |
|
118 | + { |
|
119 | + require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php'; |
|
120 | + // set_definitions, instantiate the thank you page class, and get the ball rolling |
|
121 | + EED_Thank_You_Page::set_definitions(); |
|
122 | + $this->thank_you_page = EED_Thank_You_Page::instance(); |
|
123 | + $this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']); |
|
124 | + $this->thank_you_page->init(); |
|
125 | + // get TXN |
|
126 | + $transaction = $this->thank_you_page->get_txn(); |
|
127 | + // no TXN? then get out |
|
128 | + if (! $transaction instanceof EE_Transaction) { |
|
129 | + $notices = EE_Error::get_notices(); |
|
130 | + $response[ $this->heartbeat ] = array( |
|
131 | + 'errors' => ! empty($notices['errors']) |
|
132 | + ? $notices['errors'] |
|
133 | + : sprintf( |
|
134 | + esc_html__( |
|
135 | + 'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)', |
|
136 | + 'event_espresso' |
|
137 | + ), |
|
138 | + __LINE__ |
|
139 | + ), |
|
140 | + ); |
|
141 | + return $response; |
|
142 | + } |
|
143 | + $this->transaction = $transaction; |
|
144 | + return $response; |
|
145 | + } |
|
146 | 146 | |
147 | 147 | |
148 | - /** |
|
149 | - * @param string $txn_status |
|
150 | - * @param array $response |
|
151 | - * @param array $data |
|
152 | - * @return array |
|
153 | - * @throws EE_Error |
|
154 | - * @throws InvalidArgumentException |
|
155 | - * @throws InvalidDataTypeException |
|
156 | - * @throws InvalidInterfaceException |
|
157 | - * @throws ReflectionException |
|
158 | - */ |
|
159 | - private function getTransactionDetails($txn_status, $response, $data) |
|
160 | - { |
|
161 | - // has the TXN status changed since we last checked (or empty because this is the first time running through this code)? |
|
162 | - if ($txn_status !== $this->transaction->status_ID()) { |
|
163 | - // switch between two possible basic outcomes |
|
164 | - switch ($this->transaction->status_ID()) { |
|
165 | - // TXN has been updated in some way |
|
166 | - case EEM_Transaction::overpaid_status_code: |
|
167 | - case EEM_Transaction::complete_status_code: |
|
168 | - case EEM_Transaction::incomplete_status_code: |
|
169 | - // send updated TXN results back to client, |
|
170 | - return $this->setTransactionDetails($response); |
|
171 | - // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back... |
|
172 | - case EEM_Transaction::failed_status_code: |
|
173 | - default: |
|
174 | - // keep on waiting... |
|
175 | - return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
176 | - } |
|
177 | - // or is the TXN still failed (never been updated) ??? |
|
178 | - } elseif ($this->transaction->failed()) { |
|
179 | - // keep on waiting... |
|
180 | - return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
181 | - } |
|
182 | - return $response; |
|
183 | - } |
|
148 | + /** |
|
149 | + * @param string $txn_status |
|
150 | + * @param array $response |
|
151 | + * @param array $data |
|
152 | + * @return array |
|
153 | + * @throws EE_Error |
|
154 | + * @throws InvalidArgumentException |
|
155 | + * @throws InvalidDataTypeException |
|
156 | + * @throws InvalidInterfaceException |
|
157 | + * @throws ReflectionException |
|
158 | + */ |
|
159 | + private function getTransactionDetails($txn_status, $response, $data) |
|
160 | + { |
|
161 | + // has the TXN status changed since we last checked (or empty because this is the first time running through this code)? |
|
162 | + if ($txn_status !== $this->transaction->status_ID()) { |
|
163 | + // switch between two possible basic outcomes |
|
164 | + switch ($this->transaction->status_ID()) { |
|
165 | + // TXN has been updated in some way |
|
166 | + case EEM_Transaction::overpaid_status_code: |
|
167 | + case EEM_Transaction::complete_status_code: |
|
168 | + case EEM_Transaction::incomplete_status_code: |
|
169 | + // send updated TXN results back to client, |
|
170 | + return $this->setTransactionDetails($response); |
|
171 | + // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back... |
|
172 | + case EEM_Transaction::failed_status_code: |
|
173 | + default: |
|
174 | + // keep on waiting... |
|
175 | + return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
176 | + } |
|
177 | + // or is the TXN still failed (never been updated) ??? |
|
178 | + } elseif ($this->transaction->failed()) { |
|
179 | + // keep on waiting... |
|
180 | + return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
181 | + } |
|
182 | + return $response; |
|
183 | + } |
|
184 | 184 | |
185 | 185 | |
186 | - /** |
|
187 | - * @param array $response |
|
188 | - * @param boolean $status_only |
|
189 | - * @return array |
|
190 | - * @throws EE_Error |
|
191 | - * @throws InvalidArgumentException |
|
192 | - * @throws InvalidDataTypeException |
|
193 | - * @throws InvalidInterfaceException |
|
194 | - * @throws ReflectionException |
|
195 | - */ |
|
196 | - private function setTransactionDetails($response, $status_only = false) |
|
197 | - { |
|
198 | - if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) { |
|
199 | - $response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details(); |
|
200 | - } |
|
201 | - if (! isset($response[ $this->heartbeat ]['txn_status'])) { |
|
202 | - $response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID(); |
|
203 | - } |
|
204 | - return $response; |
|
205 | - } |
|
186 | + /** |
|
187 | + * @param array $response |
|
188 | + * @param boolean $status_only |
|
189 | + * @return array |
|
190 | + * @throws EE_Error |
|
191 | + * @throws InvalidArgumentException |
|
192 | + * @throws InvalidDataTypeException |
|
193 | + * @throws InvalidInterfaceException |
|
194 | + * @throws ReflectionException |
|
195 | + */ |
|
196 | + private function setTransactionDetails($response, $status_only = false) |
|
197 | + { |
|
198 | + if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) { |
|
199 | + $response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details(); |
|
200 | + } |
|
201 | + if (! isset($response[ $this->heartbeat ]['txn_status'])) { |
|
202 | + $response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID(); |
|
203 | + } |
|
204 | + return $response; |
|
205 | + } |
|
206 | 206 | |
207 | 207 | |
208 | - /** |
|
209 | - * @param array $response |
|
210 | - * @param int $since |
|
211 | - * @return array |
|
212 | - * @throws EE_Error |
|
213 | - * @throws InvalidArgumentException |
|
214 | - * @throws InvalidDataTypeException |
|
215 | - * @throws InvalidInterfaceException |
|
216 | - * @throws ReflectionException |
|
217 | - */ |
|
218 | - private function paymentDetails($response, $since) |
|
219 | - { |
|
220 | - // then check for payments |
|
221 | - $payments = $this->thank_you_page->get_txn_payments($since); |
|
222 | - // has a payment been processed ? |
|
223 | - if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
224 | - if ($since) { |
|
225 | - $response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments); |
|
226 | - $response = $this->setTransactionDetails($response); |
|
227 | - } else { |
|
228 | - $response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details( |
|
229 | - $payments |
|
230 | - ); |
|
231 | - } |
|
232 | - // reset time to check for payments |
|
233 | - $response[ $this->heartbeat ]['get_payments_since'] = time(); |
|
234 | - } else { |
|
235 | - $response[ $this->heartbeat ]['get_payments_since'] = $since; |
|
236 | - } |
|
237 | - return $response; |
|
238 | - } |
|
208 | + /** |
|
209 | + * @param array $response |
|
210 | + * @param int $since |
|
211 | + * @return array |
|
212 | + * @throws EE_Error |
|
213 | + * @throws InvalidArgumentException |
|
214 | + * @throws InvalidDataTypeException |
|
215 | + * @throws InvalidInterfaceException |
|
216 | + * @throws ReflectionException |
|
217 | + */ |
|
218 | + private function paymentDetails($response, $since) |
|
219 | + { |
|
220 | + // then check for payments |
|
221 | + $payments = $this->thank_you_page->get_txn_payments($since); |
|
222 | + // has a payment been processed ? |
|
223 | + if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
224 | + if ($since) { |
|
225 | + $response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments); |
|
226 | + $response = $this->setTransactionDetails($response); |
|
227 | + } else { |
|
228 | + $response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details( |
|
229 | + $payments |
|
230 | + ); |
|
231 | + } |
|
232 | + // reset time to check for payments |
|
233 | + $response[ $this->heartbeat ]['get_payments_since'] = time(); |
|
234 | + } else { |
|
235 | + $response[ $this->heartbeat ]['get_payments_since'] = $since; |
|
236 | + } |
|
237 | + return $response; |
|
238 | + } |
|
239 | 239 | |
240 | 240 | |
241 | - /** |
|
242 | - * @param array $thank_you_page_data thank you page portion of the incoming JSON array |
|
243 | - * from the WP heartbeat data |
|
244 | - * @return array |
|
245 | - * @throws EE_Error |
|
246 | - * @throws InvalidArgumentException |
|
247 | - * @throws InvalidDataTypeException |
|
248 | - * @throws InvalidInterfaceException |
|
249 | - * @throws ReflectionException |
|
250 | - */ |
|
251 | - private function updateServerWaitTime($thank_you_page_data) |
|
252 | - { |
|
253 | - $response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access']) |
|
254 | - ? time() - $thank_you_page_data['initial_access'] |
|
255 | - : 0; |
|
256 | - $response = $this->setTransactionDetails($response, true); |
|
257 | - return $response; |
|
258 | - } |
|
241 | + /** |
|
242 | + * @param array $thank_you_page_data thank you page portion of the incoming JSON array |
|
243 | + * from the WP heartbeat data |
|
244 | + * @return array |
|
245 | + * @throws EE_Error |
|
246 | + * @throws InvalidArgumentException |
|
247 | + * @throws InvalidDataTypeException |
|
248 | + * @throws InvalidInterfaceException |
|
249 | + * @throws ReflectionException |
|
250 | + */ |
|
251 | + private function updateServerWaitTime($thank_you_page_data) |
|
252 | + { |
|
253 | + $response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access']) |
|
254 | + ? time() - $thank_you_page_data['initial_access'] |
|
255 | + : 0; |
|
256 | + $response = $this->setTransactionDetails($response, true); |
|
257 | + return $response; |
|
258 | + } |
|
259 | 259 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | ); |
89 | 89 | $success = \EEH_Line_Item::add_item($transaction->total_line_item(), $cancelled_line_item); |
90 | 90 | } |
91 | - if (! $success) { |
|
91 | + if ( ! $success) { |
|
92 | 92 | throw new \RuntimeException( |
93 | 93 | sprintf( |
94 | 94 | esc_html__('An error occurred while attempting to cancel ticket line item %1$s', 'event_espresso'), |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | break; |
126 | 126 | } |
127 | 127 | } |
128 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
128 | + if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
129 | 129 | throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
130 | 130 | } |
131 | 131 | return $line_item; |
@@ -18,114 +18,114 @@ |
||
18 | 18 | */ |
19 | 19 | class CancelTicketLineItemService extends DomainService |
20 | 20 | { |
21 | - /** |
|
22 | - * @param \EE_Registration $registration |
|
23 | - * @param int $quantity |
|
24 | - * @return bool|int |
|
25 | - */ |
|
26 | - public function forRegistration(\EE_Registration $registration, $quantity = 1) |
|
27 | - { |
|
28 | - return $this->cancel( |
|
29 | - $registration->transaction(), |
|
30 | - $registration->ticket(), |
|
31 | - $quantity, |
|
32 | - $registration->ticket_line_item() |
|
33 | - ); |
|
34 | - } |
|
21 | + /** |
|
22 | + * @param \EE_Registration $registration |
|
23 | + * @param int $quantity |
|
24 | + * @return bool|int |
|
25 | + */ |
|
26 | + public function forRegistration(\EE_Registration $registration, $quantity = 1) |
|
27 | + { |
|
28 | + return $this->cancel( |
|
29 | + $registration->transaction(), |
|
30 | + $registration->ticket(), |
|
31 | + $quantity, |
|
32 | + $registration->ticket_line_item() |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * @param \EE_Transaction $transaction |
|
39 | - * @param \EE_Ticket $ticket |
|
40 | - * @param int $quantity |
|
41 | - * @param \EE_Line_Item $ticket_line_item |
|
42 | - * @return bool|int |
|
43 | - */ |
|
44 | - public function cancel( |
|
45 | - \EE_Transaction $transaction, |
|
46 | - \EE_Ticket $ticket, |
|
47 | - $quantity = 1, |
|
48 | - \EE_Line_Item $ticket_line_item = null |
|
49 | - ) { |
|
50 | - $ticket_line_item = $ticket_line_item instanceof \EE_Line_Item |
|
51 | - ? $ticket_line_item |
|
52 | - : $this->getTicketLineItem($transaction, $ticket); |
|
53 | - // first we need to decrement the ticket quantity |
|
54 | - \EEH_Line_Item::decrement_quantity($ticket_line_item, $quantity); |
|
55 | - // no tickets left for this line item ? |
|
56 | - if ((int) $ticket_line_item->quantity() === 0) { |
|
57 | - // then just set this line item as cancelled, save, and get out |
|
58 | - $ticket_line_item->set_type(\EEM_Line_Item::type_cancellation); |
|
59 | - $success = $ticket_line_item->save(); |
|
60 | - } else { |
|
61 | - // otherwise create a new cancelled line item, so that we have a record of the cancellation |
|
62 | - $items_subtotal = \EEH_Line_Item::get_pre_tax_subtotal( |
|
63 | - \EEH_Line_Item::get_event_line_item_for_ticket( |
|
64 | - $transaction->total_line_item(), |
|
65 | - $ticket |
|
66 | - ) |
|
67 | - ); |
|
68 | - $cancelled_line_item = \EE_Line_Item::new_instance( |
|
69 | - array( |
|
70 | - 'LIN_name' => $ticket_line_item->name(), |
|
71 | - 'LIN_desc' => sprintf( |
|
72 | - esc_html__('%1$s Cancelled: %2$s', 'event_espresso'), |
|
73 | - $ticket_line_item->desc(), |
|
74 | - date('Y-m-d h:i a') |
|
75 | - ), |
|
76 | - 'LIN_unit_price' => (float) $ticket_line_item->unit_price(), |
|
77 | - 'LIN_quantity' => $quantity, |
|
78 | - 'LIN_percent' => null, |
|
79 | - 'LIN_is_taxable' => false, |
|
80 | - 'LIN_order' => $items_subtotal instanceof \EE_Line_Item |
|
81 | - ? count($items_subtotal->children()) |
|
82 | - : 0, |
|
83 | - 'LIN_total' => (float) $ticket_line_item->unit_price(), |
|
84 | - 'LIN_type' => \EEM_Line_Item::type_cancellation, |
|
85 | - ) |
|
86 | - ); |
|
87 | - $success = \EEH_Line_Item::add_item($transaction->total_line_item(), $cancelled_line_item); |
|
88 | - } |
|
89 | - if (! $success) { |
|
90 | - throw new \RuntimeException( |
|
91 | - sprintf( |
|
92 | - esc_html__('An error occurred while attempting to cancel ticket line item %1$s', 'event_espresso'), |
|
93 | - $ticket_line_item->ID() |
|
94 | - ) |
|
95 | - ); |
|
96 | - } |
|
97 | - return $success; |
|
98 | - } |
|
37 | + /** |
|
38 | + * @param \EE_Transaction $transaction |
|
39 | + * @param \EE_Ticket $ticket |
|
40 | + * @param int $quantity |
|
41 | + * @param \EE_Line_Item $ticket_line_item |
|
42 | + * @return bool|int |
|
43 | + */ |
|
44 | + public function cancel( |
|
45 | + \EE_Transaction $transaction, |
|
46 | + \EE_Ticket $ticket, |
|
47 | + $quantity = 1, |
|
48 | + \EE_Line_Item $ticket_line_item = null |
|
49 | + ) { |
|
50 | + $ticket_line_item = $ticket_line_item instanceof \EE_Line_Item |
|
51 | + ? $ticket_line_item |
|
52 | + : $this->getTicketLineItem($transaction, $ticket); |
|
53 | + // first we need to decrement the ticket quantity |
|
54 | + \EEH_Line_Item::decrement_quantity($ticket_line_item, $quantity); |
|
55 | + // no tickets left for this line item ? |
|
56 | + if ((int) $ticket_line_item->quantity() === 0) { |
|
57 | + // then just set this line item as cancelled, save, and get out |
|
58 | + $ticket_line_item->set_type(\EEM_Line_Item::type_cancellation); |
|
59 | + $success = $ticket_line_item->save(); |
|
60 | + } else { |
|
61 | + // otherwise create a new cancelled line item, so that we have a record of the cancellation |
|
62 | + $items_subtotal = \EEH_Line_Item::get_pre_tax_subtotal( |
|
63 | + \EEH_Line_Item::get_event_line_item_for_ticket( |
|
64 | + $transaction->total_line_item(), |
|
65 | + $ticket |
|
66 | + ) |
|
67 | + ); |
|
68 | + $cancelled_line_item = \EE_Line_Item::new_instance( |
|
69 | + array( |
|
70 | + 'LIN_name' => $ticket_line_item->name(), |
|
71 | + 'LIN_desc' => sprintf( |
|
72 | + esc_html__('%1$s Cancelled: %2$s', 'event_espresso'), |
|
73 | + $ticket_line_item->desc(), |
|
74 | + date('Y-m-d h:i a') |
|
75 | + ), |
|
76 | + 'LIN_unit_price' => (float) $ticket_line_item->unit_price(), |
|
77 | + 'LIN_quantity' => $quantity, |
|
78 | + 'LIN_percent' => null, |
|
79 | + 'LIN_is_taxable' => false, |
|
80 | + 'LIN_order' => $items_subtotal instanceof \EE_Line_Item |
|
81 | + ? count($items_subtotal->children()) |
|
82 | + : 0, |
|
83 | + 'LIN_total' => (float) $ticket_line_item->unit_price(), |
|
84 | + 'LIN_type' => \EEM_Line_Item::type_cancellation, |
|
85 | + ) |
|
86 | + ); |
|
87 | + $success = \EEH_Line_Item::add_item($transaction->total_line_item(), $cancelled_line_item); |
|
88 | + } |
|
89 | + if (! $success) { |
|
90 | + throw new \RuntimeException( |
|
91 | + sprintf( |
|
92 | + esc_html__('An error occurred while attempting to cancel ticket line item %1$s', 'event_espresso'), |
|
93 | + $ticket_line_item->ID() |
|
94 | + ) |
|
95 | + ); |
|
96 | + } |
|
97 | + return $success; |
|
98 | + } |
|
99 | 99 | |
100 | 100 | |
101 | - /** |
|
102 | - * @param \EE_Transaction $transaction |
|
103 | - * @param \EE_Ticket $ticket |
|
104 | - * @return \EE_Line_Item |
|
105 | - * @throws EntityNotFoundException |
|
106 | - * @throws \EE_Error |
|
107 | - */ |
|
108 | - protected static function getTicketLineItem(\EE_Transaction $transaction, \EE_Ticket $ticket) |
|
109 | - { |
|
110 | - $line_item = null; |
|
111 | - $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
112 | - $transaction->total_line_item(), |
|
113 | - 'Ticket', |
|
114 | - array($ticket->ID()) |
|
115 | - ); |
|
116 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
117 | - if ( |
|
118 | - $ticket_line_item instanceof \EE_Line_Item |
|
119 | - && $ticket_line_item->OBJ_type() === 'Ticket' |
|
120 | - && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
121 | - ) { |
|
122 | - $line_item = $ticket_line_item; |
|
123 | - break; |
|
124 | - } |
|
125 | - } |
|
126 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
127 | - throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
128 | - } |
|
129 | - return $line_item; |
|
130 | - } |
|
101 | + /** |
|
102 | + * @param \EE_Transaction $transaction |
|
103 | + * @param \EE_Ticket $ticket |
|
104 | + * @return \EE_Line_Item |
|
105 | + * @throws EntityNotFoundException |
|
106 | + * @throws \EE_Error |
|
107 | + */ |
|
108 | + protected static function getTicketLineItem(\EE_Transaction $transaction, \EE_Ticket $ticket) |
|
109 | + { |
|
110 | + $line_item = null; |
|
111 | + $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
112 | + $transaction->total_line_item(), |
|
113 | + 'Ticket', |
|
114 | + array($ticket->ID()) |
|
115 | + ); |
|
116 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
117 | + if ( |
|
118 | + $ticket_line_item instanceof \EE_Line_Item |
|
119 | + && $ticket_line_item->OBJ_type() === 'Ticket' |
|
120 | + && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
121 | + ) { |
|
122 | + $line_item = $ticket_line_item; |
|
123 | + break; |
|
124 | + } |
|
125 | + } |
|
126 | + if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
127 | + throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
128 | + } |
|
129 | + return $line_item; |
|
130 | + } |
|
131 | 131 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | // assume this if first route being called |
61 | 61 | $previous_route = false; |
62 | 62 | // but is it really ??? |
63 | - if (! empty(self::$_previous_routes)) { |
|
63 | + if ( ! empty(self::$_previous_routes)) { |
|
64 | 64 | // get last run route |
65 | 65 | $previous_routes = array_values(self::$_previous_routes); |
66 | 66 | $previous_route = array_pop($previous_routes); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | $current_route = $this->get_forward($previous_route); |
72 | 72 | try { |
73 | 73 | // check for recursive forwarding |
74 | - if (isset(self::$_previous_routes[ $current_route ])) { |
|
74 | + if (isset(self::$_previous_routes[$current_route])) { |
|
75 | 75 | throw new EE_Error( |
76 | 76 | sprintf( |
77 | 77 | esc_html__( |
@@ -144,38 +144,38 @@ discard block |
||
144 | 144 | return false; |
145 | 145 | } |
146 | 146 | // verify that result is an array |
147 | - if (! is_array($module_method)) { |
|
147 | + if ( ! is_array($module_method)) { |
|
148 | 148 | $msg = sprintf(esc_html__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
149 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
149 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
150 | 150 | return false; |
151 | 151 | } |
152 | 152 | // grab module name |
153 | 153 | $module_name = $module_method[0]; |
154 | 154 | // verify that a class method was registered properly |
155 | - if (! isset($module_method[1])) { |
|
155 | + if ( ! isset($module_method[1])) { |
|
156 | 156 | $msg = sprintf( |
157 | 157 | esc_html__('A class method for the %s route has not been properly registered.', 'event_espresso'), |
158 | 158 | $current_route |
159 | 159 | ); |
160 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
160 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
161 | 161 | return false; |
162 | 162 | } |
163 | 163 | // grab method |
164 | 164 | $method = $module_method[1]; |
165 | 165 | // verify that class exists |
166 | - if (! class_exists($module_name)) { |
|
166 | + if ( ! class_exists($module_name)) { |
|
167 | 167 | $msg = sprintf(esc_html__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
168 | 168 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
169 | 169 | return false; |
170 | 170 | } |
171 | 171 | // verify that method exists |
172 | - if (! method_exists($module_name, $method)) { |
|
172 | + if ( ! method_exists($module_name, $method)) { |
|
173 | 173 | $msg = sprintf( |
174 | 174 | esc_html__('The class method %s for the %s route is in invalid.', 'event_espresso'), |
175 | 175 | $method, |
176 | 176 | $current_route |
177 | 177 | ); |
178 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
178 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
179 | 179 | return false; |
180 | 180 | } |
181 | 181 | // instantiate module and call route method |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | // instantiate module class |
210 | 210 | $module = new $module_name(); |
211 | 211 | // ensure that class is actually a module |
212 | - if (! $module instanceof EED_Module) { |
|
212 | + if ( ! $module instanceof EED_Module) { |
|
213 | 213 | EE_Error::add_error( |
214 | 214 | sprintf(esc_html__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
215 | 215 | __FILE__, |
@@ -15,254 +15,254 @@ |
||
15 | 15 | */ |
16 | 16 | final class EE_Module_Request_Router implements InterminableInterface |
17 | 17 | { |
18 | - /** |
|
19 | - * @var RequestInterface $request |
|
20 | - */ |
|
21 | - private $request; |
|
18 | + /** |
|
19 | + * @var RequestInterface $request |
|
20 | + */ |
|
21 | + private $request; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var array $_previous_routes |
|
25 | - */ |
|
26 | - private static $_previous_routes = array(); |
|
23 | + /** |
|
24 | + * @var array $_previous_routes |
|
25 | + */ |
|
26 | + private static $_previous_routes = array(); |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var WP_Query $WP_Query |
|
30 | - */ |
|
31 | - public $WP_Query; |
|
28 | + /** |
|
29 | + * @var WP_Query $WP_Query |
|
30 | + */ |
|
31 | + public $WP_Query; |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * EE_Module_Request_Router constructor. |
|
36 | - * |
|
37 | - * @param RequestInterface $request |
|
38 | - */ |
|
39 | - public function __construct(RequestInterface $request) |
|
40 | - { |
|
41 | - $this->request = $request; |
|
42 | - } |
|
34 | + /** |
|
35 | + * EE_Module_Request_Router constructor. |
|
36 | + * |
|
37 | + * @param RequestInterface $request |
|
38 | + */ |
|
39 | + public function __construct(RequestInterface $request) |
|
40 | + { |
|
41 | + $this->request = $request; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * on the first call to this method, it checks the Request for a "route" |
|
47 | - * on subsequent calls to this method, |
|
48 | - * instead of checking the Request for a route, it checks the previous routes array, |
|
49 | - * and checks if the last called route has any forwarding routes registered for it |
|
50 | - * |
|
51 | - * @param WP_Query $WP_Query |
|
52 | - * @return NULL|string |
|
53 | - * @throws EE_Error |
|
54 | - * @throws ReflectionException |
|
55 | - */ |
|
56 | - public function get_route(WP_Query $WP_Query) |
|
57 | - { |
|
58 | - $this->WP_Query = $WP_Query; |
|
59 | - // assume this if first route being called |
|
60 | - $previous_route = false; |
|
61 | - // but is it really ??? |
|
62 | - if (! empty(self::$_previous_routes)) { |
|
63 | - // get last run route |
|
64 | - $previous_routes = array_values(self::$_previous_routes); |
|
65 | - $previous_route = array_pop($previous_routes); |
|
66 | - } |
|
67 | - // has another route already been run ? |
|
68 | - if ($previous_route) { |
|
69 | - // check if forwarding has been set |
|
70 | - $current_route = $this->get_forward($previous_route); |
|
71 | - try { |
|
72 | - // check for recursive forwarding |
|
73 | - if (isset(self::$_previous_routes[ $current_route ])) { |
|
74 | - throw new EE_Error( |
|
75 | - sprintf( |
|
76 | - esc_html__( |
|
77 | - 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
78 | - 'event_espresso' |
|
79 | - ), |
|
80 | - $current_route |
|
81 | - ) |
|
82 | - ); |
|
83 | - } |
|
84 | - } catch (EE_Error $e) { |
|
85 | - $e->get_error(); |
|
86 | - return null; |
|
87 | - } |
|
88 | - } else { |
|
89 | - // first route called |
|
90 | - $current_route = null; |
|
91 | - // grab all routes |
|
92 | - $routes = EE_Config::get_routes(); |
|
93 | - foreach ($routes as $key => $route) { |
|
94 | - // first determine if route key uses w?ldc*rds |
|
95 | - $uses_wildcards = strpos($key, '?') !== false |
|
96 | - || strpos($key, '*') !== false; |
|
97 | - // check request for module route |
|
98 | - $route_found = $uses_wildcards |
|
99 | - ? $this->request->matches($key) |
|
100 | - : $this->request->requestParamIsSet($key); |
|
101 | - if ($route_found) { |
|
102 | - $current_route = $uses_wildcards |
|
103 | - ? $this->request->getMatch($key) |
|
104 | - : $this->request->getRequestParam($key); |
|
105 | - $current_route = sanitize_text_field($current_route); |
|
106 | - if ($current_route) { |
|
107 | - $current_route = array($key, $current_route); |
|
108 | - break; |
|
109 | - } |
|
110 | - } |
|
111 | - } |
|
112 | - } |
|
113 | - // sorry, but I can't read what you route ! |
|
114 | - if (empty($current_route)) { |
|
115 | - return null; |
|
116 | - } |
|
117 | - // add route to previous routes array |
|
118 | - self::$_previous_routes[] = $current_route; |
|
119 | - return $current_route; |
|
120 | - } |
|
45 | + /** |
|
46 | + * on the first call to this method, it checks the Request for a "route" |
|
47 | + * on subsequent calls to this method, |
|
48 | + * instead of checking the Request for a route, it checks the previous routes array, |
|
49 | + * and checks if the last called route has any forwarding routes registered for it |
|
50 | + * |
|
51 | + * @param WP_Query $WP_Query |
|
52 | + * @return NULL|string |
|
53 | + * @throws EE_Error |
|
54 | + * @throws ReflectionException |
|
55 | + */ |
|
56 | + public function get_route(WP_Query $WP_Query) |
|
57 | + { |
|
58 | + $this->WP_Query = $WP_Query; |
|
59 | + // assume this if first route being called |
|
60 | + $previous_route = false; |
|
61 | + // but is it really ??? |
|
62 | + if (! empty(self::$_previous_routes)) { |
|
63 | + // get last run route |
|
64 | + $previous_routes = array_values(self::$_previous_routes); |
|
65 | + $previous_route = array_pop($previous_routes); |
|
66 | + } |
|
67 | + // has another route already been run ? |
|
68 | + if ($previous_route) { |
|
69 | + // check if forwarding has been set |
|
70 | + $current_route = $this->get_forward($previous_route); |
|
71 | + try { |
|
72 | + // check for recursive forwarding |
|
73 | + if (isset(self::$_previous_routes[ $current_route ])) { |
|
74 | + throw new EE_Error( |
|
75 | + sprintf( |
|
76 | + esc_html__( |
|
77 | + 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
78 | + 'event_espresso' |
|
79 | + ), |
|
80 | + $current_route |
|
81 | + ) |
|
82 | + ); |
|
83 | + } |
|
84 | + } catch (EE_Error $e) { |
|
85 | + $e->get_error(); |
|
86 | + return null; |
|
87 | + } |
|
88 | + } else { |
|
89 | + // first route called |
|
90 | + $current_route = null; |
|
91 | + // grab all routes |
|
92 | + $routes = EE_Config::get_routes(); |
|
93 | + foreach ($routes as $key => $route) { |
|
94 | + // first determine if route key uses w?ldc*rds |
|
95 | + $uses_wildcards = strpos($key, '?') !== false |
|
96 | + || strpos($key, '*') !== false; |
|
97 | + // check request for module route |
|
98 | + $route_found = $uses_wildcards |
|
99 | + ? $this->request->matches($key) |
|
100 | + : $this->request->requestParamIsSet($key); |
|
101 | + if ($route_found) { |
|
102 | + $current_route = $uses_wildcards |
|
103 | + ? $this->request->getMatch($key) |
|
104 | + : $this->request->getRequestParam($key); |
|
105 | + $current_route = sanitize_text_field($current_route); |
|
106 | + if ($current_route) { |
|
107 | + $current_route = array($key, $current_route); |
|
108 | + break; |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | + } |
|
113 | + // sorry, but I can't read what you route ! |
|
114 | + if (empty($current_route)) { |
|
115 | + return null; |
|
116 | + } |
|
117 | + // add route to previous routes array |
|
118 | + self::$_previous_routes[] = $current_route; |
|
119 | + return $current_route; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | |
123 | - /** |
|
124 | - * this method simply takes a valid route, and resolves what module class method the route points to |
|
125 | - * |
|
126 | - * @param string $key |
|
127 | - * @param string $current_route |
|
128 | - * @return EED_Module|object|boolean|null |
|
129 | - * @throws EE_Error |
|
130 | - * @throws ReflectionException |
|
131 | - */ |
|
132 | - public function resolve_route($key, $current_route) |
|
133 | - { |
|
134 | - // get module method that route has been mapped to |
|
135 | - $module_method = EE_Config::get_route($current_route, $key); |
|
136 | - // verify result was returned |
|
137 | - if (empty($module_method)) { |
|
138 | - $msg = sprintf( |
|
139 | - esc_html__('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
140 | - $current_route |
|
141 | - ); |
|
142 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
143 | - return false; |
|
144 | - } |
|
145 | - // verify that result is an array |
|
146 | - if (! is_array($module_method)) { |
|
147 | - $msg = sprintf(esc_html__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
148 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
149 | - return false; |
|
150 | - } |
|
151 | - // grab module name |
|
152 | - $module_name = $module_method[0]; |
|
153 | - // verify that a class method was registered properly |
|
154 | - if (! isset($module_method[1])) { |
|
155 | - $msg = sprintf( |
|
156 | - esc_html__('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
157 | - $current_route |
|
158 | - ); |
|
159 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
160 | - return false; |
|
161 | - } |
|
162 | - // grab method |
|
163 | - $method = $module_method[1]; |
|
164 | - // verify that class exists |
|
165 | - if (! class_exists($module_name)) { |
|
166 | - $msg = sprintf(esc_html__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
167 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | - return false; |
|
169 | - } |
|
170 | - // verify that method exists |
|
171 | - if (! method_exists($module_name, $method)) { |
|
172 | - $msg = sprintf( |
|
173 | - esc_html__('The class method %s for the %s route is in invalid.', 'event_espresso'), |
|
174 | - $method, |
|
175 | - $current_route |
|
176 | - ); |
|
177 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
178 | - return false; |
|
179 | - } |
|
180 | - // instantiate module and call route method |
|
181 | - return $this->_module_router($module_name, $method); |
|
182 | - } |
|
123 | + /** |
|
124 | + * this method simply takes a valid route, and resolves what module class method the route points to |
|
125 | + * |
|
126 | + * @param string $key |
|
127 | + * @param string $current_route |
|
128 | + * @return EED_Module|object|boolean|null |
|
129 | + * @throws EE_Error |
|
130 | + * @throws ReflectionException |
|
131 | + */ |
|
132 | + public function resolve_route($key, $current_route) |
|
133 | + { |
|
134 | + // get module method that route has been mapped to |
|
135 | + $module_method = EE_Config::get_route($current_route, $key); |
|
136 | + // verify result was returned |
|
137 | + if (empty($module_method)) { |
|
138 | + $msg = sprintf( |
|
139 | + esc_html__('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
140 | + $current_route |
|
141 | + ); |
|
142 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
143 | + return false; |
|
144 | + } |
|
145 | + // verify that result is an array |
|
146 | + if (! is_array($module_method)) { |
|
147 | + $msg = sprintf(esc_html__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
148 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
149 | + return false; |
|
150 | + } |
|
151 | + // grab module name |
|
152 | + $module_name = $module_method[0]; |
|
153 | + // verify that a class method was registered properly |
|
154 | + if (! isset($module_method[1])) { |
|
155 | + $msg = sprintf( |
|
156 | + esc_html__('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
157 | + $current_route |
|
158 | + ); |
|
159 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
160 | + return false; |
|
161 | + } |
|
162 | + // grab method |
|
163 | + $method = $module_method[1]; |
|
164 | + // verify that class exists |
|
165 | + if (! class_exists($module_name)) { |
|
166 | + $msg = sprintf(esc_html__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
167 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | + return false; |
|
169 | + } |
|
170 | + // verify that method exists |
|
171 | + if (! method_exists($module_name, $method)) { |
|
172 | + $msg = sprintf( |
|
173 | + esc_html__('The class method %s for the %s route is in invalid.', 'event_espresso'), |
|
174 | + $method, |
|
175 | + $current_route |
|
176 | + ); |
|
177 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
178 | + return false; |
|
179 | + } |
|
180 | + // instantiate module and call route method |
|
181 | + return $this->_module_router($module_name, $method); |
|
182 | + } |
|
183 | 183 | |
184 | 184 | |
185 | - /** |
|
186 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
187 | - * |
|
188 | - * @param string $module_name |
|
189 | - * @return EED_Module|object|null |
|
190 | - */ |
|
191 | - public static function module_factory($module_name) |
|
192 | - { |
|
193 | - if ($module_name === 'EED_Module') { |
|
194 | - EE_Error::add_error( |
|
195 | - sprintf( |
|
196 | - esc_html__( |
|
197 | - 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
198 | - 'event_espresso' |
|
199 | - ), |
|
200 | - $module_name |
|
201 | - ), |
|
202 | - __FILE__, |
|
203 | - __FUNCTION__, |
|
204 | - __LINE__ |
|
205 | - ); |
|
206 | - return null; |
|
207 | - } |
|
208 | - // instantiate module class |
|
209 | - $module = new $module_name(); |
|
210 | - // ensure that class is actually a module |
|
211 | - if (! $module instanceof EED_Module) { |
|
212 | - EE_Error::add_error( |
|
213 | - sprintf(esc_html__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
214 | - __FILE__, |
|
215 | - __FUNCTION__, |
|
216 | - __LINE__ |
|
217 | - ); |
|
218 | - return null; |
|
219 | - } |
|
220 | - return $module; |
|
221 | - } |
|
185 | + /** |
|
186 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
187 | + * |
|
188 | + * @param string $module_name |
|
189 | + * @return EED_Module|object|null |
|
190 | + */ |
|
191 | + public static function module_factory($module_name) |
|
192 | + { |
|
193 | + if ($module_name === 'EED_Module') { |
|
194 | + EE_Error::add_error( |
|
195 | + sprintf( |
|
196 | + esc_html__( |
|
197 | + 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
198 | + 'event_espresso' |
|
199 | + ), |
|
200 | + $module_name |
|
201 | + ), |
|
202 | + __FILE__, |
|
203 | + __FUNCTION__, |
|
204 | + __LINE__ |
|
205 | + ); |
|
206 | + return null; |
|
207 | + } |
|
208 | + // instantiate module class |
|
209 | + $module = new $module_name(); |
|
210 | + // ensure that class is actually a module |
|
211 | + if (! $module instanceof EED_Module) { |
|
212 | + EE_Error::add_error( |
|
213 | + sprintf(esc_html__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
214 | + __FILE__, |
|
215 | + __FUNCTION__, |
|
216 | + __LINE__ |
|
217 | + ); |
|
218 | + return null; |
|
219 | + } |
|
220 | + return $module; |
|
221 | + } |
|
222 | 222 | |
223 | 223 | |
224 | - /** |
|
225 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
226 | - * |
|
227 | - * @param string $module_name |
|
228 | - * @param string $method |
|
229 | - * @return EED_Module|null |
|
230 | - * @throws EE_Error |
|
231 | - * @throws ReflectionException |
|
232 | - */ |
|
233 | - private function _module_router($module_name, $method) |
|
234 | - { |
|
235 | - // instantiate module class |
|
236 | - $module = EE_Module_Request_Router::module_factory($module_name); |
|
237 | - if ($module instanceof EED_Module) { |
|
238 | - // and call whatever action the route was for |
|
239 | - try { |
|
240 | - $module->{$method}($this->WP_Query); |
|
241 | - } catch (EE_Error $e) { |
|
242 | - $e->get_error(); |
|
243 | - return null; |
|
244 | - } |
|
245 | - } |
|
246 | - return $module; |
|
247 | - } |
|
224 | + /** |
|
225 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
226 | + * |
|
227 | + * @param string $module_name |
|
228 | + * @param string $method |
|
229 | + * @return EED_Module|null |
|
230 | + * @throws EE_Error |
|
231 | + * @throws ReflectionException |
|
232 | + */ |
|
233 | + private function _module_router($module_name, $method) |
|
234 | + { |
|
235 | + // instantiate module class |
|
236 | + $module = EE_Module_Request_Router::module_factory($module_name); |
|
237 | + if ($module instanceof EED_Module) { |
|
238 | + // and call whatever action the route was for |
|
239 | + try { |
|
240 | + $module->{$method}($this->WP_Query); |
|
241 | + } catch (EE_Error $e) { |
|
242 | + $e->get_error(); |
|
243 | + return null; |
|
244 | + } |
|
245 | + } |
|
246 | + return $module; |
|
247 | + } |
|
248 | 248 | |
249 | 249 | |
250 | - /** |
|
251 | - * @param $current_route |
|
252 | - * @return string |
|
253 | - */ |
|
254 | - public function get_forward($current_route) |
|
255 | - { |
|
256 | - return EE_Config::get_forward($current_route); |
|
257 | - } |
|
250 | + /** |
|
251 | + * @param $current_route |
|
252 | + * @return string |
|
253 | + */ |
|
254 | + public function get_forward($current_route) |
|
255 | + { |
|
256 | + return EE_Config::get_forward($current_route); |
|
257 | + } |
|
258 | 258 | |
259 | 259 | |
260 | - /** |
|
261 | - * @param $current_route |
|
262 | - * @return string |
|
263 | - */ |
|
264 | - public function get_view($current_route) |
|
265 | - { |
|
266 | - return EE_Config::get_view($current_route); |
|
267 | - } |
|
260 | + /** |
|
261 | + * @param $current_route |
|
262 | + * @return string |
|
263 | + */ |
|
264 | + public function get_view($current_route) |
|
265 | + { |
|
266 | + return EE_Config::get_view($current_route); |
|
267 | + } |
|
268 | 268 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function add_error($error, $force = false) |
187 | 187 | { |
188 | - if (! defined('EE_DMS_ERROR_LIMIT')) { |
|
188 | + if ( ! defined('EE_DMS_ERROR_LIMIT')) { |
|
189 | 189 | $limit = 50; |
190 | 190 | } else { |
191 | 191 | $limit = EE_DMS_ERROR_LIMIT; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | $this->_errors[] = "Limit reached; removed first half of errors to save space"; |
202 | 202 | $this->_errors[] = $error; |
203 | 203 | } else { |
204 | - $this->_errors[ $limit ] = 'More, but limit reached...'; |
|
204 | + $this->_errors[$limit] = 'More, but limit reached...'; |
|
205 | 205 | } |
206 | 206 | } else { |
207 | 207 | $this->_errors[] = $error; |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | $new_columns_and_values_for_string = array(); |
346 | 346 | $count = 0; |
347 | 347 | foreach ($new_row_as_array as $column => $value) { |
348 | - $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")"; |
|
348 | + $new_columns_and_values_for_string[] = " $column => $value (".$data_types[$count++].")"; |
|
349 | 349 | } |
350 | 350 | return sprintf( |
351 | 351 | esc_html__( |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | foreach ($array_of_data as $name => $value) { |
377 | 377 | $unserialized_data = @unserialize($value); |
378 | 378 | if ($unserialized_data === false) { |
379 | - $fields_to_include[ $name ] = $value; |
|
379 | + $fields_to_include[$name] = $value; |
|
380 | 380 | } |
381 | 381 | } |
382 | 382 | return wp_json_encode($fields_to_include); |
@@ -16,408 +16,408 @@ |
||
16 | 16 | */ |
17 | 17 | abstract class EE_Data_Migration_Class_Base |
18 | 18 | { |
19 | - /** |
|
20 | - * @var $records_to_migrate int count of all that have been migrated |
|
21 | - */ |
|
22 | - protected $_records_to_migrate = 0; |
|
23 | - |
|
24 | - /** |
|
25 | - * |
|
26 | - * @var $records_migrated int |
|
27 | - */ |
|
28 | - protected $_records_migrated = 0; |
|
29 | - |
|
30 | - /** |
|
31 | - * Whether this migration script is done or not. This COULD be deduced by |
|
32 | - * _records_to_migrate and _records_migrated, but that might nto be accurate |
|
33 | - * |
|
34 | - * @var string one of EE_Data_migration_Manager::status_* constants |
|
35 | - */ |
|
36 | - protected $_status = null; |
|
37 | - |
|
38 | - /** |
|
39 | - * internationalized name of this class. Convention is to NOT restate that |
|
40 | - * this class if a migration script or a migration script stage |
|
41 | - * |
|
42 | - * @var string (i18ned) |
|
43 | - */ |
|
44 | - protected $_pretty_name = null; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $_errors = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
53 | - */ |
|
54 | - protected $_table_manager; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
58 | - */ |
|
59 | - protected $_table_analysis; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Just initializes the status of the migration |
|
64 | - * |
|
65 | - * @param TableManager $table_manager |
|
66 | - * @param TableAnalysis $table_analysis |
|
67 | - */ |
|
68 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
69 | - { |
|
70 | - $this->_table_manager = $table_manager; |
|
71 | - $this->_table_analysis = $table_analysis; |
|
72 | - $this->set_status(EE_Data_Migration_Manager::status_continue); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Just gets the pretty name for this migration script or stage |
|
78 | - * |
|
79 | - * @throws EE_Error |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function pretty_name() |
|
83 | - { |
|
84 | - if ($this->_pretty_name === null) { |
|
85 | - throw new EE_Error( |
|
86 | - sprintf( |
|
87 | - esc_html__( |
|
88 | - "Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor", |
|
89 | - "event_espresso" |
|
90 | - ), |
|
91 | - get_class($this) |
|
92 | - ) |
|
93 | - ); |
|
94 | - } |
|
95 | - return $this->_pretty_name; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * |
|
100 | - * @return int |
|
101 | - */ |
|
102 | - public function count_records_to_migrate() |
|
103 | - { |
|
104 | - if ($this->_records_to_migrate == null) { |
|
105 | - $this->_records_to_migrate = $this->_count_records_to_migrate(); |
|
106 | - } |
|
107 | - return $this->_records_to_migrate; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and |
|
112 | - * EE_Data_migration_Script_Stage |
|
113 | - * |
|
114 | - * @return int |
|
115 | - */ |
|
116 | - abstract public function count_records_migrated(); |
|
117 | - |
|
118 | - /** |
|
119 | - * Counts the records to migrate; the public version may cache it |
|
120 | - * |
|
121 | - * @return int |
|
122 | - */ |
|
123 | - abstract protected function _count_records_to_migrate(); |
|
124 | - |
|
125 | - /** |
|
126 | - * Returns a string indicating the migration script's status. |
|
127 | - * |
|
128 | - * @return string one of EE_Data_Migration_Manager::status_* constants |
|
129 | - * @throws EE_Error |
|
130 | - */ |
|
131 | - public function get_status() |
|
132 | - { |
|
133 | - if ($this->_status === null) { |
|
134 | - throw new EE_Error( |
|
135 | - sprintf( |
|
136 | - esc_html__( |
|
137 | - "Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.", |
|
138 | - "event_espresso" |
|
139 | - ), |
|
140 | - get_class($this) |
|
141 | - ) |
|
142 | - ); |
|
143 | - } |
|
144 | - return $this->_status; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * |
|
149 | - * @param string $status |
|
150 | - * @return void |
|
151 | - */ |
|
152 | - protected function set_status($status) |
|
153 | - { |
|
154 | - $this->_status = $status; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @return array of strings |
|
159 | - */ |
|
160 | - abstract public function get_errors(); |
|
161 | - |
|
162 | - /** |
|
163 | - * Returns the last error that occurred. If none occurred, returns null |
|
164 | - * |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - public function get_last_error() |
|
168 | - { |
|
169 | - $errors = $this->get_errors(); |
|
170 | - if ($errors) { |
|
171 | - return end($errors); |
|
172 | - } else { |
|
173 | - return null; |
|
174 | - } |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Adds an error to the array of errors on this class. |
|
179 | - * |
|
180 | - * @param string $error a string describing the error that will be useful for debugging. Consider including all |
|
181 | - * the data that led to the error, and a stack trace etc. |
|
182 | - * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are |
|
183 | - * already at their limit, we will purposefully forget the first half |
|
184 | - */ |
|
185 | - public function add_error($error, $force = false) |
|
186 | - { |
|
187 | - if (! defined('EE_DMS_ERROR_LIMIT')) { |
|
188 | - $limit = 50; |
|
189 | - } else { |
|
190 | - $limit = EE_DMS_ERROR_LIMIT; |
|
191 | - } |
|
192 | - // make sure errors is an array, see ticket #8261 |
|
193 | - if (is_string($this->_errors)) { |
|
194 | - $this->_errors = array($this->_errors); |
|
195 | - } |
|
196 | - if (count($this->_errors) >= $limit) { |
|
197 | - if ($force) { |
|
198 | - // get rid of the first half of the errors and any above the limit |
|
199 | - $this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2); |
|
200 | - $this->_errors[] = "Limit reached; removed first half of errors to save space"; |
|
201 | - $this->_errors[] = $error; |
|
202 | - } else { |
|
203 | - $this->_errors[ $limit ] = 'More, but limit reached...'; |
|
204 | - } |
|
205 | - } else { |
|
206 | - $this->_errors[] = $error; |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Indicates there was a fatal error and the migration cannot possibly continue |
|
212 | - * |
|
213 | - * @return boolean |
|
214 | - */ |
|
215 | - public function is_broken() |
|
216 | - { |
|
217 | - return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @deprecated since 4.6.12 |
|
222 | - */ |
|
223 | - public function is_borked() |
|
224 | - { |
|
225 | - EE_Error::doing_it_wrong( |
|
226 | - 'is_borked', |
|
227 | - esc_html__( |
|
228 | - 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', |
|
229 | - 'event_espresso' |
|
230 | - ), |
|
231 | - '4.6.12' |
|
232 | - ); |
|
233 | - return $this->is_broken(); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Sets the status to as having a fatal error |
|
238 | - */ |
|
239 | - public function set_broken() |
|
240 | - { |
|
241 | - $this->_status = EE_Data_Migration_Manager::status_fatal_error; |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * |
|
246 | - * @deprecated since 4.6.12 |
|
247 | - */ |
|
248 | - public function set_borked() |
|
249 | - { |
|
250 | - EE_Error::doing_it_wrong( |
|
251 | - 'is_borked', |
|
252 | - esc_html__( |
|
253 | - 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', |
|
254 | - 'event_espresso' |
|
255 | - ), |
|
256 | - '4.6.12' |
|
257 | - ); |
|
258 | - return $this->set_broken(); |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Checks if this thing believes it is completed |
|
263 | - * |
|
264 | - * @return boolean |
|
265 | - */ |
|
266 | - public function is_completed() |
|
267 | - { |
|
268 | - return $this->get_status() == EE_Data_Migration_Manager::status_completed; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Checks if the current script has more to do or not (ie, if it's status is CONTINUE) |
|
273 | - * |
|
274 | - * @return boolean |
|
275 | - */ |
|
276 | - public function has_more_to_do() |
|
277 | - { |
|
278 | - return $this->get_status() == EE_Data_Migration_Manager::status_continue; |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Marks that we believe this migration thing is completed |
|
283 | - */ |
|
284 | - public function set_completed() |
|
285 | - { |
|
286 | - $this->_status = EE_Data_Migration_Manager::status_completed; |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Marks that we think this migration class can continue to migrate |
|
291 | - */ |
|
292 | - public function reattempt() |
|
293 | - { |
|
294 | - $this->_status = EE_Data_Migration_Manager::status_continue; |
|
295 | - $this->add_error(esc_html__('Reattempt migration', 'event_espresso'), true); |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class' |
|
300 | - * properties to the DB. However, we don't want to use __sleep() because its quite |
|
301 | - * possible that this class is defined when it goes to sleep, but NOT available when it |
|
302 | - * awakes (eg, this class is part of an addon that is deactivated at some point). |
|
303 | - */ |
|
304 | - public function properties_as_array() |
|
305 | - { |
|
306 | - $properties = get_object_vars($this); |
|
307 | - $properties['class'] = get_class($this); |
|
308 | - unset($properties['_migration_script']); |
|
309 | - unset($properties['_table_manager']); |
|
310 | - unset($properties['_table_analysis']); |
|
311 | - return $properties; |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Sets all of the properties of this script stage to match what's in the array, which is assumed |
|
316 | - * to have been made from the properties_as_array() function. |
|
317 | - * |
|
318 | - * @param array $array_of_properties like what's produced from properties_as_array() method |
|
319 | - */ |
|
320 | - abstract public function instantiate_from_array_of_properties($array_of_properties); |
|
321 | - |
|
322 | - /** |
|
323 | - * Convenience method for showing a database insertion error |
|
324 | - * |
|
325 | - * @param string $old_table |
|
326 | - * @param array $old_row_as_array |
|
327 | - * @param string $new_table |
|
328 | - * @param array $new_row_as_array columns=>values like used in wpdb->insert |
|
329 | - * @param array $data_types numerically indexed |
|
330 | - * @return string |
|
331 | - */ |
|
332 | - protected function _create_error_message_for_db_insertion( |
|
333 | - $old_table, |
|
334 | - $old_row_as_array, |
|
335 | - $new_table, |
|
336 | - $new_row_as_array, |
|
337 | - $data_types |
|
338 | - ) { |
|
339 | - global $wpdb; |
|
340 | - $old_columns_and_values_for_string = array(); |
|
341 | - foreach ($old_row_as_array as $column => $value) { |
|
342 | - $old_columns_and_values_for_string[] = "$column => $value"; |
|
343 | - } |
|
344 | - $new_columns_and_values_for_string = array(); |
|
345 | - $count = 0; |
|
346 | - foreach ($new_row_as_array as $column => $value) { |
|
347 | - $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")"; |
|
348 | - } |
|
349 | - return sprintf( |
|
350 | - esc_html__( |
|
351 | - 'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.', |
|
352 | - 'event_espresso' |
|
353 | - ), |
|
354 | - implode(", ", $new_columns_and_values_for_string), |
|
355 | - $new_table, |
|
356 | - implode(", ", $old_columns_and_values_for_string), |
|
357 | - $old_table, |
|
358 | - '<br/>', |
|
359 | - $wpdb->last_error |
|
360 | - ); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * Same as json_encode, just avoids putting |
|
366 | - * serialized arrays into the http build query, as that would |
|
367 | - * |
|
368 | - * @param array $array_of_data |
|
369 | - * @return string |
|
370 | - */ |
|
371 | - protected function _json_encode($array_of_data) |
|
372 | - { |
|
373 | - // we'd rather NOT serialize the transaction details |
|
374 | - $fields_to_include = array(); |
|
375 | - foreach ($array_of_data as $name => $value) { |
|
376 | - $unserialized_data = @unserialize($value); |
|
377 | - if ($unserialized_data === false) { |
|
378 | - $fields_to_include[ $name ] = $value; |
|
379 | - } |
|
380 | - } |
|
381 | - return wp_json_encode($fields_to_include); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Gets the table manager (or throws an exception if it cannot be retrieved) |
|
386 | - * |
|
387 | - * @return TableManager |
|
388 | - * @throws EE_Error |
|
389 | - */ |
|
390 | - protected function _get_table_manager() |
|
391 | - { |
|
392 | - if ($this->_table_manager instanceof TableManager) { |
|
393 | - return $this->_table_manager; |
|
394 | - } else { |
|
395 | - throw new EE_Error( |
|
396 | - sprintf( |
|
397 | - esc_html__('Table manager on migration class %1$s is not set properly.', 'event_espresso'), |
|
398 | - get_class($this) |
|
399 | - ) |
|
400 | - ); |
|
401 | - } |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Gets the injected table analyzer, or throws an exception |
|
406 | - * |
|
407 | - * @return TableAnalysis |
|
408 | - * @throws EE_Error |
|
409 | - */ |
|
410 | - protected function _get_table_analysis() |
|
411 | - { |
|
412 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
413 | - return $this->_table_analysis; |
|
414 | - } else { |
|
415 | - throw new EE_Error( |
|
416 | - sprintf( |
|
417 | - esc_html__('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'), |
|
418 | - get_class($this) |
|
419 | - ) |
|
420 | - ); |
|
421 | - } |
|
422 | - } |
|
19 | + /** |
|
20 | + * @var $records_to_migrate int count of all that have been migrated |
|
21 | + */ |
|
22 | + protected $_records_to_migrate = 0; |
|
23 | + |
|
24 | + /** |
|
25 | + * |
|
26 | + * @var $records_migrated int |
|
27 | + */ |
|
28 | + protected $_records_migrated = 0; |
|
29 | + |
|
30 | + /** |
|
31 | + * Whether this migration script is done or not. This COULD be deduced by |
|
32 | + * _records_to_migrate and _records_migrated, but that might nto be accurate |
|
33 | + * |
|
34 | + * @var string one of EE_Data_migration_Manager::status_* constants |
|
35 | + */ |
|
36 | + protected $_status = null; |
|
37 | + |
|
38 | + /** |
|
39 | + * internationalized name of this class. Convention is to NOT restate that |
|
40 | + * this class if a migration script or a migration script stage |
|
41 | + * |
|
42 | + * @var string (i18ned) |
|
43 | + */ |
|
44 | + protected $_pretty_name = null; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $_errors = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
53 | + */ |
|
54 | + protected $_table_manager; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
58 | + */ |
|
59 | + protected $_table_analysis; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Just initializes the status of the migration |
|
64 | + * |
|
65 | + * @param TableManager $table_manager |
|
66 | + * @param TableAnalysis $table_analysis |
|
67 | + */ |
|
68 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
69 | + { |
|
70 | + $this->_table_manager = $table_manager; |
|
71 | + $this->_table_analysis = $table_analysis; |
|
72 | + $this->set_status(EE_Data_Migration_Manager::status_continue); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Just gets the pretty name for this migration script or stage |
|
78 | + * |
|
79 | + * @throws EE_Error |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function pretty_name() |
|
83 | + { |
|
84 | + if ($this->_pretty_name === null) { |
|
85 | + throw new EE_Error( |
|
86 | + sprintf( |
|
87 | + esc_html__( |
|
88 | + "Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor", |
|
89 | + "event_espresso" |
|
90 | + ), |
|
91 | + get_class($this) |
|
92 | + ) |
|
93 | + ); |
|
94 | + } |
|
95 | + return $this->_pretty_name; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * |
|
100 | + * @return int |
|
101 | + */ |
|
102 | + public function count_records_to_migrate() |
|
103 | + { |
|
104 | + if ($this->_records_to_migrate == null) { |
|
105 | + $this->_records_to_migrate = $this->_count_records_to_migrate(); |
|
106 | + } |
|
107 | + return $this->_records_to_migrate; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and |
|
112 | + * EE_Data_migration_Script_Stage |
|
113 | + * |
|
114 | + * @return int |
|
115 | + */ |
|
116 | + abstract public function count_records_migrated(); |
|
117 | + |
|
118 | + /** |
|
119 | + * Counts the records to migrate; the public version may cache it |
|
120 | + * |
|
121 | + * @return int |
|
122 | + */ |
|
123 | + abstract protected function _count_records_to_migrate(); |
|
124 | + |
|
125 | + /** |
|
126 | + * Returns a string indicating the migration script's status. |
|
127 | + * |
|
128 | + * @return string one of EE_Data_Migration_Manager::status_* constants |
|
129 | + * @throws EE_Error |
|
130 | + */ |
|
131 | + public function get_status() |
|
132 | + { |
|
133 | + if ($this->_status === null) { |
|
134 | + throw new EE_Error( |
|
135 | + sprintf( |
|
136 | + esc_html__( |
|
137 | + "Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.", |
|
138 | + "event_espresso" |
|
139 | + ), |
|
140 | + get_class($this) |
|
141 | + ) |
|
142 | + ); |
|
143 | + } |
|
144 | + return $this->_status; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * |
|
149 | + * @param string $status |
|
150 | + * @return void |
|
151 | + */ |
|
152 | + protected function set_status($status) |
|
153 | + { |
|
154 | + $this->_status = $status; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @return array of strings |
|
159 | + */ |
|
160 | + abstract public function get_errors(); |
|
161 | + |
|
162 | + /** |
|
163 | + * Returns the last error that occurred. If none occurred, returns null |
|
164 | + * |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + public function get_last_error() |
|
168 | + { |
|
169 | + $errors = $this->get_errors(); |
|
170 | + if ($errors) { |
|
171 | + return end($errors); |
|
172 | + } else { |
|
173 | + return null; |
|
174 | + } |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Adds an error to the array of errors on this class. |
|
179 | + * |
|
180 | + * @param string $error a string describing the error that will be useful for debugging. Consider including all |
|
181 | + * the data that led to the error, and a stack trace etc. |
|
182 | + * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are |
|
183 | + * already at their limit, we will purposefully forget the first half |
|
184 | + */ |
|
185 | + public function add_error($error, $force = false) |
|
186 | + { |
|
187 | + if (! defined('EE_DMS_ERROR_LIMIT')) { |
|
188 | + $limit = 50; |
|
189 | + } else { |
|
190 | + $limit = EE_DMS_ERROR_LIMIT; |
|
191 | + } |
|
192 | + // make sure errors is an array, see ticket #8261 |
|
193 | + if (is_string($this->_errors)) { |
|
194 | + $this->_errors = array($this->_errors); |
|
195 | + } |
|
196 | + if (count($this->_errors) >= $limit) { |
|
197 | + if ($force) { |
|
198 | + // get rid of the first half of the errors and any above the limit |
|
199 | + $this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2); |
|
200 | + $this->_errors[] = "Limit reached; removed first half of errors to save space"; |
|
201 | + $this->_errors[] = $error; |
|
202 | + } else { |
|
203 | + $this->_errors[ $limit ] = 'More, but limit reached...'; |
|
204 | + } |
|
205 | + } else { |
|
206 | + $this->_errors[] = $error; |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Indicates there was a fatal error and the migration cannot possibly continue |
|
212 | + * |
|
213 | + * @return boolean |
|
214 | + */ |
|
215 | + public function is_broken() |
|
216 | + { |
|
217 | + return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @deprecated since 4.6.12 |
|
222 | + */ |
|
223 | + public function is_borked() |
|
224 | + { |
|
225 | + EE_Error::doing_it_wrong( |
|
226 | + 'is_borked', |
|
227 | + esc_html__( |
|
228 | + 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', |
|
229 | + 'event_espresso' |
|
230 | + ), |
|
231 | + '4.6.12' |
|
232 | + ); |
|
233 | + return $this->is_broken(); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Sets the status to as having a fatal error |
|
238 | + */ |
|
239 | + public function set_broken() |
|
240 | + { |
|
241 | + $this->_status = EE_Data_Migration_Manager::status_fatal_error; |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * |
|
246 | + * @deprecated since 4.6.12 |
|
247 | + */ |
|
248 | + public function set_borked() |
|
249 | + { |
|
250 | + EE_Error::doing_it_wrong( |
|
251 | + 'is_borked', |
|
252 | + esc_html__( |
|
253 | + 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', |
|
254 | + 'event_espresso' |
|
255 | + ), |
|
256 | + '4.6.12' |
|
257 | + ); |
|
258 | + return $this->set_broken(); |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Checks if this thing believes it is completed |
|
263 | + * |
|
264 | + * @return boolean |
|
265 | + */ |
|
266 | + public function is_completed() |
|
267 | + { |
|
268 | + return $this->get_status() == EE_Data_Migration_Manager::status_completed; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Checks if the current script has more to do or not (ie, if it's status is CONTINUE) |
|
273 | + * |
|
274 | + * @return boolean |
|
275 | + */ |
|
276 | + public function has_more_to_do() |
|
277 | + { |
|
278 | + return $this->get_status() == EE_Data_Migration_Manager::status_continue; |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Marks that we believe this migration thing is completed |
|
283 | + */ |
|
284 | + public function set_completed() |
|
285 | + { |
|
286 | + $this->_status = EE_Data_Migration_Manager::status_completed; |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Marks that we think this migration class can continue to migrate |
|
291 | + */ |
|
292 | + public function reattempt() |
|
293 | + { |
|
294 | + $this->_status = EE_Data_Migration_Manager::status_continue; |
|
295 | + $this->add_error(esc_html__('Reattempt migration', 'event_espresso'), true); |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class' |
|
300 | + * properties to the DB. However, we don't want to use __sleep() because its quite |
|
301 | + * possible that this class is defined when it goes to sleep, but NOT available when it |
|
302 | + * awakes (eg, this class is part of an addon that is deactivated at some point). |
|
303 | + */ |
|
304 | + public function properties_as_array() |
|
305 | + { |
|
306 | + $properties = get_object_vars($this); |
|
307 | + $properties['class'] = get_class($this); |
|
308 | + unset($properties['_migration_script']); |
|
309 | + unset($properties['_table_manager']); |
|
310 | + unset($properties['_table_analysis']); |
|
311 | + return $properties; |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Sets all of the properties of this script stage to match what's in the array, which is assumed |
|
316 | + * to have been made from the properties_as_array() function. |
|
317 | + * |
|
318 | + * @param array $array_of_properties like what's produced from properties_as_array() method |
|
319 | + */ |
|
320 | + abstract public function instantiate_from_array_of_properties($array_of_properties); |
|
321 | + |
|
322 | + /** |
|
323 | + * Convenience method for showing a database insertion error |
|
324 | + * |
|
325 | + * @param string $old_table |
|
326 | + * @param array $old_row_as_array |
|
327 | + * @param string $new_table |
|
328 | + * @param array $new_row_as_array columns=>values like used in wpdb->insert |
|
329 | + * @param array $data_types numerically indexed |
|
330 | + * @return string |
|
331 | + */ |
|
332 | + protected function _create_error_message_for_db_insertion( |
|
333 | + $old_table, |
|
334 | + $old_row_as_array, |
|
335 | + $new_table, |
|
336 | + $new_row_as_array, |
|
337 | + $data_types |
|
338 | + ) { |
|
339 | + global $wpdb; |
|
340 | + $old_columns_and_values_for_string = array(); |
|
341 | + foreach ($old_row_as_array as $column => $value) { |
|
342 | + $old_columns_and_values_for_string[] = "$column => $value"; |
|
343 | + } |
|
344 | + $new_columns_and_values_for_string = array(); |
|
345 | + $count = 0; |
|
346 | + foreach ($new_row_as_array as $column => $value) { |
|
347 | + $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")"; |
|
348 | + } |
|
349 | + return sprintf( |
|
350 | + esc_html__( |
|
351 | + 'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.', |
|
352 | + 'event_espresso' |
|
353 | + ), |
|
354 | + implode(", ", $new_columns_and_values_for_string), |
|
355 | + $new_table, |
|
356 | + implode(", ", $old_columns_and_values_for_string), |
|
357 | + $old_table, |
|
358 | + '<br/>', |
|
359 | + $wpdb->last_error |
|
360 | + ); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * Same as json_encode, just avoids putting |
|
366 | + * serialized arrays into the http build query, as that would |
|
367 | + * |
|
368 | + * @param array $array_of_data |
|
369 | + * @return string |
|
370 | + */ |
|
371 | + protected function _json_encode($array_of_data) |
|
372 | + { |
|
373 | + // we'd rather NOT serialize the transaction details |
|
374 | + $fields_to_include = array(); |
|
375 | + foreach ($array_of_data as $name => $value) { |
|
376 | + $unserialized_data = @unserialize($value); |
|
377 | + if ($unserialized_data === false) { |
|
378 | + $fields_to_include[ $name ] = $value; |
|
379 | + } |
|
380 | + } |
|
381 | + return wp_json_encode($fields_to_include); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Gets the table manager (or throws an exception if it cannot be retrieved) |
|
386 | + * |
|
387 | + * @return TableManager |
|
388 | + * @throws EE_Error |
|
389 | + */ |
|
390 | + protected function _get_table_manager() |
|
391 | + { |
|
392 | + if ($this->_table_manager instanceof TableManager) { |
|
393 | + return $this->_table_manager; |
|
394 | + } else { |
|
395 | + throw new EE_Error( |
|
396 | + sprintf( |
|
397 | + esc_html__('Table manager on migration class %1$s is not set properly.', 'event_espresso'), |
|
398 | + get_class($this) |
|
399 | + ) |
|
400 | + ); |
|
401 | + } |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Gets the injected table analyzer, or throws an exception |
|
406 | + * |
|
407 | + * @return TableAnalysis |
|
408 | + * @throws EE_Error |
|
409 | + */ |
|
410 | + protected function _get_table_analysis() |
|
411 | + { |
|
412 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
413 | + return $this->_table_analysis; |
|
414 | + } else { |
|
415 | + throw new EE_Error( |
|
416 | + sprintf( |
|
417 | + esc_html__('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'), |
|
418 | + get_class($this) |
|
419 | + ) |
|
420 | + ); |
|
421 | + } |
|
422 | + } |
|
423 | 423 | } |