I just deleted a node reference field on which I had previously specified some nodeaccess_nodereference settings. When I did that and then tried to view the content where the field was, was getting heaps of errors about the underlying now-deleted field's table being not there. I had to go into the variable in the variables table and clean up the now no-longer valid bits of data. I'm thinking this should be done automatically when a node reference field is deleted, no? Looks like you need a hook nodeaccess_nodereference_content_fieldapi($op, $field) to do the cleanup when $op is 'delete instance'. Probably just something like...

function nodeaccess_nodereference_content_fieldapi($op, $field) {
  if ( $op == 'delete instance' ) {
    $data = variable_get('nodeaccess_nodereference', array());
    if ( isset($data[$field['type_name']][$field['field_name']]) ) {
      unset($data[$field['type_name']][$field['field_name']]);
      variable_set('nodeaccess_nodereference', $data);
    }
  }
}

Shawn

Comments

danielb’s picture

Good point I'll get onto that in a few weeks. Don't have internet/phone atm.

danielb’s picture

Status: Fixed » Active

I'm assuming in Drupal 7 it will be something like this

<?php

/**
 * Implements hook_field_delete_instance().
 */
function nodeaccess_nodereference_field_delete_instance($instance) {
  $data = variable_get('nodeaccess_nodereference', array());
  if (isset($data[$instance['bundle']][$instance['field_name']])) {
    unset($data[$instance['bundle']][$instance['field_name']]);
    variable_set('nodeaccess_nodereference', $data);
  }
}

?>
danielb’s picture

Status: Active » Fixed
danielb’s picture

Just to further whittle away that array I'm going to add this

<?php
    if (empty($data[$instance['bundle']])) {
      unset($data[$instance['bundle']]);
    }
?>
danielb’s picture

Status: Active » Fixed
danielb’s picture

Status: Fixed » Needs work

I reckon we need an update or something to clear out the old ones as well.

danielb’s picture

The drupal 6 update code would be:

<?php

  $info = _content_type_info();
  $settings = variable_get('nodeaccess_nodereference', array());
  foreach ($settings as $type => $fields) {
    foreach ($fields as $field => $data) {
       if (!isset($info['content types'][$type]['fields'][$field])) {
          unset($settings[$type][$field]);
       }
    }
    if (empty($settings[$type])) {
      unset($settings[$type]);
    }
  }
  variable_set('nodeaccess_nodereference', $settings);

?>
danielb’s picture

Status: Needs work » Fixed
aCCa’s picture

Thanks update code worked for me (D6).

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.