You are here

function l10n_update_worker in Localization update 7.2

Callback: Executes interface translation queue tasks.

The translation update functions executed here are batch operations which are also used in translation update batches. The batch functions may need to be executed multiple times to complete their task, typically this is the translation import function. When a batch function is not finished, a new queue task is created and added to the end of the queue. The batch context data is needed to continue the batch task is stored in the queue with the queue data.

Parameters

array $data: Queue data array containing:

  • Function name.
  • Array of function arguments. Optionally contains the batch context data.

See also

l10n_update_queue_info()

1 string reference to 'l10n_update_worker'
l10n_update_cron_queue_info in ./l10n_update.module
Implements hook_cron_queue_info().

File

./l10n_update.module, line 232
Download translations from remote localization server.

Code

function l10n_update_worker(array $data) {
  module_load_include('batch.inc', 'l10n_update');
  list($function, $args) = $data;

  // We execute batch operation functions here to check, download and import the
  // translation files. Batch functions use a context variable as last argument
  // which is passed by reference. When a batch operation is called for the
  // first time a default batch context is created. When called iterative
  // (usually the batch import function) the batch context is passed through via
  // the queue and is part of the $data.
  $last = count($args) - 1;
  if (!is_array($args[$last]) || !isset($args[$last]['finished'])) {
    $batch_context = array(
      'sandbox' => array(),
      'results' => array(),
      'finished' => 1,
      'message' => '',
    );
  }
  else {
    $batch_context = $args[$last];
    unset($args[$last]);
  }
  $args = array_merge($args, array(
    &$batch_context,
  ));

  // Call the batch operation function.
  call_user_func_array($function, $args);

  // If the batch operation is not finished we create a new queue task to
  // continue the task. This is typically the translation import task.
  if ($batch_context['finished'] < 1) {
    unset($batch_context['strings']);
    $queue = DrupalQueue::get('l10n_update', TRUE);
    $queue
      ->createItem(array(
      $function,
      $args,
    ));
  }
}