← All changes
|
vendor/woocommerce/action-scheduler/classes/ActionScheduler_FatalErrorMonitor.php
+30
-14
1.5.4
→
trunk
View file →
| @@ -3,13 +3,28 @@ | ||
| 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; | |
| 11 | - /** @var int */ | |
| 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 | + */ | |
| 12 | 27 | private $action_id = 0; |
| 13 | 28 | |
| 14 | 29 | /** |
| 15 | 30 | * Construct. |
| @@ -28,11 +43,11 @@ | ||
| 28 | 43 | public function attach( ActionScheduler_ActionClaim $claim ) { |
| 29 | 44 | $this->claim = $claim; |
| 30 | 45 | add_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) ); |
| 31 | 46 | add_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0, 1 ); |
| 32 | - add_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0, 0 ); | |
| 33 | - add_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0, 0 ); | |
| 34 | - 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 ); | |
| 35 | 50 | } |
| 36 | 51 | |
| 37 | 52 | /** |
| 38 | 53 | * Stop monitoring. |
| @@ -37,15 +52,15 @@ | ||
| 37 | 52 | /** |
| 38 | 53 | * Stop monitoring. |
| 39 | 54 | */ |
| 40 | 55 | public function detach() { |
| 41 | - $this->claim = NULL; | |
| 56 | + $this->claim = null; | |
| 42 | 57 | $this->untrack_action(); |
| 43 | 58 | remove_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) ); |
| 44 | 59 | remove_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0 ); |
| 45 | - remove_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0 ); | |
| 46 | - remove_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0 ); | |
| 47 | - 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 ); | |
| 48 | 63 | } |
| 49 | 64 | |
| 50 | 65 | /** |
| 51 | 66 | * Track specified action. |
| @@ -69,14 +84,15 @@ | ||
| 69 | 84 | public function handle_unexpected_shutdown() { |
| 70 | 85 | $error = error_get_last(); |
| 71 | 86 | |
| 72 | 87 | if ( $error ) { |
| 73 | - if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ) ) ) { | |
| 74 | - if ( !empty($this->action_id) ) { | |
| 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 ) ) { | |
| 75 | 90 | $this->store->mark_failure( $this->action_id ); |
| 76 | 91 | do_action( 'action_scheduler_unexpected_shutdown', $this->action_id, $error ); |
| 77 | 92 | } |
| 78 | 93 | } |
| 94 | + | |
| 79 | 95 | $this->store->release_claim( $this->claim ); |
| 80 | 96 | } |
| 81 | 97 | } |
| 82 | 98 | } |