دروپال: یکی کردن واژگان یکسان (Taxonomy terms)

$result = db_query("SELECT a1.tid as tid1, a2.tid as tid2 FROM `taxonomy_term_data` a1 JOIN taxonomy_term_data a2 ON a1.name = a2.name WHERE a1.vid = a2.vid AND a1.tid < a2.tid GROUP BY a1.name LIMIT 1;");
  $tids = $result->fetch();
  if (!$tids) {
    return;
  }
  db_update('field_data_field_tags')
          ->fields(array('field_tags_tid' => $tids->tid1))
          ->condition('field_tags_tid', $tids->tid2)
          ->execute();
  db_update('field_revision_field_tags')
          ->fields(array('field_tags_tid' => $tids->tid1))
          ->condition('field_tags_tid', $tids->tid2)
          ->execute();
  db_update('field_data_field_categories')
          ->fields(array('field_categories_tid' => $tids->tid1))
          ->condition('field_categories_tid', $tids->tid2)
          ->execute();
  db_update('field_revision_field_categories')
          ->fields(array('field_categories_tid' => $tids->tid1))
          ->condition('field_categories_tid', $tids->tid2)
          ->execute();
  db_update('taxonomy_index')
          ->fields(array('tid' => $tids->tid1))
          ->condition('tid', $tids->tid2)
          ->execute();
  taxonomy_term_delete($tids->tid2);
برچسب ها: 

افزودن نظر جدید