<commit_before><?php

class Export_Command extends WP_CLI_Command {

	/**
	* Initialize the array of arguments that will be eventually be passed to export_wp
	* @var array
	*/
	public $export_args = array();

	/**
	 * Export content to a WXR file.
	 *
	 * ## OPTIONS
	 *
	 * [--dir=<dirname>]
	 * : Full path to directory where WXR export files should be stored. Defaults
	 * to current working directory.
	 *
	 * [--skip_comments]
	 * : Don't export comments.
	 *
	 * [--max_file_size=<MB>]
	 * : A single export file should have this many megabytes.
	 *
	 * ## FILTERS
	 *
	 * [--start_date=<date>]
	 * : Export only posts published after this date, in format YYYY-MM-DD.
	 *
	 * [--end_date=<date>]
	 * : Export only posts published before this date, in format YYYY-MM-DD.
	 *
	 * [--post_type=<post-type>]
	 * : Export only posts with this post_type. Defaults to all.
	 *
	 * [--post__in=<pid>]
	 * : Export all posts specified as a comma-separated list of IDs.
	 *
	 * [--author=<author>]
	 * : Export only posts by this author. Can be either user login or user ID.
	 *
	 * [--category=<name>]
	 * : Export only posts in this category.
	 *
	 * [--post_status=<status>]
	 * : Export only posts with this status.
	 *
	 * ## EXAMPLES
	 *
	 *     wp export --dir=/tmp/ --user=admin --post_type=post --start_date=2011-01-01 --end_date=2011-12-31
	 *
	 *     wp export --dir=/tmp/ --post__in=123,124,125
	 */
	public function __invoke( $_, $assoc_args ) {
		$defaults = array(
			'dir'             => NULL,
			'start_date'      => NULL,
			'end_date'        => NULL,
			'post_type'       => NULL,
			'author'          => NULL,
			'category'        => NULL,
			'post_status'     => NULL,
			'post__in'        => NULL,
			'skip_comments'   => NULL,
			'max_file_size'   => 15,
		);

		$this->validate_args( wp_parse_args( $assoc_args, $defaults ) );

		if ( !function_exists( 'wp_export' ) ) {
			self::load_export_api();
		}

		WP_CLI::log( 'Starting export process...' );

		add_action( 'wp_export_new_file', function( $file_path ) {
			WP_CLI::log( sprintf( "Writing to file %s", $file_path ) );
		} );

		try {
			wp_export( array(
				'filters' => $this->export_args,
				'writer' => 'WP_Export_Split_Files_Writer',
				'writer_args' => array(
					'max_file_size' => $this->max_file_size * MB_IN_BYTES,
					'destination_directory' => $this->wxr_path,
					'filename_template' => self::get_filename_template()
				)
			) );
		} catch ( Exception $e ) {
			WP_CLI::error( $e->getMessage() );
		}

		WP_CLI::success( 'All done with export.' );
	}

	private static function get_filename_template() {
		$sitename = sanitize_key( get_bloginfo( 'name' ) );
		if ( ! empty( $sitename ) ) {
			$sitename .= '.';
		}
		return $sitename . 'wordpress.' . date( 'Y-m-d' ) . '.%d.xml';
	}

