mailpoet
/
vendor
/
woocommerce
/
action-scheduler
/
classes
/
ActionScheduler_FatalErrorMonitor.php
WP_CLI
1 year ago
abstracts
1 year ago
actions
1 year ago
data-stores
1 year ago
migration
1 year ago
schedules
1 year ago
schema
1 year ago
ActionScheduler_ActionClaim.php
1 year ago
ActionScheduler_ActionFactory.php
1 year ago
ActionScheduler_AdminView.php
1 year ago
ActionScheduler_AsyncRequest_QueueRunner.php
1 year ago
ActionScheduler_Compatibility.php
1 year ago
ActionScheduler_DataController.php
1 year ago
ActionScheduler_DateTime.php
1 year ago
ActionScheduler_Exception.php
4 years ago
ActionScheduler_FatalErrorMonitor.php
1 year ago
ActionScheduler_InvalidActionException.php
1 year ago
ActionScheduler_ListTable.php
1 year ago
ActionScheduler_LogEntry.php
1 year ago
ActionScheduler_NullLogEntry.php
1 year ago
ActionScheduler_OptionLock.php
2 years ago
ActionScheduler_QueueCleaner.php
1 year ago
ActionScheduler_QueueRunner.php
1 year ago
ActionScheduler_SystemInformation.php
1 year ago
ActionScheduler_Versions.php
1 year ago
ActionScheduler_WPCommentCleaner.php
1 year ago
ActionScheduler_wcSystemStatus.php
4 years ago
index.php
3 years ago
ActionScheduler_FatalErrorMonitor.php
46 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | class ActionScheduler_FatalErrorMonitor { |
| 4 | private $claim = null; |
| 5 | private $store = null; |
| 6 | private $action_id = 0; |
| 7 | public function __construct( ActionScheduler_Store $store ) { |
| 8 | $this->store = $store; |
| 9 | } |
| 10 | public function attach( ActionScheduler_ActionClaim $claim ) { |
| 11 | $this->claim = $claim; |
| 12 | add_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) ); |
| 13 | add_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0, 1 ); |
| 14 | add_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0, 0 ); |
| 15 | add_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0, 0 ); |
| 16 | add_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0, 0 ); |
| 17 | } |
| 18 | public function detach() { |
| 19 | $this->claim = null; |
| 20 | $this->untrack_action(); |
| 21 | remove_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) ); |
| 22 | remove_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0 ); |
| 23 | remove_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0 ); |
| 24 | remove_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0 ); |
| 25 | remove_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0 ); |
| 26 | } |
| 27 | public function track_current_action( $action_id ) { |
| 28 | $this->action_id = $action_id; |
| 29 | } |
| 30 | public function untrack_action() { |
| 31 | $this->action_id = 0; |
| 32 | } |
| 33 | public function handle_unexpected_shutdown() { |
| 34 | $error = error_get_last(); |
| 35 | if ( $error ) { |
| 36 | if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ), true ) ) { |
| 37 | if ( ! empty( $this->action_id ) ) { |
| 38 | $this->store->mark_failure( $this->action_id ); |
| 39 | do_action( 'action_scheduler_unexpected_shutdown', $this->action_id, $error ); |
| 40 | } |
| 41 | } |
| 42 | $this->store->release_claim( $this->claim ); |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 |