PluginProbe
WANotifier for Forms and Actions / 3.1.1
WANotifier for Forms and Actions v3.1.1
3.1.1 3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 All 67 releases
← All changes | libraries/action-scheduler/classes/ActionScheduler_FatalErrorMonitor.php +57 -14 1.0.23.1.1 View file →
@@ -3,53 +3,96 @@
3 3 /**
4 4 * Class ActionScheduler_FatalErrorMonitor
5 5 */
6 6 class ActionScheduler_FatalErrorMonitor {
7 - /** @var ActionScheduler_ActionClaim */
8 - private $claim = NULL;
9 - /** @var ActionScheduler_Store */
10 - private $store = NULL;
7 +
8 + /**
9 + * ActionScheduler_ActionClaim instance.
10 + *
11 + * @var ActionScheduler_ActionClaim
12 + */
13 + private $claim = null;
14 +
15 + /**
16 + * ActionScheduler_Store instance.
17 + *
18 + * @var ActionScheduler_Store
19 + */
20 + private $store = null;
21 +
22 + /**
23 + * Current action's ID.
24 + *
25 + * @var int
26 + */
11 27 private $action_id = 0;
12 28
29 + /**
30 + * Construct.
31 + *
32 + * @param ActionScheduler_Store $store Action store.
33 + */
13 34 public function __construct( ActionScheduler_Store $store ) {
14 35 $this->store = $store;
15 36 }
16 37
38 + /**
39 + * Start monitoring.
40 + *
41 + * @param ActionScheduler_ActionClaim $claim Claimed actions.
42 + */
17 43 public function attach( ActionScheduler_ActionClaim $claim ) {
18 44 $this->claim = $claim;
19 45 add_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) );
20 46 add_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0, 1 );
21 - add_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0, 0 );
22 - add_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0, 0 );
23 - add_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0, 0 );
47 + add_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0, 0 );
48 + add_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0, 0 );
49 + add_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0, 0 );
24 50 }
25 51
52 + /**
53 + * Stop monitoring.
54 + */
26 55 public function detach() {
27 - $this->claim = NULL;
56 + $this->claim = null;
28 57 $this->untrack_action();
29 58 remove_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) );
30 59 remove_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0 );
31 - remove_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0 );
32 - remove_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0 );
33 - remove_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0 );
60 + remove_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0 );
61 + remove_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0 );
62 + remove_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0 );
34 63 }
35 64
65 + /**
66 + * Track specified action.
67 + *
68 + * @param int $action_id Action ID to track.
69 + */
36 70 public function track_current_action( $action_id ) {
37 71 $this->action_id = $action_id;
38 72 }
39 73
74 + /**
75 + * Un-track action.
76 + */
40 77 public function untrack_action() {
41 78 $this->action_id = 0;
42 79 }
43 80
81 + /**
82 + * Handle unexpected shutdown.
83 + */
44 84 public function handle_unexpected_shutdown() {
45 - if ( $error = error_get_last() ) {
46 - if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ) ) ) {
47 - if ( !empty($this->action_id) ) {
85 + $error = error_get_last();
86 +
87 + if ( $error ) {
88 + if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ), true ) ) {
89 + if ( ! empty( $this->action_id ) ) {
48 90 $this->store->mark_failure( $this->action_id );
49 91 do_action( 'action_scheduler_unexpected_shutdown', $this->action_id, $error );
50 92 }
51 93 }
94 +
52 95 $this->store->release_claim( $this->claim );
53 96 }
54 97 }
55 98 }