You are here

function lingotek_url_alias_source_language_cleanup_batch_worker in Lingotek Translation 7.6

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

Batch API worker for changing the url alias language setting

1 string reference to 'lingotek_url_alias_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 398
Central location for batch create functions, before control is handed off to individual batch command files.

Code

function lingotek_url_alias_source_language_cleanup_batch_worker($entity_type, $id, $source_language, &$context) {
  $conditions = array(
    'source' => $entity_type . '/' . $id,
  );
  $conditions['language'] = $source_language;
  $source_alias = path_load($conditions);
  if (!isset($context['results']['url_alias_cleanup'])) {
    $context['results']['url_alias_cleanup'] = array(
      'searched' => 0,
      'added' => 0,
    );
  }
  $context['results']['url_alias_cleanup']['searched']++;
  if ($source_alias === FALSE) {

    // if no url alias exists for this entity in the source language
    $conditions['language'] = LANGUAGE_NONE;
    $und_alias = path_load($conditions);
    if ($und_alias !== FALSE) {

      // if a url alias exists for language none (
      $context['message'] = t("Saving language-neutral path alias for @entity_type #@id to language '@sl'", array(
        '@entity_type' => $entity_type,
        '@nid' => $id,
        '@sl' => $source_language,
      ));
      $conditions['language'] = $source_language;
      $conditions['alias'] = $und_alias['alias'];
      path_save($conditions);
      $context['results']['url_alias_cleanup']['added']++;
    }
  }
}