Making WordPress.org

Changeset 3513


Ignore:
Timestamp:
06/21/2016 08:36:57 AM (8 years ago)
Author:
ocean90
Message:

Translate, Plugin Directory: Trigger a translation sync from dev to stable when originals get imported.

Fixes #1636.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/sync/class-translation-sync.php

    r3060 r3513  
    2222        add_action( 'gp_translation_created', array( $this, 'queue_translation_for_sync' ), 5 );
    2323        add_action( 'gp_translation_saved', array( $this, 'queue_translation_for_sync' ), 5 );
     24        add_action( 'gp_originals_imported', array( $this, 'trigger_translation_sync_on_originals_import' ), 5, 5 );
    2425
    2526        add_action( 'wporg_translate_sync_plugin_translations', array( $this, 'sync_plugin_translations_on_commit' ) );
    2627
    2728        add_action( 'shutdown', array( $this, 'sync_translations' ) );
     29    }
     30
     31    /**
     32     * Triggers a translation sync from dev to stable when originals get imported.
     33     *
     34     * @param string $project_id          Project ID the import was made to.
     35     * @param int    $originals_added     Number or total originals added.
     36     * @param int    $originals_existing  Number of existing originals updated.
     37     * @param int    $originals_obsoleted Number of originals that were marked as obsolete.
     38     * @param int    $originals_fuzzied   Number of originals that were close matches of old ones and thus marked as fuzzy.
     39     */
     40    public function trigger_translation_sync_on_originals_import( $project_id, $originals_added, $originals_existing, $originals_obsoleted, $originals_fuzzied ) {
     41        if ( ! $originals_added && ! $originals_existing && ! $originals_fuzzied && ! $originals_obsoleted ) {
     42            return;
     43        }
     44
     45        $project = GP::$project->get( $project_id );
     46        if ( ! $project || ! $this->project_is_plugin( $project->path ) ) {
     47            return;
     48        }
     49
     50        // Sync translations only if the stable project was updated.
     51        if ( false === strpos( $project->path, '/stable' ) ) {
     52            return;
     53        }
     54
     55        $project_parts  = explode( '/', $project->path ); // wp-plugins/$plugin_slug/$branch
     56        $plugin_slug    = $project_parts[1];
     57        $plugin_project = $project_parts[1] . '/' . $this->project_mapping[ $project_parts[2] ];
     58
     59        wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wporg_translate_sync_plugin_translations', [
     60            'plugin'     => $plugin_slug,
     61            'gp_project' => $plugin_project,
     62        ] );
    2863    }
    2964
     
    3873     */
    3974    public function sync_plugin_translations_on_commit( $args ) {
    40         $project = GP::$project->by_path( 'wp-plugins/' . $args['gp_project'] );
     75        $project = GP::$project->by_path( $this->master_project . '/' . $args['gp_project'] );
    4176        if ( ! $project ) {
    4277            return false;
Note: See TracChangeset for help on using the changeset viewer.