示例#1
0
 private function deleteTerms()
 {
     $result = db_query("SELECT tid FROM {term_data}");
     while ($tid = db_fetch_array($result)) {
         taxonomy_del_term($tid['tid']);
     }
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function termDelete(\stdClass $term)
 {
     $status = 0;
     if (isset($term->tid)) {
         $status = \taxonomy_del_term($term->tid);
     }
     // Will be SAVED_DELETED (3) on success.
     return $status;
 }
示例#3
0
文件: Term.php 项目: pounard/yamm
 /**
  * Find duplicates among terms with no UUID, based on name, and merge them all
  * with new one.
  *
  * Prerequisite is taxonomy have a tid (in case of term save, we have to save
  * it once before editing the $edit array and save it again.
  *
  * @param array $edit
  *   Edit array prepared for node save of the current term being saved
  */
 private function __mergeExisting($edit)
 {
     // We do this switch because of the non standard MySQL CAST() function types
     global $db_type;
     switch ($db_type) {
         case 'mysql':
         case 'mysqli':
             $result = db_query("SELECT t.tid FROM {term_data} t WHERE t.tid <> %d AND t.vid = %d AND t.name = '%s'" . " AND NOT EXISTS (SELECT 1 FROM {yamm_uuid} y WHERE CAST(y.identifier AS UNSIGNED INTEGER) = t.tid)", array($edit['tid'], $edit['vid'], $edit['name']));
             break;
         case 'pgsql':
             $result = db_query("SELECT t.tid FROM {term_data} t WHERE t.tid <> %d AND t.vid = %d AND t.name = '%s'" . " AND NOT EXISTS (SELECT 1 FROM {yamm_uuid} y WHERE CAST(y.identifier AS INTEGER) = t.tid)", array($edit['tid'], $edit['vid'], $edit['name']));
             break;
     }
     // Merge all found terms
     while ($data = db_fetch_object($result)) {
         $tid = $data->tid;
         // Merge relations
         $relations = taxonomy_get_related($tid);
         foreach ($relations as $related_id => &$related_term) {
             $edit['relations'][$related_id] = $related_id;
         }
         // Merge synonyms
         $synonyms = taxonomy_get_synonyms($tid);
         foreach ($synonyms as $name) {
             if (!in_array($name, $edit['synonyms'])) {
                 $edit['synonyms'][] = $name;
             }
         }
         // We also have to merge node dependencies
         $_result = db_query("SELECT nid,tid FROM {term_node} WHERE tid = %d", $tid);
         while ($_data = db_fetch_object($_result)) {
             $nid = $_data->nid;
             db_query("DELETE FROM {term_node} WHERE nid = %d AND tid IN (%d, %d)", array($nid, $tid, $edit['tid']));
             db_query("INSERT INTO {term_node} (nid, tid, vid) VALUES (%d, %d, %d)", array($nid, $edit['tid'], $edit['vid']));
         }
         // We do not want to merge parents, because we could have some
         // inconsistencies with synchronized taxonomy, but we should merge childs.
         db_query("UPDATE {term_hierarchy} SET parent = %d WHERE parent = %d", array($edit['tid'], $tid));
         // And finally
         taxonomy_del_term($tid);
     }
 }