Making WordPress.org

Changeset 10692


Ignore:
Timestamp:
02/17/2021 10:13:23 PM (5 years ago)
Author:
coffee2code
Message:

Developer, CLI: Automatically install latest WP for parsing into temp directory instead of requiring it be done manually beforehand.

Supports parsing of an explicit path via optional --src_path argument.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/cli-commands.php

    r10279 r10692  
    1414         * ## OPTIONS
    1515         *
    16          * <path>
     16         * [--src_path=<src_path>]
    1717         * : The path to a copy of WordPress to be parsed. Should not be code used in
    18          * an active install.
     18         * an active install. If not defined, then the latest version of WordPress will
     19         * be downloaded to a temp directory and parsed.
    1920         *
    2021         * [--user_id=<user_id>]
     
    2324         * ## EXAMPLES
    2425         *
    25          *     # Parse WP 4.9.5 into DevHub.
    26          *     $ wp devhub /home/wporgdev/developer/wp495
     26         *     # Parse lastest WP.
     27         *     $ wp devhub parse
     28         *
     29         *     # Parse specific copy of WP.
     30         *     $ wp devhub parse --src_path=/path/to/wordpress
    2731         *
    2832         * @when after_wp_load
    2933         */
    3034        public function parse( $args, $assoc_args ) {
    31                 list( $path ) = $args;
    32 
     35                $path = $assoc_args['src_path'] ?? null;
     36
     37                // Verify path is a file or directory.
     38                if ( $path ) {
     39                        if ( file_exists( $path ) ) {
     40                                WP_CLI::log( 'Parsing WordPress source from specified directory: ' . $path );
     41                        } else {
     42                                WP_CLI::error( 'Provided path for WordPress source to parse does not exist.' );
     43                        }
     44                 }
     45 
     46                // If no path provided, use a temporary path.
     47                if ( ! $path ) {
     48                        $path = WP_CLI\Utils\get_temp_dir() . 'devhub_' . time();
     49         
     50                        // @todo Attempt to reuse an existing temp dir.
     51                        if ( mkdir( $path ) ) {
     52                                WP_CLI::log( "Installing latest WordPress into temporary directory ({$path})..." );
     53                                $cmd = "core download --path={$path}";
     54                                // Install WP into the temp directory.
     55                                WP_CLI::runcommand( $cmd, [] );
     56                        } else {
     57                                $path = null;
     58                        }
     59                }
     60         
     61                if ( ! $path ) {
     62                        WP_CLI::error( 'Unable to create temporary directory for downloading WordPress. If retrying fails, consider obtaining the files manually and supplying that path via --src_path argument.' );
     63                }
     64
     65                // Determine importing user's ID.
    3366                $user_id = $assoc_args['user_id'] ?? 5911429; // 5911429 = ID for wordpressdotorg
    3467                $user = get_user_by( 'id', $user_id );
     
    4275                        'posts-to-posts' => 'posts-to-posts/posts-to-posts.php',
    4376                ];
    44 
    45                 // Verify path is a file or directory.
    46                 if ( ! file_exists( $path ) ) {
    47                         WP_CLI::error( 'Path for WordPress source to parse does not exist.' );
    48                 }
    4977
    5078                // Verify path is not a file.
Note: See TracChangeset for help on using the changeset viewer.