You are here

function lingotek_field_language_data_cleanup_batch_create in Lingotek Translation 7.3

Same name and namespace in other branches
  1. 7.7 lingotek.batch.inc \lingotek_field_language_data_cleanup_batch_create()
  2. 7.2 lingotek.batch.inc \lingotek_field_language_data_cleanup_batch_create()
  3. 7.4 lingotek.batch.inc \lingotek_field_language_data_cleanup_batch_create()
  4. 7.5 lingotek.batch.inc \lingotek_field_language_data_cleanup_batch_create()
  5. 7.6 lingotek.batch.inc \lingotek_field_language_data_cleanup_batch_create()

Field Language Data Cleanup Utility

Creates a batch to cleanup nodes with data in an 'und' language field.

Parameters

bool $front: If this batch was NOT created from a form_submit() handler, then pass in TRUE

1 call to lingotek_field_language_data_cleanup_batch_create()
lingotek_cleanup_utility in ./lingotek.util.inc
Clean-up utility

File

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

Code

function lingotek_field_language_data_cleanup_batch_create($front = FALSE) {
  LingotekLog::trace(__METHOD__);
  $operations = array();
  $entity_type = 'node';
  $source_language = lingotek_get_source_language();
  $translated_types = lingotek_translatable_node_types();

  // Get the list of content types that we translate.
  // Fix node level language settings
  // This selects all the nodes that are language undefined and are content types we need to translate.  We need to change these nodes from language undefined to the source language.
  $query1 = new EntityFieldQuery();
  $nodes1 = $query1
    ->entityCondition('entity_type', $entity_type)
    ->entityCondition('bundle', $translated_types)
    ->propertyCondition('language', 'und', '=')
    ->execute();
  if (isset($nodes1[$entity_type])) {
    foreach ($nodes1[$entity_type] as $node1) {
      $operations[] = array(
        'lingotek_node_source_language_cleanup_batch_worker',
        array(
          $node1->nid,
          $source_language,
        ),
      );
      $operations[] = array(
        'lingotek_node_url_alias_source_language_cleanup_batch_worker',
        array(
          $node1->nid,
          $source_language,
        ),
      );
      $operations[] = array(
        'lingotek_field_language_data_cleanup_batch_worker',
        array(
          $node1->nid,
        ),
      );
    }
  }

  // Fix field languages
  // This selects all nodes that have a language defined.  It does NOT select the UND language nodes.
  $query2 = new EntityFieldQuery();
  $nodes2 = $query2
    ->entityCondition('entity_type', $entity_type)
    ->propertyCondition('language', 'und', '<>')
    ->execute();
  if (isset($nodes2[$entity_type])) {
    foreach ($nodes2[$entity_type] as $node2) {
      $operations[] = array(
        'lingotek_node_url_alias_source_language_cleanup_batch_worker',
        array(
          $node2->nid,
          $source_language,
        ),
      );
      $operations[] = array(
        'lingotek_field_language_data_cleanup_batch_worker',
        array(
          $node2->nid,
        ),
      );
    }
  }
  if (count($operations) > 0) {
    $batch = array(
      'title' => t('Lingotek Field Language Updater'),
      'operations' => $operations,
      'finished' => 'lingotek_field_language_data_cleanup_batch_finished',
      'file' => 'lingotek.batch.inc',
    );
    batch_set($batch);
    if ($front) {

      // If this batch was NOT created from a form_submit() handler, do this to initiate the batch.
      batch_process('<front>');

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

  // END:  if operations
}