You are here

function lingotek_batch_identify_content in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.2 lingotek.batch.inc \lingotek_batch_identify_content()
  2. 7.3 lingotek.batch.inc \lingotek_batch_identify_content()

Batch Create: Lingotek Identify Content - create informative lingonode data (in lingotek table) for pre-existing content

1 call to lingotek_batch_identify_content()
lingotek_cleanup_utility in ./lingotek.util.inc
Clean-up utility
1 string reference to 'lingotek_batch_identify_content'
lingotek_menu in ./lingotek.module
Implements hook_menu().

File

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

Code

function lingotek_batch_identify_content($front = FALSE) {
  LingotekLog::trace(__METHOD__);
  $result = db_query('SELECT DISTINCT nid FROM {lingotek}');
  $existing_nids = $result
    ->fetchCol();
  $operations = array();
  global $language;
  $existing_languages = language_list();
  unset($existing_languages[$language->language]);
  foreach (lingotek_get_content_types() as $type) {
    $nodes = node_load_multiple(array(), array(
      'type' => $type,
    ));
    $nodes_in_language_field = array();
    $nodes_in_language_node = array();
    foreach ($existing_languages as $lang) {
      $nodes_in_language_field[$lang->language] = lingotek_list_entities_with_language('node', $type, $lang->language);
      $nodes_in_language_node[$lang->language] = lingotek_list_nodes_translated_in_language($type, $lang->language);
    }
    foreach ($nodes as $node) {
      if (!in_array($node->nid, $existing_nids)) {
        if ($node->tnid == 0 || $node->tnid == $node->nid) {

          //skip node translation target nodes

          // Add content nodes to lingotek table, to indicate that they are machine translatable nodes
          $operations[] = array(
            'LingotekSync::setNodeStatus',
            array(
              $node->nid,
              LingotekSync::STATUS_EDITED,
            ),
          );
          foreach ($existing_languages as $lang) {
            if (in_array($node->nid, $nodes_in_language_field[$lang->language]) || in_array($node->nid, $nodes_in_language_node[$lang->language])) {
              $lingotek_locale = Lingotek::convertDrupal2Lingotek($lang->language);
              lingotek_lingonode($node->nid, 'target_sync_status_' . $lingotek_locale, LingotekSync::STATUS_CURRENT);
            }
          }
        }
      }
    }
  }
  $batch = array(
    'title' => t('Identifying Translatable Content'),
    'operations' => $operations,
  );
  batch_set($batch);
  if ($front) {
    batch_process('<front>');

    // Needed if not inside a form _submit handler.  Setting redirect in batch_process.
  }
}