PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / packages / action-scheduler / classes / ActionScheduler_FatalErrorMonitor.php

ActionScheduler_FatalErrorMonitor.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at packages/action-scheduler/classes/ActionScheduler_FatalErrorMonitor.php

60 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class ActionScheduler_FatalErrorMonitor
5 */
6 class ActionScheduler_FatalErrorMonitor {
7 /**
8 * @var ActionScheduler_ActionClaim
9 */
10 private $claim = NULL;
11 /**
12 * @var ActionScheduler_Store
13 */
14 private $store = NULL;
15 private $action_id = 0;
16
17 public function __construct( ActionScheduler_Store $store ) {
18 $this->store = $store;
19 }
20
21 public function attach( ActionScheduler_ActionClaim $claim ) {
22 $this->claim = $claim;
23 add_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) );
24 add_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0, 1 );
25 add_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0, 0 );
26 add_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0, 0 );
27 add_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0, 0 );
28 }
29
30 public function detach() {
31 $this->claim = NULL;
32 $this->untrack_action();
33 remove_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) );
34 remove_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0 );
35 remove_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0 );
36 remove_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0 );
37 remove_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0 );
38 }
39
40 public function track_current_action( $action_id ) {
41 $this->action_id = $action_id;
42 }
43
44 public function untrack_action() {
45 $this->action_id = 0;
46 }
47
48 public function handle_unexpected_shutdown() {
49 if ( $error = error_get_last() ) {
50 if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ) ) ) {
51 if ( !empty($this->action_id) ) {
52 $this->store->mark_failure( $this->action_id );
53 do_action( 'action_scheduler_unexpected_shutdown', $this->action_id, $error );
54 }
55 }
56 $this->store->release_claim( $this->claim );
57 }
58 }
59 }
60