PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.5.4
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.5.4
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / vendor / woocommerce / action-scheduler / classes / ActionScheduler_FatalErrorMonitor.php

ActionScheduler_FatalErrorMonitor.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.5.4, at vendor/woocommerce/action-scheduler/classes/ActionScheduler_FatalErrorMonitor.php

83 lines 2.4 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 /** @var ActionScheduler_ActionClaim */
8 private $claim = NULL;
9 /** @var ActionScheduler_Store */
10 private $store = NULL;
11 /** @var int */
12 private $action_id = 0;
13
14 /**
15 * Construct.
16 *
17 * @param ActionScheduler_Store $store Action store.
18 */
19 public function __construct( ActionScheduler_Store $store ) {
20 $this->store = $store;
21 }
22
23 /**
24 * Start monitoring.
25 *
26 * @param ActionScheduler_ActionClaim $claim Claimed actions.
27 */
28 public function attach( ActionScheduler_ActionClaim $claim ) {
29 $this->claim = $claim;
30 add_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) );
31 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 );
35 }
36
37 /**
38 * Stop monitoring.
39 */
40 public function detach() {
41 $this->claim = NULL;
42 $this->untrack_action();
43 remove_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) );
44 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 );
48 }
49
50 /**
51 * Track specified action.
52 *
53 * @param int $action_id Action ID to track.
54 */
55 public function track_current_action( $action_id ) {
56 $this->action_id = $action_id;
57 }
58
59 /**
60 * Un-track action.
61 */
62 public function untrack_action() {
63 $this->action_id = 0;
64 }
65
66 /**
67 * Handle unexpected shutdown.
68 */
69 public function handle_unexpected_shutdown() {
70 $error = error_get_last();
71
72 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) ) {
75 $this->store->mark_failure( $this->action_id );
76 do_action( 'action_scheduler_unexpected_shutdown', $this->action_id, $error );
77 }
78 }
79 $this->store->release_claim( $this->claim );
80 }
81 }
82 }
83