You are here

function content_taxonomy_taxonomy in Content Taxonomy 6

Same name and namespace in other branches
  1. 6.2 content_taxonomy.module \content_taxonomy_taxonomy()

Implementation of hook_taxonomy().

File

./content_taxonomy.module, line 377
Defines a field type for referencing a taxonomy term.

Code

function content_taxonomy_taxonomy($op, $type, $array = NULL) {

  //keep the database consistent when either a voc or a term is deleted

  //in case of voc: delete all associated fields and its data

  //in case of term: delete all its entries
  if ($op == 'delete') {
    $vid = $array['vid'];
    $needs_refresh = FALSE;
    foreach (content_taxonomy_fields() as $type_name => $ct_type) {
      foreach ($ct_type['fields'] as $field_name => $field) {
        if ($field['vid'] == $vid) {
          if ($type == 'vocabulary') {
            module_load_include('inc', 'content', 'includes/content.crud');
            content_field_instance_delete($field_name, $field['type_name']);
            $needs_refresh = TRUE;
            watchdog('content', 'Deleted field %field_name and its data.', array(
              '%field_name' => $field_name,
            ));
          }
          else {
            $tid = $array['tid'];
            if ($tid) {
              $db_info = content_database_info($field);
              if ($field['multiple']) {
                db_query('DELETE FROM {' . $db_info['table'] . '} WHERE ' . $db_info['columns']['value']['column'] . ' = %d', $tid);
              }
              else {
                db_query('UPDATE {' . $db_info['table'] . '} SET ' . $db_info['columns']['value']['column'] . '= NULL  WHERE ' . $db_info['columns']['value']['column'] . ' = %d', $tid);
              }
              $needs_refresh = TRUE;
              watchdog('content', 'Entries with term id = %tid have been deleted out of %table for field %field_name.', array(
                '%tid' => $tid,
                '%table' => $db_info['table'],
                '%field_name' => $field_name,
              ));
            }
          }
        }
      }
    }
    if ($needs_refresh) {
      content_clear_type_cache(TRUE);
    }
  }
}