config = $config; $this->aggregate_site_schema_command_handler = $aggregate_site_schema_command_handler; } /** * Returns the namespace of this command. * * @return string */ public static function get_namespace() { return Main::WP_CLI_NAMESPACE; } /** * Aggregates the schema for a certain site. * * ## OPTIONS * * [--page=] * : The current page to process. * --- * default: 1 * --- * * [--per_page=] * : How many items to process per page. * --- * default: 100 * --- * * [--post_type=] * : The post type to aggregate schema for. * --- * default: 'post' * --- * * ## EXAMPLES * * wp yoast aggregate_site_schema * * @when after_wp_load * * @param array|null $args The arguments. * @param array|null $assoc_args The associative arguments. * * @throws ExitException When the input args are invalid. * @return void */ public function aggregate_site_schema( $args = null, $assoc_args = null ) { if ( isset( $assoc_args['page'] ) && (int) $assoc_args['page'] < 1 ) { WP_CLI::error( \__( 'The value for \'page\' must be a positive integer higher than equal to 1.', 'wordpress-seo' ) ); } if ( isset( $assoc_args['per_page'] ) && (int) $assoc_args['per_page'] < 1 ) { WP_CLI::error( \__( 'The value for \'per_page\' must be a positive integer higher than equal to 1.', 'wordpress-seo' ) ); } $page = (int) $assoc_args['page']; $per_page = (int) $assoc_args['per_page']; $post_type = $assoc_args['post_type']; try { $result = $this->aggregate_site_schema_command_handler->handle( new Aggregate_Site_Schema_Command( $page, $per_page, $post_type ) ); } catch ( Exception $exception ) { WP_CLI::error( \__( 'An error occurred while aggregating the site schema.', 'wordpress-seo' ) ); } $output = WPSEO_Utils::format_json_encode( $result ); $output = \str_replace( "\n", \PHP_EOL . "\t", $output ); WP_CLI::log( $output, ); } }