Making WordPress.org

Changeset 5444


Ignore:
Timestamp:
04/30/2017 04:00:54 PM (9 years ago)
Author:
ocean90
Message:

Plugin Directory: Introduce I18n_Import::get_plugin_svn_url() and use it in the code/readme importers.

Also move the constructor to the parent class.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n
Files:
3 edited

Legend:

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

    r5198 r5444  
    22namespace WordPressdotorg\Plugin_Directory\CLI\I18N;
    33
     4use Exception;
    45use WordPressdotorg\Plugin_Directory\Readme\Parser;
     6use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
    57use WordPressdotorg\Plugin_Directory\Tools\SVN;
    6 use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
    7 use Exception;
    88use WP_Error;
    99
     
    1414 */
    1515class Code_Import extends I18n_Import {
    16     const PLUGIN_SVN_BASE = 'https://plugins.svn.wordpress.org';
    17 
    18     /**
    19      * Slug of the plugin.
    20      *
    21      * @var string
    22      */
    23     private $plugin;
    24 
    25     /**
    26      * Constructor.
    27      *
    28      * @param string $plugin The plugin slug.
    29      */
    30     public function __construct( $plugin ) {
    31         $this->plugin = $plugin;
    32     }
    3316
    3417    /**
     
    4023     */
    4124    public function import_from_tag( $tag ) {
    42         $plugin_url = self::PLUGIN_SVN_BASE . "/{$this->plugin}/{$tag}";
     25        $svn_url = $this->get_plugin_svn_url( $tag );
    4326
    44         $files = SVN::ls( $plugin_url );
     27        $files = SVN::ls( $svn_url );
    4528        if ( ! $files ) {
    4629            throw new Exception( "Plugin has no files in {$tag}." );
     
    5033        $export_directory = $tmp_directory . '/export';
    5134
    52         $res = SVN::export( $plugin_url, $export_directory, [ 'ignore-externals' ] );
     35        $res = SVN::export( $svn_url, $export_directory, [ 'ignore-externals' ] );
    5336        if ( ! $res['result'] ) {
    5437            throw new Exception( 'Plugin export failed.' );
     
    5740        $valid = $this->is_plugin_valid( $export_directory );
    5841        if ( is_wp_error( $valid ) ) {
    59             throw new Exception( 'Plugin is not compatible with language packs.' );
     42            throw new Exception( 'Plugin is not compatible with language packs: ' . $valid->get_error_message() );
    6043        }
    6144
     
    6750        $makepot  = new \MakePOT;
    6851
    69         if ( ! $makepot->wp_plugin( $export_directory, $pot_file, $this->plugin ) || ! file_exists( $pot_file ) ) {
     52        if ( $makepot->wp_plugin( $export_directory, $pot_file, $this->plugin ) || ! file_exists( $pot_file ) ) {
    7053            throw new Exception( "POT file couldn't be created." );
    7154        }
     
    9477     */
    9578    private function is_plugin_valid( $export_directory ) {
    96         $error  = new WP_Error();
    9779        $readme = new Parser( $this->find_readme_file( $export_directory ) );
    9880
    9981        // Whether plugin files should be checked for valid text domains.
    10082        if ( empty( $readme->requires ) || version_compare( $readme->requires, '4.6', '<' ) ) {
     83            $error  = new WP_Error();
    10184            $esc_export_directory = escapeshellarg( $export_directory );
    10285
     
    122105                return $error;
    123106            }
    124 
    125107        }
    126108
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n/class-i18n-import.php

    r4223 r5444  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\CLI\I18N;
     3
     4use WordPressdotorg\Plugin_Directory\CLI\Import;
    35use WordPressdotorg\Plugin_Directory\Plugin_I18n;
    46use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
    57use WP_Error;
    6 
    78
    89/**
     
    1213 */
    1314abstract class I18n_Import {
     15
     16    /**
     17     * Slug of the plugin.
     18     *
     19     * @var string
     20     */
     21    protected $plugin;
     22
     23    /**
     24     * Constructor.
     25     *
     26     * @param string $plugin The plugin slug.
     27     */
     28    public function __construct( $plugin ) {
     29        $this->plugin = $plugin;
     30    }
     31
     32    /**
     33     * Imports a specific tag to GlotPress.
     34     *
     35     * @param string $tag SVN tag of the import.
     36     *
     37     * @throws Exception
     38     */
     39    abstract public function import_from_tag( $tag );
     40
     41    /**
     42     * Returns the SVN URL for a plugins tag.
     43     *
     44     * @param string $tag SVN tag or 'trunk'.
     45     * @return string Plugins SVN URL.
     46     */
     47    public function get_plugin_svn_url( $tag ) {
     48        if ( 'trunk' === $tag ) {
     49            return Import::PLUGIN_SVN_BASE . "/{$this->plugin}/trunk/";
     50        } else {
     51            return Import::PLUGIN_SVN_BASE . "/{$this->plugin}/tags/{$tag}/";
     52        }
     53    }
    1454
    1555    /**
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n/class-readme-import.php

    r5436 r5444  
    22namespace WordPressdotorg\Plugin_Directory\CLI\I18N;
    33
     4use Exception;
    45use PO;
    56use Translation_Entry;
    6 use WordPressdotorg\Plugin_Directory\Tools\SVN;
    77use WordPressdotorg\Plugin_Directory\Readme\Parser;
    88use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
    9 use Exception;
     9use WordPressdotorg\Plugin_Directory\Tools\SVN;
    1010
    1111/**
     
    1515 */
    1616class Readme_Import extends I18n_Import {
    17     const PLUGIN_SVN_BASE = 'https://plugins.svn.wordpress.org';
    18 
    19     /**
    20      * Slug of the plugin.
    21      *
    22      * @var string
    23      */
    24     private $plugin;
    25 
    26     /**
    27      * Constructor.
    28      *
    29      * @param string $plugin The plugin slug.
    30      */
    31     public function __construct( $plugin ) {
    32         $this->plugin = $plugin;
    33     }
    3417
    3518    /**
     
    4124     */
    4225    public function import_from_tag( $tag ) {
    43         if ( 'trunk' === $tag ) {
    44             $svn_url = self::PLUGIN_SVN_BASE . "/{$this->plugin}/trunk/";
    45         } else {
    46             $svn_url = self::PLUGIN_SVN_BASE . "/{$this->plugin}/tags/{$tag}/";
    47         }
     26        $svn_url = $this->get_plugin_svn_url( $tag );
    4827
    4928        $files = SVN::ls( $svn_url );
Note: See TracChangeset for help on using the changeset viewer.