jetformbuilder
/
vendor
/
woocommerce
/
action-scheduler
/
classes
/
abstracts
/
ActionScheduler_WPCLI_Command.php
ActionScheduler.php
2 months ago
ActionScheduler_Abstract_ListTable.php
1 year ago
ActionScheduler_Abstract_QueueRunner.php
2 months ago
ActionScheduler_Abstract_RecurringSchedule.php
1 year ago
ActionScheduler_Abstract_Schedule.php
1 year ago
ActionScheduler_Abstract_Schema.php
1 year ago
ActionScheduler_Lock.php
1 year ago
ActionScheduler_Logger.php
1 year ago
ActionScheduler_Store.php
1 year ago
ActionScheduler_TimezoneHelper.php
1 year ago
ActionScheduler_WPCLI_Command.php
1 year ago
ActionScheduler_WPCLI_Command.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Abstract for WP-CLI commands. |
| 5 | */ |
| 6 | abstract class ActionScheduler_WPCLI_Command extends \WP_CLI_Command { |
| 7 | |
| 8 | const DATE_FORMAT = 'Y-m-d H:i:s O'; |
| 9 | |
| 10 | /** |
| 11 | * Keyed arguments. |
| 12 | * |
| 13 | * @var string[] |
| 14 | */ |
| 15 | protected $args; |
| 16 | |
| 17 | /** |
| 18 | * Positional arguments. |
| 19 | * |
| 20 | * @var array<string, string> |
| 21 | */ |
| 22 | protected $assoc_args; |
| 23 | |
| 24 | /** |
| 25 | * Construct. |
| 26 | * |
| 27 | * @param string[] $args Positional arguments. |
| 28 | * @param array<string, string> $assoc_args Keyed arguments. |
| 29 | * @throws \Exception When loading a CLI command file outside of WP CLI context. |
| 30 | */ |
| 31 | public function __construct( array $args, array $assoc_args ) { |
| 32 | if ( ! defined( 'WP_CLI' ) || ! constant( 'WP_CLI' ) ) { |
| 33 | /* translators: %s php class name */ |
| 34 | throw new \Exception( sprintf( __( 'The %s class can only be run within WP CLI.', 'action-scheduler' ), get_class( $this ) ) ); |
| 35 | } |
| 36 | |
| 37 | $this->args = $args; |
| 38 | $this->assoc_args = $assoc_args; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Execute command. |
| 43 | */ |
| 44 | abstract public function execute(); |
| 45 | |
| 46 | /** |
| 47 | * Get the scheduled date in a human friendly format. |
| 48 | * |
| 49 | * @see ActionScheduler_ListTable::get_schedule_display_string() |
| 50 | * @param ActionScheduler_Schedule $schedule Schedule. |
| 51 | * @return string |
| 52 | */ |
| 53 | protected function get_schedule_display_string( ActionScheduler_Schedule $schedule ) { |
| 54 | |
| 55 | $schedule_display_string = ''; |
| 56 | |
| 57 | if ( ! $schedule->get_date() ) { |
| 58 | return '0000-00-00 00:00:00'; |
| 59 | } |
| 60 | |
| 61 | $next_timestamp = $schedule->get_date()->getTimestamp(); |
| 62 | |
| 63 | $schedule_display_string .= $schedule->get_date()->format( static::DATE_FORMAT ); |
| 64 | |
| 65 | return $schedule_display_string; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Transforms arguments with '__' from CSV into expected arrays. |
| 70 | * |
| 71 | * @see \WP_CLI\CommandWithDBObject::process_csv_arguments_to_arrays() |
| 72 | * @link https://github.com/wp-cli/entity-command/blob/c270cc9a2367cb8f5845f26a6b5e203397c91392/src/WP_CLI/CommandWithDBObject.php#L99 |
| 73 | * @return void |
| 74 | */ |
| 75 | protected function process_csv_arguments_to_arrays() { |
| 76 | foreach ( $this->assoc_args as $k => $v ) { |
| 77 | if ( false !== strpos( $k, '__' ) ) { |
| 78 | $this->assoc_args[ $k ] = explode( ',', $v ); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | } |
| 84 |