@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | /** |
@@ -12,160 +12,160 @@ discard block |
||
12 | 12 | class EE_Cron_Tasks extends EE_Base |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
|
17 | - * so we'll set our retry time for just over 10 minutes to avoid that |
|
18 | - */ |
|
19 | - const reschedule_timeout = 605; |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * @var EE_Cron_Tasks |
|
24 | - */ |
|
25 | - private static $_instance; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @return EE_Cron_Tasks |
|
30 | - */ |
|
31 | - public static function instance() |
|
32 | - { |
|
33 | - if ( ! self::$_instance instanceof EE_Cron_Tasks) { |
|
34 | - self::$_instance = new self(); |
|
35 | - } |
|
36 | - return self::$_instance; |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * @access private |
|
42 | - */ |
|
43 | - private function __construct() |
|
44 | - { |
|
45 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
46 | - // verify that WP Cron is enabled |
|
47 | - if ( |
|
48 | - defined('DISABLE_WP_CRON') |
|
49 | - && DISABLE_WP_CRON |
|
50 | - && is_admin() |
|
51 | - && ! get_option('ee_disabled_wp_cron_check') |
|
52 | - ) { |
|
53 | - /** |
|
54 | - * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before |
|
55 | - * config is loaded. |
|
56 | - * This is intentionally using a anonymous function so that its not easily de-registered. Client code |
|
57 | - * wanting to not have this functionality can just register its own action at a priority after this one to |
|
58 | - * reverse any changes. |
|
59 | - */ |
|
60 | - add_action('AHEE__EE_System__load_core_configuration__complete', function () { |
|
61 | - EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
|
62 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
63 | - add_option('ee_disabled_wp_cron_check', 1, '', false); |
|
64 | - }); |
|
65 | - } |
|
66 | - // UPDATE TRANSACTION WITH PAYMENT |
|
67 | - add_action( |
|
68 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
69 | - array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'), |
|
70 | - 10, 2 |
|
71 | - ); |
|
72 | - // FINALIZE ABANDONED TRANSACTIONS |
|
73 | - add_action( |
|
74 | - 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
75 | - array('EE_Cron_Tasks', 'check_for_abandoned_transactions'), |
|
76 | - 10, 1 |
|
77 | - ); |
|
15 | + /** |
|
16 | + * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
|
17 | + * so we'll set our retry time for just over 10 minutes to avoid that |
|
18 | + */ |
|
19 | + const reschedule_timeout = 605; |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * @var EE_Cron_Tasks |
|
24 | + */ |
|
25 | + private static $_instance; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @return EE_Cron_Tasks |
|
30 | + */ |
|
31 | + public static function instance() |
|
32 | + { |
|
33 | + if ( ! self::$_instance instanceof EE_Cron_Tasks) { |
|
34 | + self::$_instance = new self(); |
|
35 | + } |
|
36 | + return self::$_instance; |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * @access private |
|
42 | + */ |
|
43 | + private function __construct() |
|
44 | + { |
|
45 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
46 | + // verify that WP Cron is enabled |
|
47 | + if ( |
|
48 | + defined('DISABLE_WP_CRON') |
|
49 | + && DISABLE_WP_CRON |
|
50 | + && is_admin() |
|
51 | + && ! get_option('ee_disabled_wp_cron_check') |
|
52 | + ) { |
|
53 | + /** |
|
54 | + * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before |
|
55 | + * config is loaded. |
|
56 | + * This is intentionally using a anonymous function so that its not easily de-registered. Client code |
|
57 | + * wanting to not have this functionality can just register its own action at a priority after this one to |
|
58 | + * reverse any changes. |
|
59 | + */ |
|
60 | + add_action('AHEE__EE_System__load_core_configuration__complete', function () { |
|
61 | + EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
|
62 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
63 | + add_option('ee_disabled_wp_cron_check', 1, '', false); |
|
64 | + }); |
|
65 | + } |
|
66 | + // UPDATE TRANSACTION WITH PAYMENT |
|
67 | + add_action( |
|
68 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
69 | + array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'), |
|
70 | + 10, 2 |
|
71 | + ); |
|
72 | + // FINALIZE ABANDONED TRANSACTIONS |
|
73 | + add_action( |
|
74 | + 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
75 | + array('EE_Cron_Tasks', 'check_for_abandoned_transactions'), |
|
76 | + 10, 1 |
|
77 | + ); |
|
78 | 78 | // EXPIRED TRANSACTION CHECK |
79 | 79 | add_action( |
80 | 80 | 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
81 | 81 | array( 'EE_Cron_Tasks', 'expired_transaction_check' ), |
82 | 82 | 10, 1 |
83 | 83 | ); |
84 | - // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
|
85 | - add_action( |
|
86 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
87 | - array('EE_Cron_Tasks', 'clean_out_junk_transactions') |
|
88 | - ); |
|
89 | - // logging |
|
90 | - add_action( |
|
91 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
92 | - array('EE_Cron_Tasks', 'log_scheduled_ee_crons') |
|
93 | - ); |
|
94 | - EE_Registry::instance()->load_lib('Messages_Scheduler'); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @access protected |
|
100 | - * @return void |
|
101 | - */ |
|
102 | - public static function log_scheduled_ee_crons() |
|
103 | - { |
|
104 | - $ee_crons = array( |
|
105 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment', |
|
106 | - 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
107 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
108 | - ); |
|
109 | - $crons = (array) get_option('cron'); |
|
110 | - if ( ! is_array($crons)) { |
|
111 | - return; |
|
112 | - } |
|
113 | - foreach ($crons as $timestamp => $cron) { |
|
114 | - foreach ($ee_crons as $ee_cron) { |
|
115 | - if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) { |
|
116 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
117 | - foreach ($cron[$ee_cron] as $ee_cron_details) { |
|
118 | - if ( ! empty($ee_cron_details['args'])) { |
|
119 | - do_action( |
|
120 | - 'AHEE_log', |
|
121 | - __CLASS__, |
|
122 | - __FUNCTION__, |
|
123 | - print_r($ee_cron_details['args'], true), |
|
124 | - "{$ee_cron} args" |
|
125 | - ); |
|
126 | - } |
|
127 | - } |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * reschedule_cron_for_transactions_if_maintenance_mode |
|
137 | - * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
|
138 | - * |
|
139 | - * @param string $cron_task |
|
140 | - * @param array $TXN_IDs |
|
141 | - * @return bool |
|
142 | - * @throws \DomainException |
|
143 | - */ |
|
84 | + // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
|
85 | + add_action( |
|
86 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
87 | + array('EE_Cron_Tasks', 'clean_out_junk_transactions') |
|
88 | + ); |
|
89 | + // logging |
|
90 | + add_action( |
|
91 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
92 | + array('EE_Cron_Tasks', 'log_scheduled_ee_crons') |
|
93 | + ); |
|
94 | + EE_Registry::instance()->load_lib('Messages_Scheduler'); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @access protected |
|
100 | + * @return void |
|
101 | + */ |
|
102 | + public static function log_scheduled_ee_crons() |
|
103 | + { |
|
104 | + $ee_crons = array( |
|
105 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment', |
|
106 | + 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
107 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
108 | + ); |
|
109 | + $crons = (array) get_option('cron'); |
|
110 | + if ( ! is_array($crons)) { |
|
111 | + return; |
|
112 | + } |
|
113 | + foreach ($crons as $timestamp => $cron) { |
|
114 | + foreach ($ee_crons as $ee_cron) { |
|
115 | + if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) { |
|
116 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
117 | + foreach ($cron[$ee_cron] as $ee_cron_details) { |
|
118 | + if ( ! empty($ee_cron_details['args'])) { |
|
119 | + do_action( |
|
120 | + 'AHEE_log', |
|
121 | + __CLASS__, |
|
122 | + __FUNCTION__, |
|
123 | + print_r($ee_cron_details['args'], true), |
|
124 | + "{$ee_cron} args" |
|
125 | + ); |
|
126 | + } |
|
127 | + } |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * reschedule_cron_for_transactions_if_maintenance_mode |
|
137 | + * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
|
138 | + * |
|
139 | + * @param string $cron_task |
|
140 | + * @param array $TXN_IDs |
|
141 | + * @return bool |
|
142 | + * @throws \DomainException |
|
143 | + */ |
|
144 | 144 | public static function reschedule_cron_for_transactions_if_maintenance_mode( $cron_task, array $TXN_IDs ) { |
145 | - if( ! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
146 | - throw new \DomainException( |
|
147 | - sprintf( |
|
148 | - __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
|
149 | - $cron_task |
|
150 | - ) |
|
151 | - ); |
|
152 | - } |
|
145 | + if( ! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
146 | + throw new \DomainException( |
|
147 | + sprintf( |
|
148 | + __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
|
149 | + $cron_task |
|
150 | + ) |
|
151 | + ); |
|
152 | + } |
|
153 | 153 | // reschedule the cron if we can't hit the db right now |
154 | 154 | if ( ! EE_Maintenance_Mode::instance()->models_can_query() ) { |
155 | 155 | foreach( $TXN_IDs as $TXN_ID => $additional_vars ) { |
156 | - // ensure $additional_vars is an array |
|
157 | - $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
|
156 | + // ensure $additional_vars is an array |
|
157 | + $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
|
158 | 158 | // reset cron job for the TXN |
159 | - call_user_func_array( |
|
160 | - array('EE_Cron_Tasks', $cron_task), |
|
161 | - array_merge( |
|
162 | - array( |
|
163 | - time() + (10 * MINUTE_IN_SECONDS), |
|
164 | - $TXN_ID |
|
165 | - ), |
|
166 | - $additional_vars |
|
167 | - ) |
|
168 | - ); |
|
159 | + call_user_func_array( |
|
160 | + array('EE_Cron_Tasks', $cron_task), |
|
161 | + array_merge( |
|
162 | + array( |
|
163 | + time() + (10 * MINUTE_IN_SECONDS), |
|
164 | + $TXN_ID |
|
165 | + ), |
|
166 | + $additional_vars |
|
167 | + ) |
|
168 | + ); |
|
169 | 169 | } |
170 | 170 | return true; |
171 | 171 | } |
@@ -175,85 +175,85 @@ discard block |
||
175 | 175 | |
176 | 176 | |
177 | 177 | |
178 | - /**************** UPDATE TRANSACTION WITH PAYMENT ****************/ |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * array of TXN IDs and the payment |
|
183 | - * |
|
184 | - * @var array |
|
185 | - */ |
|
186 | - protected static $_update_transactions_with_payment = array(); |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * schedule_update_transaction_with_payment |
|
191 | - * sets a wp_schedule_single_event() for updating any TXNs that may |
|
192 | - * require updating due to recently received payments |
|
193 | - * |
|
194 | - * @param int $timestamp |
|
195 | - * @param int $TXN_ID |
|
196 | - * @param int $PAY_ID |
|
197 | - */ |
|
198 | - public static function schedule_update_transaction_with_payment( |
|
199 | - $timestamp, |
|
200 | - $TXN_ID, |
|
201 | - $PAY_ID |
|
202 | - ) { |
|
203 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
204 | - // validate $TXN_ID and $timestamp |
|
205 | - $TXN_ID = absint($TXN_ID); |
|
206 | - $timestamp = absint($timestamp); |
|
207 | - if ($TXN_ID && $timestamp) { |
|
208 | - wp_schedule_single_event( |
|
209 | - $timestamp, |
|
210 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
211 | - array($TXN_ID, $PAY_ID) |
|
212 | - ); |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * setup_update_for_transaction_with_payment |
|
219 | - * this is the callback for the action hook: |
|
220 | - * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
|
221 | - * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
|
222 | - * The passed TXN_ID and associated payment gets added to an array, and then |
|
223 | - * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
|
224 | - * 'shutdown' which will actually handle the processing of any |
|
225 | - * transactions requiring updating, because doing so now would be too early |
|
226 | - * and the required resources may not be available |
|
227 | - * |
|
228 | - * @param int $TXN_ID |
|
229 | - * @param int $PAY_ID |
|
230 | - */ |
|
231 | - public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0) |
|
232 | - { |
|
233 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
234 | - if (absint($TXN_ID)) { |
|
235 | - self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID; |
|
236 | - add_action( |
|
237 | - 'shutdown', |
|
238 | - array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
|
239 | - 5 |
|
240 | - ); |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * update_transaction_with_payment |
|
247 | - * loops through the self::$_abandoned_transactions array |
|
248 | - * and attempts to finalize any TXNs that have not been completed |
|
249 | - * but have had their sessions expired, most likely due to a user not |
|
250 | - * returning from an off-site payment gateway |
|
251 | - * |
|
252 | - * @throws \EE_Error |
|
253 | - */ |
|
254 | - public static function update_transaction_with_payment() |
|
255 | - { |
|
256 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
178 | + /**************** UPDATE TRANSACTION WITH PAYMENT ****************/ |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * array of TXN IDs and the payment |
|
183 | + * |
|
184 | + * @var array |
|
185 | + */ |
|
186 | + protected static $_update_transactions_with_payment = array(); |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * schedule_update_transaction_with_payment |
|
191 | + * sets a wp_schedule_single_event() for updating any TXNs that may |
|
192 | + * require updating due to recently received payments |
|
193 | + * |
|
194 | + * @param int $timestamp |
|
195 | + * @param int $TXN_ID |
|
196 | + * @param int $PAY_ID |
|
197 | + */ |
|
198 | + public static function schedule_update_transaction_with_payment( |
|
199 | + $timestamp, |
|
200 | + $TXN_ID, |
|
201 | + $PAY_ID |
|
202 | + ) { |
|
203 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
204 | + // validate $TXN_ID and $timestamp |
|
205 | + $TXN_ID = absint($TXN_ID); |
|
206 | + $timestamp = absint($timestamp); |
|
207 | + if ($TXN_ID && $timestamp) { |
|
208 | + wp_schedule_single_event( |
|
209 | + $timestamp, |
|
210 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
211 | + array($TXN_ID, $PAY_ID) |
|
212 | + ); |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * setup_update_for_transaction_with_payment |
|
219 | + * this is the callback for the action hook: |
|
220 | + * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
|
221 | + * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
|
222 | + * The passed TXN_ID and associated payment gets added to an array, and then |
|
223 | + * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
|
224 | + * 'shutdown' which will actually handle the processing of any |
|
225 | + * transactions requiring updating, because doing so now would be too early |
|
226 | + * and the required resources may not be available |
|
227 | + * |
|
228 | + * @param int $TXN_ID |
|
229 | + * @param int $PAY_ID |
|
230 | + */ |
|
231 | + public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0) |
|
232 | + { |
|
233 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
234 | + if (absint($TXN_ID)) { |
|
235 | + self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID; |
|
236 | + add_action( |
|
237 | + 'shutdown', |
|
238 | + array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
|
239 | + 5 |
|
240 | + ); |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * update_transaction_with_payment |
|
247 | + * loops through the self::$_abandoned_transactions array |
|
248 | + * and attempts to finalize any TXNs that have not been completed |
|
249 | + * but have had their sessions expired, most likely due to a user not |
|
250 | + * returning from an off-site payment gateway |
|
251 | + * |
|
252 | + * @throws \EE_Error |
|
253 | + */ |
|
254 | + public static function update_transaction_with_payment() |
|
255 | + { |
|
256 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
257 | 257 | if ( |
258 | 258 | // are there any TXNs that need cleaning up ? |
259 | 259 | empty( self::$_update_transactions_with_payment ) |
@@ -263,119 +263,119 @@ discard block |
||
263 | 263 | self::$_update_transactions_with_payment |
264 | 264 | ) |
265 | 265 | ) { |
266 | - return; |
|
267 | - } |
|
268 | - /** @type EE_Payment_Processor $payment_processor */ |
|
269 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
270 | - // set revisit flag for payment processor |
|
271 | - $payment_processor->set_revisit(false); |
|
272 | - // load EEM_Transaction |
|
273 | - EE_Registry::instance()->load_model('Transaction'); |
|
274 | - foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
275 | - // reschedule the cron if we can't hit the db right now |
|
276 | - if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
277 | - // reset cron job for updating the TXN |
|
278 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
279 | - time() + EE_Cron_Tasks::reschedule_timeout, |
|
280 | - $TXN_ID, |
|
281 | - $PAY_ID |
|
282 | - ); |
|
283 | - continue; |
|
284 | - } |
|
285 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
286 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
287 | - // verify transaction |
|
288 | - if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) { |
|
289 | - // now try to update the TXN with any payments |
|
290 | - $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
291 | - } |
|
292 | - unset(self::$_update_transactions_with_payment[$TXN_ID]); |
|
293 | - } |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - |
|
298 | - /************ END OF UPDATE TRANSACTION WITH PAYMENT ************/ |
|
299 | - |
|
300 | - |
|
301 | - /***************** FINALIZE ABANDONED TRANSACTIONS *****************/ |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * array of TXN IDs |
|
306 | - * |
|
307 | - * @var array |
|
308 | - */ |
|
309 | - protected static $_abandoned_transactions = array(); |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * schedule_finalize_abandoned_transactions_check |
|
314 | - * sets a wp_schedule_single_event() for finalizing any TXNs that may |
|
315 | - * have been abandoned during the registration process |
|
316 | - * |
|
317 | - * @param int $timestamp |
|
318 | - * @param int $TXN_ID |
|
319 | - */ |
|
320 | - public static function schedule_finalize_abandoned_transactions_check( |
|
321 | - $timestamp, |
|
322 | - $TXN_ID |
|
323 | - ) { |
|
324 | - // validate $TXN_ID and $timestamp |
|
325 | - $TXN_ID = absint($TXN_ID); |
|
326 | - $timestamp = absint($timestamp); |
|
327 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
328 | - if ($TXN_ID && $timestamp) { |
|
329 | - wp_schedule_single_event( |
|
330 | - $timestamp, |
|
331 | - 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
332 | - array($TXN_ID) |
|
333 | - ); |
|
334 | - } |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * check_for_abandoned_transactions |
|
340 | - * this is the callback for the action hook: |
|
341 | - * 'AHEE__EE_Cron_Tasks__espresso_finalize_abandoned_transactions' |
|
342 | - * which is utilized by wp_schedule_single_event() |
|
343 | - * in EE_SPCO_Reg_Step_Payment_Options::_post_payment_processing(). |
|
344 | - * The passed TXN_ID gets added to an array, and then the |
|
345 | - * espresso_finalize_abandoned_transactions() function is hooked into |
|
346 | - * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
347 | - * processing of any abandoned transactions, because doing so now would be |
|
348 | - * too early and the required resources may not be available |
|
349 | - * |
|
350 | - * @param int $TXN_ID |
|
351 | - */ |
|
352 | - public static function check_for_abandoned_transactions($TXN_ID = 0) |
|
353 | - { |
|
354 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
355 | - if (absint($TXN_ID)) { |
|
356 | - self::$_abandoned_transactions[] = $TXN_ID; |
|
357 | - add_action( |
|
358 | - 'shutdown', |
|
359 | - array('EE_Cron_Tasks', 'finalize_abandoned_transactions'), |
|
360 | - 5 |
|
361 | - ); |
|
362 | - } |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - /** |
|
367 | - * finalize_abandoned_transactions |
|
368 | - * loops through the self::$_abandoned_transactions array |
|
369 | - * and attempts to finalize any TXNs that have not been completed |
|
370 | - * but have had their sessions expired, most likely due to a user not |
|
371 | - * returning from an off-site payment gateway |
|
372 | - * |
|
373 | - * @throws \EE_Error |
|
374 | - */ |
|
375 | - public static function finalize_abandoned_transactions() |
|
376 | - { |
|
377 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
378 | - if ( |
|
266 | + return; |
|
267 | + } |
|
268 | + /** @type EE_Payment_Processor $payment_processor */ |
|
269 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
270 | + // set revisit flag for payment processor |
|
271 | + $payment_processor->set_revisit(false); |
|
272 | + // load EEM_Transaction |
|
273 | + EE_Registry::instance()->load_model('Transaction'); |
|
274 | + foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
275 | + // reschedule the cron if we can't hit the db right now |
|
276 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
277 | + // reset cron job for updating the TXN |
|
278 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
279 | + time() + EE_Cron_Tasks::reschedule_timeout, |
|
280 | + $TXN_ID, |
|
281 | + $PAY_ID |
|
282 | + ); |
|
283 | + continue; |
|
284 | + } |
|
285 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
286 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
287 | + // verify transaction |
|
288 | + if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) { |
|
289 | + // now try to update the TXN with any payments |
|
290 | + $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
291 | + } |
|
292 | + unset(self::$_update_transactions_with_payment[$TXN_ID]); |
|
293 | + } |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + |
|
298 | + /************ END OF UPDATE TRANSACTION WITH PAYMENT ************/ |
|
299 | + |
|
300 | + |
|
301 | + /***************** FINALIZE ABANDONED TRANSACTIONS *****************/ |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * array of TXN IDs |
|
306 | + * |
|
307 | + * @var array |
|
308 | + */ |
|
309 | + protected static $_abandoned_transactions = array(); |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * schedule_finalize_abandoned_transactions_check |
|
314 | + * sets a wp_schedule_single_event() for finalizing any TXNs that may |
|
315 | + * have been abandoned during the registration process |
|
316 | + * |
|
317 | + * @param int $timestamp |
|
318 | + * @param int $TXN_ID |
|
319 | + */ |
|
320 | + public static function schedule_finalize_abandoned_transactions_check( |
|
321 | + $timestamp, |
|
322 | + $TXN_ID |
|
323 | + ) { |
|
324 | + // validate $TXN_ID and $timestamp |
|
325 | + $TXN_ID = absint($TXN_ID); |
|
326 | + $timestamp = absint($timestamp); |
|
327 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
328 | + if ($TXN_ID && $timestamp) { |
|
329 | + wp_schedule_single_event( |
|
330 | + $timestamp, |
|
331 | + 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
332 | + array($TXN_ID) |
|
333 | + ); |
|
334 | + } |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * check_for_abandoned_transactions |
|
340 | + * this is the callback for the action hook: |
|
341 | + * 'AHEE__EE_Cron_Tasks__espresso_finalize_abandoned_transactions' |
|
342 | + * which is utilized by wp_schedule_single_event() |
|
343 | + * in EE_SPCO_Reg_Step_Payment_Options::_post_payment_processing(). |
|
344 | + * The passed TXN_ID gets added to an array, and then the |
|
345 | + * espresso_finalize_abandoned_transactions() function is hooked into |
|
346 | + * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
347 | + * processing of any abandoned transactions, because doing so now would be |
|
348 | + * too early and the required resources may not be available |
|
349 | + * |
|
350 | + * @param int $TXN_ID |
|
351 | + */ |
|
352 | + public static function check_for_abandoned_transactions($TXN_ID = 0) |
|
353 | + { |
|
354 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
355 | + if (absint($TXN_ID)) { |
|
356 | + self::$_abandoned_transactions[] = $TXN_ID; |
|
357 | + add_action( |
|
358 | + 'shutdown', |
|
359 | + array('EE_Cron_Tasks', 'finalize_abandoned_transactions'), |
|
360 | + 5 |
|
361 | + ); |
|
362 | + } |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + /** |
|
367 | + * finalize_abandoned_transactions |
|
368 | + * loops through the self::$_abandoned_transactions array |
|
369 | + * and attempts to finalize any TXNs that have not been completed |
|
370 | + * but have had their sessions expired, most likely due to a user not |
|
371 | + * returning from an off-site payment gateway |
|
372 | + * |
|
373 | + * @throws \EE_Error |
|
374 | + */ |
|
375 | + public static function finalize_abandoned_transactions() |
|
376 | + { |
|
377 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
378 | + if ( |
|
379 | 379 | // are there any TXNs that need cleaning up ? |
380 | 380 | empty( self::$_abandoned_transactions ) |
381 | 381 | // reschedule the cron if we can't hit the db right now |
@@ -384,45 +384,45 @@ discard block |
||
384 | 384 | self::$_abandoned_transactions |
385 | 385 | ) |
386 | 386 | ) { |
387 | - return; |
|
388 | - } |
|
389 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
390 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
391 | - // set revisit flag for txn processor |
|
392 | - $transaction_processor->set_revisit(false); |
|
393 | - /** @type EE_Payment_Processor $payment_processor */ |
|
394 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
395 | - // load EEM_Transaction |
|
396 | - EE_Registry::instance()->load_model('Transaction'); |
|
397 | - foreach (self::$_abandoned_transactions as $TXN_ID) { |
|
398 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
399 | - // reschedule the cron if we can't hit the db right now |
|
400 | - if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
401 | - // reset cron job for finalizing the TXN |
|
402 | - EE_Cron_Tasks::schedule_finalize_abandoned_transactions_check( |
|
403 | - time() + EE_Cron_Tasks::reschedule_timeout, |
|
404 | - $TXN_ID |
|
405 | - ); |
|
406 | - continue; |
|
407 | - } |
|
408 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
409 | - // verify transaction |
|
410 | - if ($transaction instanceof EE_Transaction) { |
|
411 | - // don't finalize the TXN if it has already been completed |
|
412 | - if ($transaction->all_reg_steps_completed() === true) { |
|
413 | - continue; |
|
414 | - } |
|
415 | - // let's simulate an IPN here which will trigger any notifications that need to go out |
|
416 | - $payment_processor->update_txn_based_on_payment($transaction, $transaction->last_payment(), true, |
|
417 | - true); |
|
418 | - } |
|
419 | - unset(self::$_abandoned_transactions[$TXN_ID]); |
|
420 | - } |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - |
|
425 | - /************* END OF FINALIZE ABANDONED TRANSACTIONS *************/ |
|
387 | + return; |
|
388 | + } |
|
389 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
390 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
391 | + // set revisit flag for txn processor |
|
392 | + $transaction_processor->set_revisit(false); |
|
393 | + /** @type EE_Payment_Processor $payment_processor */ |
|
394 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
395 | + // load EEM_Transaction |
|
396 | + EE_Registry::instance()->load_model('Transaction'); |
|
397 | + foreach (self::$_abandoned_transactions as $TXN_ID) { |
|
398 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
399 | + // reschedule the cron if we can't hit the db right now |
|
400 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
401 | + // reset cron job for finalizing the TXN |
|
402 | + EE_Cron_Tasks::schedule_finalize_abandoned_transactions_check( |
|
403 | + time() + EE_Cron_Tasks::reschedule_timeout, |
|
404 | + $TXN_ID |
|
405 | + ); |
|
406 | + continue; |
|
407 | + } |
|
408 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
409 | + // verify transaction |
|
410 | + if ($transaction instanceof EE_Transaction) { |
|
411 | + // don't finalize the TXN if it has already been completed |
|
412 | + if ($transaction->all_reg_steps_completed() === true) { |
|
413 | + continue; |
|
414 | + } |
|
415 | + // let's simulate an IPN here which will trigger any notifications that need to go out |
|
416 | + $payment_processor->update_txn_based_on_payment($transaction, $transaction->last_payment(), true, |
|
417 | + true); |
|
418 | + } |
|
419 | + unset(self::$_abandoned_transactions[$TXN_ID]); |
|
420 | + } |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + |
|
425 | + /************* END OF FINALIZE ABANDONED TRANSACTIONS *************/ |
|
426 | 426 | |
427 | 427 | |
428 | 428 | /***************** EXPIRED TRANSACTION CHECK *****************/ |
@@ -491,12 +491,12 @@ discard block |
||
491 | 491 | |
492 | 492 | |
493 | 493 | |
494 | - /** |
|
495 | - * process_expired_transactions |
|
496 | - * loops through the self::$_expired_transactions array and processes any failed TXNs |
|
497 | - * |
|
498 | - * @throws \EE_Error |
|
499 | - */ |
|
494 | + /** |
|
495 | + * process_expired_transactions |
|
496 | + * loops through the self::$_expired_transactions array and processes any failed TXNs |
|
497 | + * |
|
498 | + * @throws \EE_Error |
|
499 | + */ |
|
500 | 500 | public static function process_expired_transactions() { |
501 | 501 | if ( |
502 | 502 | // are there any TXNs that need cleaning up ? |
@@ -507,58 +507,58 @@ discard block |
||
507 | 507 | self::$_expired_transactions |
508 | 508 | ) |
509 | 509 | ) { |
510 | - return; |
|
511 | - } |
|
512 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
513 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
514 | - // set revisit flag for txn processor |
|
515 | - $transaction_processor->set_revisit( false ); |
|
516 | - // load EEM_Transaction |
|
517 | - EE_Registry::instance()->load_model( 'Transaction' ); |
|
518 | - foreach ( self::$_expired_transactions as $TXN_ID ) { |
|
519 | - $transaction = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID ); |
|
520 | - // verify transaction and whether it is failed or not |
|
521 | - if ( $transaction instanceof EE_Transaction) { |
|
522 | - switch( $transaction->status_ID() ) { |
|
523 | - // Completed TXNs |
|
524 | - case EEM_Transaction::complete_status_code : |
|
525 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', $transaction ); |
|
526 | - break; |
|
527 | - // Overpaid TXNs |
|
528 | - case EEM_Transaction::overpaid_status_code : |
|
529 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', $transaction ); |
|
530 | - break; |
|
531 | - // Incomplete TXNs |
|
532 | - case EEM_Transaction::incomplete_status_code : |
|
533 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', $transaction ); |
|
534 | - // todo : merge the finalize_abandoned_transactions cron into this one... |
|
535 | - // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
536 | - break; |
|
537 | - // Failed TXNs |
|
538 | - case EEM_Transaction::failed_status_code : |
|
539 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', $transaction ); |
|
540 | - // todo : perform garbage collection here and remove clean_out_junk_transactions() |
|
541 | - //$registrations = $transaction->registrations(); |
|
542 | - //if ( ! empty( $registrations ) ) { |
|
543 | - // foreach ( $registrations as $registration ) { |
|
544 | - // if ( $registration instanceof EE_Registration ) { |
|
545 | - //$delete_registration = true; |
|
546 | - //if ( $registration->attendee() instanceof EE_Attendee ) { |
|
547 | - // $delete_registration = false; |
|
548 | - //} |
|
549 | - //if ( $delete_registration ) { |
|
550 | - // $registration->delete_permanently(); |
|
551 | - // $registration->delete_related_permanently(); |
|
552 | - //} |
|
553 | - // } |
|
554 | - // } |
|
555 | - //} |
|
556 | - break; |
|
557 | - } |
|
558 | - |
|
559 | - } |
|
560 | - unset( self::$_expired_transactions[ $TXN_ID ] ); |
|
561 | - } |
|
510 | + return; |
|
511 | + } |
|
512 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
513 | + $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
514 | + // set revisit flag for txn processor |
|
515 | + $transaction_processor->set_revisit( false ); |
|
516 | + // load EEM_Transaction |
|
517 | + EE_Registry::instance()->load_model( 'Transaction' ); |
|
518 | + foreach ( self::$_expired_transactions as $TXN_ID ) { |
|
519 | + $transaction = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID ); |
|
520 | + // verify transaction and whether it is failed or not |
|
521 | + if ( $transaction instanceof EE_Transaction) { |
|
522 | + switch( $transaction->status_ID() ) { |
|
523 | + // Completed TXNs |
|
524 | + case EEM_Transaction::complete_status_code : |
|
525 | + do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', $transaction ); |
|
526 | + break; |
|
527 | + // Overpaid TXNs |
|
528 | + case EEM_Transaction::overpaid_status_code : |
|
529 | + do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', $transaction ); |
|
530 | + break; |
|
531 | + // Incomplete TXNs |
|
532 | + case EEM_Transaction::incomplete_status_code : |
|
533 | + do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', $transaction ); |
|
534 | + // todo : merge the finalize_abandoned_transactions cron into this one... |
|
535 | + // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
536 | + break; |
|
537 | + // Failed TXNs |
|
538 | + case EEM_Transaction::failed_status_code : |
|
539 | + do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', $transaction ); |
|
540 | + // todo : perform garbage collection here and remove clean_out_junk_transactions() |
|
541 | + //$registrations = $transaction->registrations(); |
|
542 | + //if ( ! empty( $registrations ) ) { |
|
543 | + // foreach ( $registrations as $registration ) { |
|
544 | + // if ( $registration instanceof EE_Registration ) { |
|
545 | + //$delete_registration = true; |
|
546 | + //if ( $registration->attendee() instanceof EE_Attendee ) { |
|
547 | + // $delete_registration = false; |
|
548 | + //} |
|
549 | + //if ( $delete_registration ) { |
|
550 | + // $registration->delete_permanently(); |
|
551 | + // $registration->delete_related_permanently(); |
|
552 | + //} |
|
553 | + // } |
|
554 | + // } |
|
555 | + //} |
|
556 | + break; |
|
557 | + } |
|
558 | + |
|
559 | + } |
|
560 | + unset( self::$_expired_transactions[ $TXN_ID ] ); |
|
561 | + } |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | |
@@ -566,18 +566,18 @@ discard block |
||
566 | 566 | /************* END OF EXPIRED TRANSACTION CHECK *************/ |
567 | 567 | |
568 | 568 | |
569 | - /************* START CLEAN UP BOT TRANSACTIONS **********************/ |
|
569 | + /************* START CLEAN UP BOT TRANSACTIONS **********************/ |
|
570 | 570 | |
571 | - //when a transaction is initially made, schedule this check. |
|
572 | - //if it has NO REG data by the time it has expired, forget about it |
|
573 | - public static function clean_out_junk_transactions() |
|
574 | - { |
|
575 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
576 | - EEM_Transaction::instance('')->delete_junk_transactions(); |
|
577 | - EEM_Registration::instance('')->delete_registrations_with_no_transaction(); |
|
578 | - EEM_Line_Item::instance('')->delete_line_items_with_no_transaction(); |
|
579 | - } |
|
580 | - } |
|
571 | + //when a transaction is initially made, schedule this check. |
|
572 | + //if it has NO REG data by the time it has expired, forget about it |
|
573 | + public static function clean_out_junk_transactions() |
|
574 | + { |
|
575 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
576 | + EEM_Transaction::instance('')->delete_junk_transactions(); |
|
577 | + EEM_Registration::instance('')->delete_registrations_with_no_transaction(); |
|
578 | + EEM_Line_Item::instance('')->delete_line_items_with_no_transaction(); |
|
579 | + } |
|
580 | + } |
|
581 | 581 | |
582 | 582 | |
583 | 583 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * wanting to not have this functionality can just register its own action at a priority after this one to |
58 | 58 | * reverse any changes. |
59 | 59 | */ |
60 | - add_action('AHEE__EE_System__load_core_configuration__complete', function () { |
|
60 | + add_action('AHEE__EE_System__load_core_configuration__complete', function() { |
|
61 | 61 | EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
62 | 62 | EE_Registry::instance()->NET_CFG->update_config(true, false); |
63 | 63 | add_option('ee_disabled_wp_cron_check', 1, '', false); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | // EXPIRED TRANSACTION CHECK |
79 | 79 | add_action( |
80 | 80 | 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
81 | - array( 'EE_Cron_Tasks', 'expired_transaction_check' ), |
|
81 | + array('EE_Cron_Tasks', 'expired_transaction_check'), |
|
82 | 82 | 10, 1 |
83 | 83 | ); |
84 | 84 | // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
@@ -141,8 +141,8 @@ discard block |
||
141 | 141 | * @return bool |
142 | 142 | * @throws \DomainException |
143 | 143 | */ |
144 | - public static function reschedule_cron_for_transactions_if_maintenance_mode( $cron_task, array $TXN_IDs ) { |
|
145 | - if( ! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
144 | + public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs) { |
|
145 | + if ( ! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
146 | 146 | throw new \DomainException( |
147 | 147 | sprintf( |
148 | 148 | __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
@@ -151,8 +151,8 @@ discard block |
||
151 | 151 | ); |
152 | 152 | } |
153 | 153 | // reschedule the cron if we can't hit the db right now |
154 | - if ( ! EE_Maintenance_Mode::instance()->models_can_query() ) { |
|
155 | - foreach( $TXN_IDs as $TXN_ID => $additional_vars ) { |
|
154 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
155 | + foreach ($TXN_IDs as $TXN_ID => $additional_vars) { |
|
156 | 156 | // ensure $additional_vars is an array |
157 | 157 | $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
158 | 158 | // reset cron job for the TXN |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | do_action('AHEE_log', __CLASS__, __FUNCTION__); |
257 | 257 | if ( |
258 | 258 | // are there any TXNs that need cleaning up ? |
259 | - empty( self::$_update_transactions_with_payment ) |
|
259 | + empty(self::$_update_transactions_with_payment) |
|
260 | 260 | // reschedule the cron if we can't hit the db right now |
261 | 261 | || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
262 | 262 | 'schedule_update_transaction_with_payment', |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | do_action('AHEE_log', __CLASS__, __FUNCTION__); |
378 | 378 | if ( |
379 | 379 | // are there any TXNs that need cleaning up ? |
380 | - empty( self::$_abandoned_transactions ) |
|
380 | + empty(self::$_abandoned_transactions) |
|
381 | 381 | // reschedule the cron if we can't hit the db right now |
382 | 382 | || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
383 | 383 | 'schedule_finalize_abandoned_transactions_check', |
@@ -450,13 +450,13 @@ discard block |
||
450 | 450 | $TXN_ID |
451 | 451 | ) { |
452 | 452 | // validate $TXN_ID and $timestamp |
453 | - $TXN_ID = absint( $TXN_ID ); |
|
454 | - $timestamp = absint( $timestamp ); |
|
455 | - if ( $TXN_ID && $timestamp ) { |
|
453 | + $TXN_ID = absint($TXN_ID); |
|
454 | + $timestamp = absint($timestamp); |
|
455 | + if ($TXN_ID && $timestamp) { |
|
456 | 456 | wp_schedule_single_event( |
457 | 457 | $timestamp, |
458 | 458 | 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
459 | - array( $TXN_ID ) |
|
459 | + array($TXN_ID) |
|
460 | 460 | ); |
461 | 461 | } |
462 | 462 | } |
@@ -478,12 +478,12 @@ discard block |
||
478 | 478 | * |
479 | 479 | * @param int $TXN_ID |
480 | 480 | */ |
481 | - public static function expired_transaction_check( $TXN_ID = 0 ) { |
|
482 | - if ( absint( $TXN_ID )) { |
|
483 | - self::$_expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
481 | + public static function expired_transaction_check($TXN_ID = 0) { |
|
482 | + if (absint($TXN_ID)) { |
|
483 | + self::$_expired_transactions[$TXN_ID] = $TXN_ID; |
|
484 | 484 | add_action( |
485 | 485 | 'shutdown', |
486 | - array( 'EE_Cron_Tasks', 'process_expired_transactions' ), |
|
486 | + array('EE_Cron_Tasks', 'process_expired_transactions'), |
|
487 | 487 | 5 |
488 | 488 | ); |
489 | 489 | } |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | public static function process_expired_transactions() { |
501 | 501 | if ( |
502 | 502 | // are there any TXNs that need cleaning up ? |
503 | - empty( self::$_expired_transactions ) |
|
503 | + empty(self::$_expired_transactions) |
|
504 | 504 | // reschedule the cron if we can't hit the db right now |
505 | 505 | || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
506 | 506 | 'schedule_expired_transaction_check', |
@@ -510,33 +510,33 @@ discard block |
||
510 | 510 | return; |
511 | 511 | } |
512 | 512 | /** @type EE_Transaction_Processor $transaction_processor */ |
513 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
513 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
514 | 514 | // set revisit flag for txn processor |
515 | - $transaction_processor->set_revisit( false ); |
|
515 | + $transaction_processor->set_revisit(false); |
|
516 | 516 | // load EEM_Transaction |
517 | - EE_Registry::instance()->load_model( 'Transaction' ); |
|
518 | - foreach ( self::$_expired_transactions as $TXN_ID ) { |
|
519 | - $transaction = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID ); |
|
517 | + EE_Registry::instance()->load_model('Transaction'); |
|
518 | + foreach (self::$_expired_transactions as $TXN_ID) { |
|
519 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
520 | 520 | // verify transaction and whether it is failed or not |
521 | - if ( $transaction instanceof EE_Transaction) { |
|
522 | - switch( $transaction->status_ID() ) { |
|
521 | + if ($transaction instanceof EE_Transaction) { |
|
522 | + switch ($transaction->status_ID()) { |
|
523 | 523 | // Completed TXNs |
524 | 524 | case EEM_Transaction::complete_status_code : |
525 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', $transaction ); |
|
525 | + do_action('AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', $transaction); |
|
526 | 526 | break; |
527 | 527 | // Overpaid TXNs |
528 | 528 | case EEM_Transaction::overpaid_status_code : |
529 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', $transaction ); |
|
529 | + do_action('AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', $transaction); |
|
530 | 530 | break; |
531 | 531 | // Incomplete TXNs |
532 | 532 | case EEM_Transaction::incomplete_status_code : |
533 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', $transaction ); |
|
533 | + do_action('AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', $transaction); |
|
534 | 534 | // todo : merge the finalize_abandoned_transactions cron into this one... |
535 | 535 | // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
536 | 536 | break; |
537 | 537 | // Failed TXNs |
538 | 538 | case EEM_Transaction::failed_status_code : |
539 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', $transaction ); |
|
539 | + do_action('AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', $transaction); |
|
540 | 540 | // todo : perform garbage collection here and remove clean_out_junk_transactions() |
541 | 541 | //$registrations = $transaction->registrations(); |
542 | 542 | //if ( ! empty( $registrations ) ) { |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | } |
558 | 558 | |
559 | 559 | } |
560 | - unset( self::$_expired_transactions[ $TXN_ID ] ); |
|
560 | + unset(self::$_expired_transactions[$TXN_ID]); |
|
561 | 561 | } |
562 | 562 | } |
563 | 563 |