You are here

function taxonomy_csv_term_find_duplicate in Taxonomy CSV import/export 7.5

Same name and namespace in other branches
  1. 6.5 taxonomy_csv.term.api.inc \taxonomy_csv_term_find_duplicate()
  2. 6.2 taxonomy_csv.term.api.inc \taxonomy_csv_term_find_duplicate()
  3. 6.3 taxonomy_csv.term.api.inc \taxonomy_csv_term_find_duplicate()
  4. 6.4 taxonomy_csv.term.api.inc \taxonomy_csv_term_find_duplicate()
  5. 7.4 taxonomy_csv.term.api.inc \taxonomy_csv_term_find_duplicate()

Find duplicate terms in a vocabulary or in all vocabularies.

@todo Use taxonomy_term_load_multiple or regular Drupal 7 query.

Parameters

$vid: (Optional) Vocabulary to check in.

Return value

An array of term names, indexed by tid.

1 call to taxonomy_csv_term_find_duplicate()
_taxonomy_csv_export_result in export/taxonomy_csv.export.result.inc
Display result messages of export process.

File

./taxonomy_csv.term.api.inc, line 99
Find, get and set full or detail term items.

Code

function taxonomy_csv_term_find_duplicate($vid = 0) {
  $terms = array();
  $sql = '
    SELECT t1.tid, t1.name
    FROM {taxonomy_term_data} t1
    LEFT OUTER JOIN {taxonomy_term_data} t2 ON t1.tid != t2.tid AND LOWER(t1.name) = LOWER(t2.name)
    WHERE t2.tid IS NOT NULL
  ';
  $args = array();
  if ($vid) {
    $sql .= ' AND t1.vid = :vid AND t2.vid = :vid ';
    $args[':vid'] = $vid;
  }
  $sql .= ' ORDER BY t1.tid ASC ';
  $result = db_query($sql, $args)
    ->fetchAllKeyed();
  return $result;
}