WordPress.org

Making WordPress.org


Ignore:
Timestamp:
04/26/2016 10:12:57 PM (5 years ago)
Author:
ocean90
Message:

Translate, Plugin Directory: Add a callback for the sync_plugin_translations hook.

The hook gets triggered by the cron API and starts the sync of plugin translations between two projects.

See #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

    r2931 r3018  
    2323        add_action( 'gp_translation_saved', array( $this, 'queue_translation_for_sync' ), 5 );
    2424
     25        add_action( 'sync_plugin_translations', array( $this, 'sync_plugin_translations_on_commit' ) );
     26
    2527        add_action( 'shutdown', array( $this, 'sync_translations' ) );
     28    }
     29
     30    /**
     31     * Starts the sync of plugin translations between two projects.
     32     *
     33     * Gets trigged by the cron API and the hook `sync_plugin_translations`.
     34     *
     35     * @param array $args Arguments from the job. Should include the path
     36     *                    of the GP project.
     37     * @return bool False on failure, true on success.
     38     */
     39    public function sync_plugin_translations_on_commit( $args ) {
     40        $project = GP::$project->by_path( 'wp-plugins/' . $args['gp_project'] );
     41        if ( ! $project ) {
     42            return false;
     43        }
     44
     45        $translation_sets = GP::$translation_set->by_project_id( $project->id );
     46        if ( ! $translation_sets ) {
     47            return false;
     48        }
     49
     50        foreach ( $translation_sets as $translation_set ) {
     51            if ( 0 == $translation_set->current_count() ) {
     52                continue;
     53            }
     54
     55            // Sync translations in a separate process.
     56            $cmd = WPORGTRANSLATE_WPCLI . ' wporg-translate sync-plugin-translations ' . escapeshellarg( $args['gp_project'] ) . ' ' . escapeshellarg( $translation_set->locale ) . ' --set=' . escapeshellarg( $translation_set->slug );
     57            echo shell_exec( $cmd );
     58        }
     59
     60        return true;
    2661    }
    2762
Note: See TracChangeset for help on using the changeset viewer.