You are here

function entity_translation_update_7008 in Entity Translation 7

Enable Entity Translation for taxonomy vocabularies having terms translated through it.

File

./entity_translation.install, line 465
Installation functions for Entity Translation module.

Code

function entity_translation_update_7008() {
  if (!module_exists('taxonomy')) {
    return;
  }

  // According to EXPLAIN joining {taxonomy_vocabulary} here makes the query
  // perform way worse, so we just split into two quick ones.
  $query = "SELECT t.vid\n    FROM {entity_translation} et\n    JOIN {taxonomy_term_data} t ON et.entity_type = 'taxonomy_term' AND et.entity_id = t.tid AND et.source != ''\n    GROUP BY t.vid";
  $vids = db_query($query)
    ->fetchCol();
  if ($vids) {
    $query = "SELECT v.machine_name FROM {taxonomy_vocabulary} v WHERE v.vid IN (:vids)";
    $names = db_query($query, array(
      ':vids' => $vids,
    ))
      ->fetchCol();
    $info = variable_get('entity_translation_taxonomy', array());
    foreach ($names as $name) {
      $info[$name] = TRUE;
    }
    variable_set('entity_translation_taxonomy', $info);
  }
}