You are here

function l10n_update_batch_status_check in Localization update 7.2

Batch operation callback: Check status of a remote and local po file.

Checks the presence and creation time po translation files in located at remote server location and local file system.

Parameters

string $project: Machine name of the project for which to check the translation status.

string $langcode: Language code of the language for which to check the translation.

array $options: Optional, an array with options that can have the following elements:

  • 'finish_feedback': Whether or not to give feedback to the user when the batch is finished. Optional, defaults to TRUE.
  • 'use_remote': Whether or not to check the remote translation file. Optional, defaults to TRUE.

array $context: The batch context.

1 string reference to 'l10n_update_batch_status_check'
_l10n_update_batch_status_operations in ./l10n_update.compare.inc
Constructs batch operations checking remote translation status.

File

./l10n_update.batch.inc, line 34
Batch process to check the availability of remote or local po files.

Code

function l10n_update_batch_status_check($project, $langcode, $options = array(), &$context) {
  $failure = $checked = FALSE;
  $options += array(
    'finish_feedback' => TRUE,
    'use_remote' => TRUE,
  );
  $source = l10n_update_get_status(array(
    $project,
  ), array(
    $langcode,
  ));
  $source = $source[$project][$langcode];

  // Check the status of local translation files.
  if (isset($source->files[L10N_UPDATE_LOCAL])) {
    if ($file = l10n_update_source_check_file($source)) {
      l10n_update_status_save($source->name, $source->langcode, L10N_UPDATE_LOCAL, $file);
    }
    $checked = TRUE;
  }

  // Check the status of remote translation files.
  if ($options['use_remote'] && isset($source->files[L10N_UPDATE_REMOTE])) {
    $remote_file = $source->files[L10N_UPDATE_REMOTE];
    module_load_include('http.inc', 'l10n_update');
    if ($result = l10n_update_http_check($remote_file->uri)) {

      // Update the file object with the result data. In case of a redirect we
      // store the resulting uri.
      if (!empty($result->updated)) {
        $remote_file->uri = isset($result->redirect_url) ? $result->redirect_url : $remote_file->uri;
        $remote_file->timestamp = $result->updated;
        l10n_update_status_save($source->name, $source->langcode, L10N_UPDATE_REMOTE, $remote_file);
      }

      // @todo What to do with when the file is not found (404)? To prevent
      //   re-checking within the TTL (1day, 1week) we can set a last_checked
      //   timestamp or cache the result.
      $checked = TRUE;
    }
    else {
      $failure = TRUE;
    }
  }

  // Provide user feedback and record success or failure for reporting at the
  // end of the batch.
  if ($options['finish_feedback'] && $checked) {
    $context['results']['files'][] = $source->name;
  }
  if ($failure && !$checked) {
    $context['results']['failed_files'][] = $source->name;
  }
  $context['message'] = t('Checked translation for %project.', array(
    '%project' => $source->project,
  ));
}