	private static function load_export_api() {
		if ( !defined( 'KB_IN_BYTES' ) ) {
			// Constants for expressing human-readable data sizes
			// in their respective number of bytes.
			define( 'KB_IN_BYTES', 1024 );
			define( 'MB_IN_BYTES', 1024 * KB_IN_BYTES );
			define( 'GB_IN_BYTES', 1024 * MB_IN_BYTES );
			define( 'TB_IN_BYTES', 1024 * GB_IN_BYTES );
			define( 'PB_IN_BYTES', 1024 * TB_IN_BYTES );<commit_msg>Pad export filenames with zeros<commit_after><?php

class Export_Command extends WP_CLI_Command {

	/**
	* Initialize the array of arguments that will be eventually be passed to export_wp
	* @var array
	*/
	public $export_args = array();

	/**
	 * Export content to a WXR file.
	 *
	 * ## OPTIONS
	 *
	 * [--dir=<dirname>]
	 * : Full path to directory where WXR export files should be stored. Defaults
	 * to current working directory.
	 *
	 * [--skip_comments]
	 * : Don't export comments.
	 *
	 * [--max_file_size=<MB>]
	 * : A single export file should have this many megabytes.
	 *
	 * ## FILTERS
	 *
	 * [--start_date=<date>]
	 * : Export only posts published after this date, in format YYYY-MM-DD.
	 *
	 * [--end_date=<date>]
	 * : Export only posts published before this date, in format YYYY-MM-DD.
	 *
	 * [--post_type=<post-type>]
	 * : Export only posts with this post_type. Defaults to all.
	 *
	 * [--post__in=<pid>]
	 * : Export all posts specified as a comma-separated list of IDs.
	 *
	 * [--author=<author>]
	 * : Export only posts by this author. Can be either user login or user ID.
	 *
	 * [--category=<name>]
	 * : Export only posts in this category.
	 *
	 * [--post_status=<status>]
	 * : Export only posts with this status.
	 *
	 * ## EXAMPLES
	 *
	 *     wp export --dir=/tmp/ --user=admin --post_type=post --start_date=2011-01-01 --end_date=2011-12-31
	 *
	 *     wp export --dir=/tmp/ --post__in=123,124,125
	 */
	public function __invoke( $_, $assoc_args ) {
		$defaults = array(
			'dir'             => NULL,
			'start_date'      => NULL,
			'end_date'        => NULL,
			'post_type'       => NULL,
			'author'          => NULL,
			'category'        => NULL,
			'post_status'     => NULL,
			'post__in'        => NULL,
			'skip_comments'   => NULL,
			'max_file_size'   => 15,
		);

		$this->validate_args( wp_parse_args( $assoc_args, $defaults ) );

		if ( !function_exists( 'wp_export' ) ) {
			self::load_export_api();
		}

		WP_CLI::log( 'Starting export process...' );

		add_action( 'wp_export_new_file', function( $file_path ) {
			WP_CLI::log( sprintf( "Writing to file %s", $file_path ) );
		} );

		try {
			wp_export( array(
				'filters' => $this->export_args,
				'writer' => 'WP_Export_Split_Files_Writer',
				'writer_args' => array(
					'max_file_size' => $this->max_file_size * MB_IN_BYTES,
					'destination_directory' => $this->wxr_path,
					'filename_template' => self::get_filename_template()
				)
			) );
		} catch ( Exception $e ) {
			WP_CLI::error( $e->getMessage() );
		}

		WP_CLI::success( 'All done with export.' );
	}

	private static function get_filename_template() {
		$sitename = sanitize_key( get_bloginfo( 'name' ) );
		if ( ! empty( $sitename ) ) {
			$sitename .= '.';
		}
		return $sitename . 'wordpress.' . date( 'Y-m-d' ) . '.%03d.xml';
	}

	private static function load_export_api() {
		if ( !defined( 'KB_IN_BYTES' ) ) {
			// Constants for expressing human-readable data sizes
			// in their respective number of bytes.
			define( 'KB_IN_BYTES', 1024 );
			define( 'MB_IN_BYTES', 1024 * KB_IN_BYTES );
			define( 'GB_IN_BYTES', 1024 * MB_IN_BYTES );
			define( 'TB_IN_BYTES', 1024 * GB_IN_BYTES );
			define( 'PB_IN_BYTES', 1024 * TB_IN_BYTES );
{'fraction_non_alphanumeric': 0.1548769086942973, 'fraction_numerical': 0.01495793081956996, 'mean_word_length': 2.892662219526986, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3272019', 'n_tokens_mistral': 2660, 'n_tokens_neox': 2235, 'n_words': 558}