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_wcSystemStatus.php
98 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | class ActionScheduler_wcSystemStatus { |
| 4 | protected $store; |
| 5 | public function __construct( $store ) { |
| 6 | $this->store = $store; |
| 7 | } |
| 8 | public function render() { |
| 9 | $action_counts = $this->store->action_counts(); |
| 10 | $status_labels = $this->store->get_status_labels(); |
| 11 | $oldest_and_newest = $this->get_oldest_and_newest( array_keys( $status_labels ) ); |
| 12 | $this->get_template( $status_labels, $action_counts, $oldest_and_newest ); |
| 13 | } |
| 14 | protected function get_oldest_and_newest( $status_keys ) { |
| 15 | $oldest_and_newest = array(); |
| 16 | foreach ( $status_keys as $status ) { |
| 17 | $oldest_and_newest[ $status ] = array( |
| 18 | 'oldest' => '–', |
| 19 | 'newest' => '–', |
| 20 | ); |
| 21 | if ( 'in-progress' === $status ) { |
| 22 | continue; |
| 23 | } |
| 24 | $oldest_and_newest[ $status ]['oldest'] = $this->get_action_status_date( $status, 'oldest' ); |
| 25 | $oldest_and_newest[ $status ]['newest'] = $this->get_action_status_date( $status, 'newest' ); |
| 26 | } |
| 27 | return $oldest_and_newest; |
| 28 | } |
| 29 | protected function get_action_status_date( $status, $date_type = 'oldest' ) { |
| 30 | $order = 'oldest' === $date_type ? 'ASC' : 'DESC'; |
| 31 | $action = $this->store->query_actions( |
| 32 | array( |
| 33 | 'claimed' => false, |
| 34 | 'status' => $status, |
| 35 | 'per_page' => 1, |
| 36 | 'order' => $order, |
| 37 | ) |
| 38 | ); |
| 39 | if ( ! empty( $action ) ) { |
| 40 | $date_object = $this->store->get_date( $action[0] ); |
| 41 | $action_date = $date_object->format( 'Y-m-d H:i:s O' ); |
| 42 | } else { |
| 43 | $action_date = '–'; |
| 44 | } |
| 45 | return $action_date; |
| 46 | } |
| 47 | protected function get_template( $status_labels, $action_counts, $oldest_and_newest ) { |
| 48 | $as_version = ActionScheduler_Versions::instance()->latest_version(); |
| 49 | $as_datastore = get_class( ActionScheduler_Store::instance() ); |
| 50 | ?> |
| 51 | <table class="wc_status_table widefat" cellspacing="0"> |
| 52 | <thead> |
| 53 | <tr> |
| 54 | <th colspan="5" data-export-label="Action Scheduler"><h2><?php esc_html_e( 'Action Scheduler', 'action-scheduler' ); ?><?php echo wc_help_tip( esc_html__( 'This section shows details of Action Scheduler.', 'action-scheduler' ) ); ?></h2></th> |
| 55 | </tr> |
| 56 | <tr> |
| 57 | <td colspan="2" data-export-label="Version"><?php esc_html_e( 'Version:', 'action-scheduler' ); ?></td> |
| 58 | <td colspan="3"><?php echo esc_html( $as_version ); ?></td> |
| 59 | </tr> |
| 60 | <tr> |
| 61 | <td colspan="2" data-export-label="Data store"><?php esc_html_e( 'Data store:', 'action-scheduler' ); ?></td> |
| 62 | <td colspan="3"><?php echo esc_html( $as_datastore ); ?></td> |
| 63 | </tr> |
| 64 | <tr> |
| 65 | <td><strong><?php esc_html_e( 'Action Status', 'action-scheduler' ); ?></strong></td> |
| 66 | <td class="help"> </td> |
| 67 | <td><strong><?php esc_html_e( 'Count', 'action-scheduler' ); ?></strong></td> |
| 68 | <td><strong><?php esc_html_e( 'Oldest Scheduled Date', 'action-scheduler' ); ?></strong></td> |
| 69 | <td><strong><?php esc_html_e( 'Newest Scheduled Date', 'action-scheduler' ); ?></strong></td> |
| 70 | </tr> |
| 71 | </thead> |
| 72 | <tbody> |
| 73 | <?php |
| 74 | foreach ( $action_counts as $status => $count ) { |
| 75 | // WC uses the 3rd column for export, so we need to display more data in that (hidden when viewed as part of the table) and add an empty 2nd column. |
| 76 | printf( |
| 77 | '<tr><td>%1$s</td><td> </td><td>%2$s<span style="display: none;">, Oldest: %3$s, Newest: %4$s</span></td><td>%3$s</td><td>%4$s</td></tr>', |
| 78 | esc_html( $status_labels[ $status ] ), |
| 79 | esc_html( number_format_i18n( $count ) ), |
| 80 | esc_html( $oldest_and_newest[ $status ]['oldest'] ), |
| 81 | esc_html( $oldest_and_newest[ $status ]['newest'] ) |
| 82 | ); |
| 83 | } |
| 84 | ?> |
| 85 | </tbody> |
| 86 | </table> |
| 87 | <?php |
| 88 | } |
| 89 | public function __call( $name, $arguments ) { |
| 90 | switch ( $name ) { |
| 91 | case 'print': |
| 92 | _deprecated_function( __CLASS__ . '::print()', '2.2.4', __CLASS__ . '::render()' ); |
| 93 | return call_user_func_array( array( $this, 'render' ), $arguments ); |
| 94 | } |
| 95 | return null; |
| 96 | } |
| 97 | } |
| 98 |