function locale_translation_batch_status_compare

Batch operation callback: Compare states and store the result.

In the preceding batch processes data of remote and local translation sources is collected. Here we compare the collected results and update the source object with the data of the most recent translation file. The end result is stored in the 'locale.translation_status' state variable. Other processes can collect this data after the batch process is completed.

Parameters

array $context: The batch context array. The 'results' element contains a structured array of project data with languages, local and remote source data.

See also

locale_translation_batch_status_fetch_remote()

locale_translation_batch_status_fetch_local()

2 string references to 'locale_translation_batch_status_compare'
_locale_translation_batch_status_operations in drupal/core/modules/locale/locale.compare.inc
Helper function to construct batch operations checking remote translation status.
_locale_translation_fetch_operations in drupal/core/modules/locale/locale.fetch.inc
Helper function to construct the batch operations to fetch translations.

File

drupal/core/modules/locale/locale.batch.inc, line 118
Batch process to check the availability of remote or local po files.

Code

function locale_translation_batch_status_compare(&$context) {
  $t = get_t();
  $history = locale_translation_get_file_history();
  $results = array();
  if (isset($context['results']['sources'])) {
    foreach ($context['results']['sources'] as $project => $langcodes) {
      foreach ($langcodes as $langcode => $source) {
        $local = isset($source->files[LOCALE_TRANSLATION_LOCAL]) ? $source->files[LOCALE_TRANSLATION_LOCAL] : NULL;
        $remote = isset($source->files[LOCALE_TRANSLATION_REMOTE]) ? $source->files[LOCALE_TRANSLATION_REMOTE] : NULL;

        // The available translation files are compared and data of the most
        // recent file is used to update the source object.
        $file = _locale_translation_source_compare($local, $remote) == LOCALE_TRANSLATION_SOURCE_COMPARE_LT ? $remote : $local;
        if (isset($file->timestamp)) {
          $source->type = $file->type;
          $source->timestamp = $file->timestamp;
        }

        // Compare the available translation with the current translations
        // status. If the project/language was translated before and it is more
        // recent than the most recent translation, the translation is up to
        // date. Which is marked in the source object with type "current".
        if (isset($history[$source->project][$source->langcode])) {
          $current = $history[$source->project][$source->langcode];

          // Add the current translation to the source object to save it in
          // the status cache.
          $source->files[LOCALE_TRANSLATION_CURRENT] = $current;
          if (isset($source->type)) {
            $available = $source->files[$source->type];
            $result = _locale_translation_source_compare($current, $available) == LOCALE_TRANSLATION_SOURCE_COMPARE_LT ? $available : $current;
            $source->type = $result->type;
            $source->timestamp = $result->timestamp;
          }
          else {
            $source->type = $current->type;
            $source->timestamp = $current->timestamp;
          }
        }
        $results[$project][$langcode] = $source;
      }
    }
    $context['message'] = $t('Updated translation status.');
  }
  locale_translation_status_save($results);
}