Changeset 13774 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats-print.php
- Timestamp:
- 06/04/2024 02:53:48 PM (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats-print.php
r12114 r13774 3 3 namespace WordPressdotorg\GlotPress\Customizations\CLI; 4 4 5 use DateTime; 5 6 use WP_CLI; 6 7 use WP_CLI_Command; … … 8 9 class Stats_Print extends WP_CLI_Command { 9 10 11 /** 12 * Prints statistics starting from a specified date. 13 * 14 * ## OPTIONS 15 * 16 * [--start_date=<start_date>] 17 * : The start date for the statistics in 'Y-m-d' format. 18 * If not provided, defaults to one week before the current date. 19 * 20 * ## EXAMPLES 21 * 22 * # Print statistics starting from one week before the current date. 23 * wp wporg-translate show-stats --url=translate.wordpress.org 24 * 25 * # Print statistics starting from 2023-10-25. 26 * wp wporg-translate show-stats --start_date=2023-10-25 --url=translate.wordpress.org 27 * 28 * @param array $args Positional arguments. 29 * @param array $assoc_args Associative arguments. 30 */ 10 31 public function __invoke( $args, $assoc_args ) { 32 if ( !isset( $assoc_args['start_date'] ) ) { 33 $start_date = date( 'Y-m-d', strtotime( '-1 week' ) ); 34 } else { 35 $start_date = $assoc_args['start_date']; 36 $start_datetime = DateTime::createFromFormat( 'Y-m-d', $start_date ) ; 37 $is_valid_date = $start_datetime && $start_datetime->format( 'Y-m-d' ) === $start_date; 38 if ( ! $is_valid_date ) { 39 WP_CLI::error( 'The --start_date parameter must be in the format Y-m-d. E.g.: 2023-10-24' ); 40 return; 41 } 42 } 11 43 $stats = new Stats(); 12 $stats( true );44 $stats( true, $start_date ); 13 45 } 14 46 }
Note: See TracChangeset
for help on using the changeset viewer.