function locale_cron_fill_queue

Same name in other branches
  1. 8.9.x core/modules/locale/locale.translation.inc \locale_cron_fill_queue()
  2. 10 core/modules/locale/locale.translation.inc \locale_cron_fill_queue()
  3. 11.x core/modules/locale/locale.translation.inc \locale_cron_fill_queue()

Populate a queue with project to check for translation updates.

1 call to locale_cron_fill_queue()
locale_cron in core/modules/locale/locale.module
Implements hook_cron().

File

core/modules/locale/locale.translation.inc, line 329

Code

function locale_cron_fill_queue() {
    $updates = [];
    $config = \Drupal::config('locale.settings');
    // Determine which project+language should be updated.
    $request_time = \Drupal::time()->getRequestTime();
    $last = $request_time - $config->get('translation.update_interval_days') * 3600 * 24;
    $projects = \Drupal::service('locale.project')->getAll();
    $projects = array_filter($projects, function ($project) {
        return $project['status'] == 1;
    });
    $connection = \Drupal::database();
    $files = $connection->select('locale_file', 'f')
        ->condition('f.project', array_keys($projects), 'IN')
        ->condition('f.last_checked', $last, '<')
        ->fields('f', [
        'project',
        'langcode',
    ])
        ->execute()
        ->fetchAll();
    foreach ($files as $file) {
        $updates[$file->project][] = $file->langcode;
        // Update the last_checked timestamp of the project+language that will
        // be checked for updates.
        $connection->update('locale_file')
            ->fields([
            'last_checked' => $request_time,
        ])
            ->condition('project', $file->project)
            ->condition('langcode', $file->langcode)
            ->execute();
    }
    // For each project+language combination a number of tasks are added to
    // the queue.
    if ($updates) {
        \Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.fetch');
        $options = _locale_translation_default_update_options();
        $queue = \Drupal::queue('locale_translation', TRUE);
        foreach ($updates as $project => $languages) {
            $batch = locale_translation_batch_update_build([
                $project,
            ], $languages, $options);
            foreach ($batch['operations'] as $item) {
                $queue->createItem($item);
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.