You are here

function lingotek_update_7401 in Lingotek Translation 7.5

Same name and namespace in other branches
  1. 7.7 lingotek.install \lingotek_update_7401()
  2. 7.4 lingotek.install \lingotek_update_7401()
  3. 7.6 lingotek.install \lingotek_update_7401()

Adds the lingotek_translation_agent table and links it to the locales_target table

1 call to lingotek_update_7401()
lingotek_install in ./lingotek.install
Implements hook_install().

File

./lingotek.install, line 497

Code

function lingotek_update_7401(&$sandbox) {

  // add the translation_agent table
  $module = 'lingotek';
  $table = 'lingotek_translation_agent';
  if (!db_table_exists($table)) {
    $schema = drupal_get_schema_unprocessed($module, $table);
    db_create_table($table, $schema);
    $output = t('Table @table was created.', array(
      '@table' => $table,
    ));
  }
  else {
    $output = t('The @table table already exists. No action taken.', array(
      '@table' => $table,
    ));
  }

  // populate translation_agent table
  $agents = array(
    array(
      'id' => '1',
      'name' => 'unknown',
    ),
    array(
      'id' => '2',
      'name' => 'Drupal Translations',
    ),
    array(
      'id' => '3',
      'name' => 'Lingotek',
    ),
  );
  foreach ($agents as $a) {
    db_merge('lingotek_translation_agent')
      ->key(array(
      'id' => $a['id'],
    ))
      ->fields(array(
      'id' => $a['id'],
      'name' => $a['name'],
    ))
      ->execute();
  }
  $spec = array(
    'type' => 'int',
    'description' => "translation tool mapping",
    'length' => 10,
    'not null' => TRUE,
    'default' => '1',
  );
  try {
    db_add_field('locales_target', 'translation_agent_id', $spec);
  } catch (DatabaseSchemaObjectExistsException $e) {

    // already exists (no need to do anything)
  }
  drupal_static_reset('language_list');
  $output .= "\n" . t('Upgraded the locales target table to have the translation_agent_id field (if not already present).');
  return $output;
}