Action
1 year ago
ActionScheduler_WPCLI_Clean_Command.php
1 year ago
ActionScheduler_WPCLI_QueueRunner.php
1 year ago
ActionScheduler_WPCLI_Scheduler_command.php
1 year ago
Action_Command.php
1 year ago
Migration_Command.php
1 year ago
ProgressBar.php
1 year ago
System_Command.php
1 year ago
index.php
3 years ago
ProgressBar.php
51 lines
| 1 | <?php |
| 2 | namespace Action_Scheduler\WP_CLI; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | class ProgressBar { |
| 5 | protected $total_ticks; |
| 6 | protected $count; |
| 7 | protected $interval; |
| 8 | protected $message; |
| 9 | protected $progress_bar; |
| 10 | public function __construct( $message, $count, $interval = 100 ) { |
| 11 | if ( ! ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
| 12 | throw new \Exception( sprintf( __( 'The %s class can only be run within WP CLI.', 'action-scheduler' ), __CLASS__ ) ); |
| 13 | } |
| 14 | $this->total_ticks = 0; |
| 15 | $this->message = $message; |
| 16 | $this->count = $count; |
| 17 | $this->interval = $interval; |
| 18 | } |
| 19 | public function tick() { |
| 20 | if ( null === $this->progress_bar ) { |
| 21 | $this->setup_progress_bar(); |
| 22 | } |
| 23 | $this->progress_bar->tick(); |
| 24 | $this->total_ticks++; |
| 25 | do_action( 'action_scheduler/progress_tick', $this->total_ticks ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
| 26 | } |
| 27 | public function current() { |
| 28 | return $this->progress_bar ? $this->progress_bar->current() : 0; |
| 29 | } |
| 30 | public function finish() { |
| 31 | if ( null !== $this->progress_bar ) { |
| 32 | $this->progress_bar->finish(); |
| 33 | } |
| 34 | $this->progress_bar = null; |
| 35 | } |
| 36 | public function set_message( $message ) { |
| 37 | $this->message = $message; |
| 38 | } |
| 39 | public function set_count( $count ) { |
| 40 | $this->count = $count; |
| 41 | $this->finish(); |
| 42 | } |
| 43 | protected function setup_progress_bar() { |
| 44 | $this->progress_bar = \WP_CLI\Utils\make_progress_bar( |
| 45 | $this->message, |
| 46 | $this->count, |
| 47 | $this->interval |
| 48 | ); |
| 49 | } |
| 50 | } |
| 51 |