You are here

function lingotek_cleanup_notify_entity_translation in Lingotek Translation 7.7

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

Report all Lingotek translations to the Entity Translation module

File

./lingotek.util.inc, line 1668
Utility functions.

Code

function lingotek_cleanup_notify_entity_translation() {
  $entity_list = array();
  $results = db_select('lingotek_entity_metadata', 'l')
    ->fields('l', array(
    'entity_id',
    'entity_type',
    'entity_key',
    'created',
    'modified',
  ))
    ->condition('entity_key', 'target_sync_status_%', 'LIKE')
    ->condition('value', LingotekSync::STATUS_CURRENT)
    ->execute();
  $total_updates = 0;
  foreach ($results as $r) {
    $locale = str_replace('target_sync_status_', '', $r->entity_key);
    $entity = lingotek_entity_load_single($r->entity_type, $r->entity_id);
    if ($entity) {
      $info = entity_get_info($r->entity_type);
      $bundle_name = !empty($info['entity keys']['bundle']) ? $info['entity keys']['bundle'] : NULL;
      if ($bundle_name && lingotek_managed_by_entity_translation($entity->{$bundle_name})) {
        $addtl_params = array(
          'created' => $r->created,
          'changed' => $r->modified,
        );
        list($languages_updated, $updates) = lingotek_entity_translation_save_status($r->entity_type, $entity, array(
          Lingotek::convertLingotek2Drupal($locale),
        ), $addtl_params);
        $total_updates += $updates;
      }
    }
  }
  if ($total_updates > 0) {
    $translation_str = format_plural($total_updates, t('translation was'), t('translations were'));
    drupal_set_message(t('@num_updates @translations reported to the Entity Translation module.', array(
      '@num_updates' => $total_updates,
      '@translations' => $translation_str,
    )));
  }
  else {
    drupal_set_message(t('The Entity Translation module was already aware of all current translations.'));
  }
}