You are here

function l10n_update_status_save in Localization update 7.2

Saves the status of translation sources in static cache.

Parameters

string $project: Machine readable project name.

string $langcode: Language code.

string $type: Type of data to be stored.

object $data: File object also containing timestamp when the translation is last updated.

4 calls to l10n_update_status_save()
l10n_update_batch_fetch_download in ./l10n_update.batch.inc
Batch operation: Download a remote translation file.
l10n_update_batch_fetch_import in ./l10n_update.batch.inc
Batch process: Import translation file.
l10n_update_batch_status_check in ./l10n_update.batch.inc
Batch operation callback: Check status of a remote and local po file.
l10n_update_check_projects_local in ./l10n_update.compare.inc
Check and store the status and timestamp of local po files.

File

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

Code

function l10n_update_status_save($project, $langcode, $type, $data) {

  // Followup issue: https://www.drupal.org/node/1842362
  // Split status storage per module/language and expire individually. This will
  // improve performance for large sites.
  // Load the translation status or build it if not already available.
  module_load_include('translation.inc', 'l10n_update');
  $status = l10n_update_get_status();
  if (empty($status)) {
    $projects = l10n_update_get_projects(array(
      $project,
    ));
    if (isset($projects[$project])) {
      $status[$project][$langcode] = l10n_update_source_build($projects[$project], $langcode);
    }
  }

  // Merge the new status data with the existing status.
  if (isset($status[$project][$langcode])) {
    switch ($type) {
      case L10N_UPDATE_REMOTE:
      case L10N_UPDATE_LOCAL:

        // Add the source data to the status array.
        $status[$project][$langcode]->files[$type] = $data;

        // Check if this translation is the most recent one. Set timestamp and
        // data type of the most recent translation source.
        if (isset($data->timestamp) && $data->timestamp) {
          $version_changed = isset($status[$project][$langcode]->files[L10N_UPDATE_CURRENT]->version) && $status[$project][$langcode]->files[L10N_UPDATE_CURRENT]->version != $data->version;
          if ($data->timestamp > $status[$project][$langcode]->timestamp || $version_changed) {
            $status[$project][$langcode]->timestamp = $data->timestamp;
            $status[$project][$langcode]->last_checked = REQUEST_TIME;
            $status[$project][$langcode]->version = $data->version;
            $status[$project][$langcode]->type = $type;
          }
        }
        break;
      case L10N_UPDATE_CURRENT:
        $data->last_checked = REQUEST_TIME;
        $status[$project][$langcode]->timestamp = $data->timestamp;
        $status[$project][$langcode]->last_checked = $data->last_checked;
        $status[$project][$langcode]->version = $data->version;
        $status[$project][$langcode]->type = $type;
        $status[$project][$langcode]->files[$type] = $data;
        l10n_update_update_file_history($data);
        break;
    }
    cache_set('l10n_update_status', $status);
    variable_set('l10n_update_last_check', REQUEST_TIME);
  }
}