Making WordPress.org


Ignore:
Timestamp:
05/01/2017 11:00:53 AM (8 years ago)
Author:
ocean90
Message:

Plugin Directory: Update a scheduled job if another i18n import is triggered during the 15 minutes timeframe.

File:
1 edited

Legend:

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

    r5449 r5453  
    1717     */
    1818    public static function queue( $plugin_slug, $plugin_data ) {
    19         // To avoid a situation where two imports run concurrently, if one is already scheduled, run it 1hr later (We'll trigger it after the current one finishes).
    2019        $when_to_run = time() + 15 * MINUTE_IN_SECONDS;
    21         if ( $next_scheuled = Manager::get_scheduled_time( "import_plugin_i18n:{$plugin_slug}", 'last' ) ) {
    22             $when_to_run = $next_scheuled + HOUR_IN_SECONDS;
     20        $next_scheduled = Manager::get_scheduled_time( "import_plugin_i18n:{$plugin_slug}", 'last' );
     21
     22        // Update a scheduled event if it doesn't run in the next minute.
     23        if ( $next_scheduled && $next_scheduled > time() + 1 * MINUTE_IN_SECONDS ) {
     24            $next_scheduled_events = Manager::get_scheduled_events( "import_plugin_i18n:{$plugin_slug}",$next_scheduled );
     25            if ( $next_scheduled_events ) {
     26                $next_scheduled_event = array_shift( $next_scheduled_events );
     27
     28                $next_scheduled_event['args'][0]['tags_touched'] = array_merge(
     29                    $next_scheduled_event['args'][0]['tags_touched'],
     30                    $plugin_data['tags_touched']
     31                );
     32
     33                if ( $plugin_data['readme_touched'] ) {
     34                    $next_scheduled_event['args'][0]['readme_touched'] = true;
     35                }
     36
     37                if ( $plugin_data['code_touched'] ) {
     38                    $next_scheduled_event['args'][0]['code_touched'] = true;
     39                }
     40
     41                if ( $plugin_data['assets_touched'] ) {
     42                    $next_scheduled_event['args'][0]['assets_touched'] = true;
     43                }
     44
     45                $next_scheduled_event['args'][0]['revisions'] = array_merge(
     46                    $next_scheduled_event['args'][0]['revisions'],
     47                    $plugin_data['revisions']
     48                );
     49
     50                $result = Manager::update_scheduled_event( "import_plugin_i18n:{$plugin_slug}", $next_scheduled, $next_scheduled_event );
     51                if ( $result ) {
     52                    return;
     53                }
     54            }
    2355        }
    2456
Note: See TracChangeset for help on using the changeset viewer.