You are here

function lingotek_source_language_cleanup_batch_worker in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.5 lingotek.batch.inc \lingotek_source_language_cleanup_batch_worker()
  2. 7.6 lingotek.batch.inc \lingotek_source_language_cleanup_batch_worker()

Batch API worker for changing the entity's language setting.

1 string reference to 'lingotek_source_language_cleanup_batch_worker'
lingotek_field_language_data_cleanup_batch_create in ./lingotek.batch.inc
Field Language Data Cleanup Utility

File

./lingotek.batch.inc, line 517
Central location for batch create functions, before control is handed off to individual batch command files.

Code

function lingotek_source_language_cleanup_batch_worker($entity_type, $entity_id, $source_language, &$context) {
  $context['message'] = t("Setting language for @entity_type #@id to '@source_language'", array(
    '@entity_type' => $entity_type,
    '@id' => $entity_id,
    '@source_language' => $source_language,
  ));
  $loaded_entity = lingotek_entity_load_single($entity_type, $entity_id);
  $info = entity_get_info($entity_type);

  // Default to string 'language' if no language-related entity key is found.
  $language_field = !empty($info['entity keys']['language']) ? $info['entity keys']['language'] : 'language';
  if (isset($loaded_entity->{$language_field}) && $loaded_entity->{$language_field} != $source_language) {
    $loaded_entity->{$language_field} = $source_language;
    $loaded_entity->lingotek_upload_override = FALSE;

    // Set 0 : Prevent upload. Set 1 : Force upload.
    entity_save($entity_type, $loaded_entity);
    if (!isset($context['results']['entity_cleanup'])) {
      $context['results']['entity_cleanup'] = 0;
    }
    $context['results']['entity_cleanup']++;
  }
}