Making WordPress.org

Changeset 4564


Ignore:
Timestamp:
12/21/2016 07:40:41 AM (8 years ago)
Author:
dd32
Message:

Plugin Directory: Allow importing of plugins which lack a trunk readme.txt file but have tagged versions.
This is currently supported by the existing directory, and a number of older (and some recent) plugins rely upon this behaviour, since it's easy to support, we might as well continue to do so.

See #1724

File:
1 edited

Legend:

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

    r4520 r4564  
    283283        $tmp_dir = Filesystem::temp_directory( "process-{$plugin_slug}" );
    284284
     285        // We assume the stable tag is trunk to start with.
     286        $stable_tag = 'trunk';
     287
    285288        // Find the trunk readme file, list remotely to avoid checking out the entire directory.
    286         $trunk_files = SVN::ls( self::PLUGIN_SVN_BASE . "/{$plugin_slug}/trunk" );
     289        $trunk_files = SVN::ls( self::PLUGIN_SVN_BASE . "/{$plugin_slug}/trunk" ) ?: array();
     290
     291        // Find the list of tagged versions of the plugin.
     292        $tagged_versions = SVN::ls( "https://plugins.svn.wordpress.org/{$plugin_slug}/tags/" ) ?: array();
     293        $tagged_versions = array_map( function( $item ) {
     294            return rtrim( $item, '/' );
     295        }, $tagged_versions );
     296
     297        // Not all plugins utilise `trunk`, some just tag versions.
    287298        if ( ! $trunk_files ) {
    288             throw new Exception( 'Plugin has no files in trunk.' );
     299            if ( ! $tagged_versions ) {
     300                throw new Exception( 'Plugin has no files in trunk, nor tags.' );
     301            }
     302
     303            $stable_tag = array_reduce( $tagged_versions, function( $a, $b ) {
     304                return version_compare( $a, $b, '>' ) ? $a : $b;
     305            } );
    289306        }
    290307
     
    304321
    305322            $stable_tag = $trunk_readme->stable_tag;
    306         } else {
    307             $stable_tag = 'trunk';
    308323        }
    309324
     
    338353        }
    339354        if ( ! $exported ) {
     355            // Catch the case where exporting a tag finds nothing, but there was nothing in trunk either.
     356            if ( ! $trunk_files ) {
     357                throw new Exception( 'Plugin has no files in trunk, nor tags.' );
     358            }
     359
    340360            $stable_tag = 'trunk';
    341361            // Either stable_tag = trunk, or the stable_tag tag didn't exist.
     
    381401        }
    382402
    383         $tagged_versions = SVN::ls( "https://plugins.svn.wordpress.org/{$plugin_slug}/tags/" ) ?: array();
    384         $tagged_versions = array_map( function( $item ) {
    385             return rtrim( $item, '/' );
    386         }, $tagged_versions );
    387 
    388403        // Find screenshots in the stable plugin folder (but don't overwrite /assets/)
    389404        foreach ( Filesystem::list_files( "$tmp_dir/export/", false /* non-recursive */, '!^screenshot-\d+\.(jpeg|jpg|png|gif)$!' ) as $plugin_screenshot ) {
Note: See TracChangeset for help on using the changeset viewer.