WordPress.org

Making WordPress.org


Ignore:
Timestamp:
12/13/2016 09:44:54 AM (3 years ago)
Author:
dd32
Message:

Plugin Directory: Shift SVN Watching, Plugin Imports, and Plugin i18n imports to Jobs.

See #2330.

File:
1 edited

Legend:

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

    r4195 r4520  
    22namespace WordPressdotorg\Plugin_Directory\CLI;
    33use WordPressdotorg\Plugin_Directory\Plugin_Directory;
     4use WordPressdotorg\Plugin_Directory\Jobs;
    45use WordPressdotorg\Plugin_Directory\Tools\SVN;
    56use Exception;
     
    1415    const SVN_URL      = 'https://plugins.svn.wordpress.org/';
    1516    const PHP          = '/usr/local/bin/php';
    16     const PROCESS_I18N = true;
    17 
    18     public function __construct() {
    19         $this->watch();
    20     }
    2117
    2218    /**
     
    2420     */
    2521    public function watch() {
    26         $svn_rev_option_name = 'svn_rev_' . php_uname( 'n' );
     22        $svn_rev_option_name = 'svn_rev_last_processed';
    2723
    2824        $last_rev_processed = $this->get_option( $svn_rev_option_name );
     
    3733        }
    3834
    39         if ( $last_rev_processed == $head_rev ) {
     35        if ( $last_rev_processed >= $head_rev ) {
    4036            // Nothing to do!
    4137            return;
    4238        }
     39
     40        // We don't want to re-process the last rev processed, so bump past it
     41        $last_rev_processed++;
    4342
    4443        echo "Processing changes from $last_rev_processed to $head_rev..\n";
     
    5150            }
    5251
    53             $esc_plugin_slug  = escapeshellarg( $plugin_slug );
    54             $esc_changed_tags = escapeshellarg( implode( ',', $plugin_data['tags_touched'] ) );
    55             $esc_revision     = escapeshellarg( $plugin_data['revision'] );
     52            Jobs\Plugin_Import::queue( $plugin_slug, $plugin_data );
    5653
    57             $cmd = self::PHP . ' ' . dirname( __DIR__ ) . "/bin/import-plugin.php --plugin {$esc_plugin_slug} --changed-tags {$esc_changed_tags} --revision {$esc_revision}";
    58 
    59             echo "\$$cmd\n";
    60             echo shell_exec( $cmd ) . "\n";
    61 
    62             if ( self::PROCESS_I18N && 'nothing-much' === $plugin_slug ) {
    63                 $plugin     = Plugin_Directory::get_plugin_post( $plugin_slug );
    64                 $stable_tag = $plugin->stable_tag;
    65 
    66                 $i18n_processes = [];
    67                 if ( in_array( 'trunk', $plugin_data['tags_touched'] ) ) {
    68                     if ( $plugin_data['code_touched'] ) {
    69                         $i18n_processes[] = 'trunk|code';
    70                     }
    71                     if ( $plugin_data['readme_touched'] ) {
    72                         $i18n_processes[] = 'trunk|readme';
    73                     }
    74                 }
    75                 if ( in_array( $stable_tag, $plugin_data['tags_touched'] ) ) {
    76                     if ( $plugin_data['code_touched'] ) {
    77                         $i18n_processes[] = "{$stable_tag}|code";
    78                     }
    79                     if ( $plugin_data['readme_touched'] ) {
    80                         $i18n_processes[] = "{$stable_tag}|readme";
    81                     }
    82                 }
    83 
    84                 $this->process_i18n_for_plugin( $plugin_slug, $i18n_processes );
    85             }
    86 
    87             $this->update_option( $svn_rev_option_name, $plugin_data['revision'] );
     54            $this->update_option( $svn_rev_option_name, min( $plugin_data['revisions'] ) );
    8855        }
    8956
    9057        // Update it to HEAD again. We do this as $plugin_data['revision'] may be set to PREVHEAD in the event the latest 2 (or more) commits are to a single plugin.
    9158        $this->update_option( $svn_rev_option_name, $head_rev );
    92     }
    93 
    94     /**
    95      * Processes i18n import tasks.
    96      *
    97      * @param string $plugin_slug
    98      * @param array $i18n_processes
    99      */
    100     protected function process_i18n_for_plugin( $plugin_slug, $i18n_processes ) {
    101         foreach ( $i18n_processes as $process ) {
    102             list( $tag, $type ) = explode( '|', $process );
    103 
    104             $esc_plugin_slug = escapeshellarg( $plugin_slug );
    105             $esc_tag         = escapeshellarg( $tag );
    106             $esc_type        = escapeshellarg( $type );
    107 
    108             $cmd = self::PHP . ' ' . dirname( __DIR__ ) . "/bin/import-plugin-to-glotpress.php --plugin {$esc_plugin_slug} --tag {$esc_tag} --type {$esc_type}";
    109 
    110             echo "\n\$$cmd\n";
    111             echo shell_exec( $cmd ) . "\n";
    112         }
    11359    }
    11460
     
    12369
    12470        $logs = SVN::log( self::SVN_URL, array( $rev, $head_rev ) );
    125         if ( $logs['error'] ) {
    126             throw new Exception( "Could not fetch plugins.svn logs: " . implode( ', ', $logs['error'] ) );
     71        if ( $logs['errors'] ) {
     72            throw new Exception( "Could not fetch plugins.svn logs: " . implode( ', ', $logs['errors'] ) );
    12773        }
    12874
    129         // If no changes (either no log entries, or HEAD was the same as $rev)
    130         if ( ! count( $logs['log'] ) || ( 1 == count( $logs['log'] ) && $rev == array_keys( $logs['log'] )[0] ) ) {
     75        // nothing new to report
     76        if ( ! $logs['log'] ) {
    13177            return array();
    13278        }
     
    14490                    'code_touched' => false,
    14591                    'assets_touched' => false,
    146                     'revision' => PHP_INT_MAX,
     92                    'revisions' => array(),
    14793                );
    14894            }
     
    15096
    15197            // Keep track of the lowest revision number we've seen for this plugin
    152             $plugin['revision'] = min( $plugin['revision'], $log['revision'] );
     98            $plugin['revisions'][] = $log['revision'];
    15399            foreach ( $log['paths'] as $path ) {
    154100                $path_parts = explode('/', trim( $path, '/' ) );
     
    183129        // Sort plugins by minimum revision, it should already be in this order, but double check.
    184130        uasort( $plugins, function( $a, $b ) {
    185             if ( $a['revision'] == $b['revision'] ) {
     131            if ( min( $a['revisions'] ) == min( $b['revisions'] ) ) {
    186132                return 0;
    187133            }
    188134
    189             return ( $a['revision'] < $b['revision'] ) ? -1 : 1;
     135            return ( min( $a['revisions'] ) < min( $b['revisions'] ) ) ? -1 : 1;
    190136        } );
    191137
     
    207153
    208154    /**
    209      * An implementation of `get_option()~ which doesn't utilise the cache.
     155     * An implementation of `get_option()` which doesn't utilise the cache.
    210156     * As this is a long-running script, we don't want to hit an alloptions race condition bug.
    211157     *
Note: See TracChangeset for help on using the changeset viewer.