Making WordPress.org


Ignore:
Timestamp:
06/04/2024 02:53:48 PM (23 months ago)
Author:
amieiro
Message:

Translation. Add the option to show statistics from the start date we want.

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  
    33namespace WordPressdotorg\GlotPress\Customizations\CLI;
    44
     5use DateTime;
    56use WP_CLI;
    67use WP_CLI_Command;
     
    89class Stats_Print extends WP_CLI_Command  {
    910
     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     */
    1031    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        }
    1143        $stats = new Stats();
    12         $stats( true );
     44        $stats( true, $start_date );
    1345    }
    1446}
Note: See TracChangeset for help on using the changeset viewer.