Making WordPress.org


Ignore:
Timestamp:
05/03/2019 04:40:12 AM (5 years ago)
Author:
dd32
Message:

Plugin Directory: Bin: Add an optional --create argument to the import script to aid debugging in the Meta Environment.

In production, the posts are created automatically upon upload, and this argument should never be needed (Unless someone manually creates the SVNs and then needs to import it to the directory).

Fixes #4377.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/import-plugin.php

    r6287 r8728  
    99ob_start();
    1010
    11 $opts = getopt( '', array( 'url:', 'abspath:', 'plugin:', 'changed-tags:', 'async' ) );
     11$opts = getopt( '', array( 'url:', 'abspath:', 'plugin:', 'changed-tags:', 'async', 'create' ) );
    1212
    1313// Guess the default parameters:
     
    2929}
    3030
    31 $opts['async'] = isset( $opts['async'] );
     31$opts['async']  = isset( $opts['async'] );
     32$opts['create'] = isset( $opts['create'] );
    3233
    3334foreach ( array( 'url', 'abspath', 'plugin' ) as $opt ) {
     
    3536        fwrite( STDERR, "Missing Parameter: $opt\n" );
    3637        fwrite( STDERR, "Usage: php {$argv[0]} --plugin hello-dolly --abspath /home/example/public_html --url https://wordpress.org/plugins/\n" );
     38        fwrite( STDERR, "Optional: --async to queue a job to import, --create to create a Post if none exist.\n" );
    3739        fwrite( STDERR, "--url and --abspath will be guessed if possible.\n" );
    3840        die();
     
    5961$start_time   = microtime( 1 );
    6062
     63// If the create flag is set, check if the post exists first:
     64if ( $opts['create'] && ! Plugin_Directory::get_plugin_post( $plugin_slug ) ) {
     65
     66    $create_result = Plugin_Directory::create_plugin_post( array(
     67        'post_name' => $plugin_slug,
     68    ) );
     69
     70    if ( is_wp_error( $create_result ) ) {
     71        echo "Failed. {$plugin_slug} post was not be found, and failed to be created.\n";
     72        fwrite( STDERR, "[{$plugin_slug}] Plugin Import Failed: " . $create_result->get_error_message() . "\n" );
     73        exit( 1 );
     74    }
     75}
     76
    6177// If async, queue it to be parsed instead.
    6278if ( $opts['async'] ) {
Note: See TracChangeset for help on using the changeset viewer.