PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 4.0.9
Visualizer – Tables & Charts Manager with Built-in AI Generator v4.0.9
4.0.9 4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 All 150 releases
visualizer / vendor / woocommerce / action-scheduler / classes / abstracts / ActionScheduler_WPCLI_Command.php

ActionScheduler_WPCLI_Command.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 4.0.9, at vendor/woocommerce/action-scheduler/classes/abstracts/ActionScheduler_WPCLI_Command.php

84 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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