Complex classes like EE_Cron_Tasks often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EE_Cron_Tasks, and based on these observations, apply Extract Interface, too.
1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
||
14 | class EE_Cron_Tasks extends EE_Base |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
||
19 | * so we'll set our retry time for just over 10 minutes to avoid that |
||
20 | */ |
||
21 | const reschedule_timeout = 605; |
||
22 | |||
23 | |||
24 | /** |
||
25 | * @var EE_Cron_Tasks |
||
26 | */ |
||
27 | private static $_instance; |
||
28 | |||
29 | |||
30 | /** |
||
31 | * @return EE_Cron_Tasks |
||
32 | * @throws \ReflectionException |
||
33 | * @throws \EE_Error |
||
34 | * @throws \InvalidArgumentException |
||
35 | * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
||
36 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
||
37 | */ |
||
38 | public static function instance() |
||
45 | |||
46 | |||
47 | /** |
||
48 | * @access private |
||
49 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
||
50 | * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
||
51 | * @throws \InvalidArgumentException |
||
52 | * @throws \EE_Error |
||
53 | * @throws \ReflectionException |
||
54 | */ |
||
55 | private function __construct() |
||
113 | |||
114 | |||
115 | /** |
||
116 | * @access protected |
||
117 | * @return void |
||
118 | */ |
||
119 | public static function log_scheduled_ee_crons() |
||
149 | |||
150 | |||
151 | |||
152 | /** |
||
153 | * reschedule_cron_for_transactions_if_maintenance_mode |
||
154 | * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
||
155 | * |
||
156 | * @param string $cron_task |
||
157 | * @param array $TXN_IDs |
||
158 | * @return bool |
||
159 | * @throws \DomainException |
||
160 | */ |
||
161 | public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs) |
||
192 | |||
193 | |||
194 | |||
195 | |||
196 | /**************** UPDATE TRANSACTION WITH PAYMENT ****************/ |
||
197 | /** |
||
198 | * array of TXN IDs and the payment |
||
199 | * |
||
200 | * @var array |
||
201 | */ |
||
202 | protected static $_update_transactions_with_payment = array(); |
||
203 | |||
204 | |||
205 | /** |
||
206 | * schedule_update_transaction_with_payment |
||
207 | * sets a wp_schedule_single_event() for updating any TXNs that may |
||
208 | * require updating due to recently received payments |
||
209 | * |
||
210 | * @param int $timestamp |
||
211 | * @param int $TXN_ID |
||
212 | * @param int $PAY_ID |
||
213 | */ |
||
214 | public static function schedule_update_transaction_with_payment( |
||
231 | |||
232 | |||
233 | /** |
||
234 | * setup_update_for_transaction_with_payment |
||
235 | * this is the callback for the action hook: |
||
236 | * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
||
237 | * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
||
238 | * The passed TXN_ID and associated payment gets added to an array, and then |
||
239 | * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
||
240 | * 'shutdown' which will actually handle the processing of any |
||
241 | * transactions requiring updating, because doing so now would be too early |
||
242 | * and the required resources may not be available |
||
243 | * |
||
244 | * @param int $TXN_ID |
||
245 | * @param int $PAY_ID |
||
246 | */ |
||
247 | public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0) |
||
259 | |||
260 | |||
261 | /** |
||
262 | * update_transaction_with_payment |
||
263 | * loops through the self::$_abandoned_transactions array |
||
264 | * and attempts to finalize any TXNs that have not been completed |
||
265 | * but have had their sessions expired, most likely due to a user not |
||
266 | * returning from an off-site payment gateway |
||
267 | * |
||
268 | * @throws \EE_Error |
||
269 | * @throws \DomainException |
||
270 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
||
271 | * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
||
272 | * @throws \InvalidArgumentException |
||
273 | * @throws \ReflectionException |
||
274 | */ |
||
275 | public static function update_transaction_with_payment() |
||
316 | |||
317 | |||
318 | |||
319 | /************ END OF UPDATE TRANSACTION WITH PAYMENT ************/ |
||
320 | /***************** EXPIRED TRANSACTION CHECK *****************/ |
||
321 | /** |
||
322 | * array of TXN IDs |
||
323 | * |
||
324 | * @var array |
||
325 | */ |
||
326 | protected static $_expired_transactions = array(); |
||
327 | |||
328 | |||
329 | |||
330 | /** |
||
331 | * schedule_expired_transaction_check |
||
332 | * sets a wp_schedule_single_event() for following up on TXNs after their session has expired |
||
333 | * |
||
334 | * @param int $timestamp |
||
335 | * @param int $TXN_ID |
||
336 | */ |
||
337 | public static function schedule_expired_transaction_check( |
||
352 | |||
353 | |||
354 | |||
355 | /** |
||
356 | * expired_transaction_check |
||
357 | * this is the callback for the action hook: |
||
358 | * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check' |
||
359 | * which is utilized by wp_schedule_single_event() |
||
360 | * in \EED_Single_Page_Checkout::_initialize_transaction(). |
||
361 | * The passed TXN_ID gets added to an array, and then the |
||
362 | * process_expired_transactions() function is hooked into |
||
363 | * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
||
364 | * processing of any failed transactions, because doing so now would be |
||
365 | * too early and the required resources may not be available |
||
366 | * |
||
367 | * @param int $TXN_ID |
||
368 | */ |
||
369 | public static function expired_transaction_check($TXN_ID = 0) |
||
380 | |||
381 | |||
382 | |||
383 | /** |
||
384 | * process_expired_transactions |
||
385 | * loops through the self::$_expired_transactions array and processes any failed TXNs |
||
386 | * |
||
387 | * @throws \EE_Error |
||
388 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
||
389 | * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
||
390 | * @throws \InvalidArgumentException |
||
391 | * @throws \ReflectionException |
||
392 | * @throws \DomainException |
||
393 | */ |
||
394 | public static function process_expired_transactions() |
||
489 | |||
490 | |||
491 | |||
492 | /************* END OF EXPIRED TRANSACTION CHECK *************/ |
||
493 | /************* START CLEAN UP BOT TRANSACTIONS **********************/ |
||
494 | |||
495 | |||
496 | |||
497 | /** |
||
498 | * when a transaction is initially made, schedule this check. |
||
499 | * if it has NO REG data by the time it has expired, forget about it |
||
500 | * |
||
501 | * @throws EE_Error |
||
502 | * @throws InvalidArgumentException |
||
503 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
||
504 | * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
||
505 | */ |
||
506 | public static function clean_out_junk_transactions() |
||
514 | |||
515 | |||
516 | |||
517 | /** |
||
518 | * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that. |
||
519 | * |
||
520 | * @throws \EE_Error |
||
521 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
||
522 | * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
||
523 | * @throws \InvalidArgumentException |
||
524 | */ |
||
525 | public static function clean_out_old_gateway_logs() |
||
535 | |||
536 | |||
537 | /***************** FINALIZE ABANDONED TRANSACTIONS *****************/ |
||
538 | /** |
||
539 | * @var array |
||
540 | */ |
||
541 | protected static $_abandoned_transactions = array(); |
||
542 | |||
543 | |||
544 | /** |
||
545 | * @deprecated |
||
546 | * @param int $timestamp |
||
547 | * @param int $TXN_ID |
||
548 | */ |
||
549 | public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID) |
||
553 | |||
554 | |||
555 | /** |
||
556 | * @deprecated |
||
557 | * @param int $TXN_ID |
||
558 | */ |
||
559 | public static function check_for_abandoned_transactions($TXN_ID = 0) |
||
563 | |||
564 | |||
565 | /** |
||
566 | * @deprecated |
||
567 | * @throws \EE_Error |
||
568 | * @throws \DomainException |
||
569 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
||
570 | * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
||
571 | * @throws \InvalidArgumentException |
||
572 | * @throws \ReflectionException |
||
573 | */ |
||
574 | public static function finalize_abandoned_transactions() |
||
593 | |||
594 | |||
595 | |||
596 | /************* END OF FINALIZE ABANDONED TRANSACTIONS *************/ |
||
597 | } |
||
598 | // End of file EE_Cron_Tasks.core.php |
||
600 |