You are here

function field_permissions_uninstall in Field Permissions 6

Same name and namespace in other branches
  1. 7 field_permissions.install \field_permissions_uninstall()

Implementation of hook_uninstall().

File

./field_permissions.install, line 46
Installation hooks for Field Permissions module.

Code

function field_permissions_uninstall() {
  $t = get_t();
  drupal_load('module', 'content');

  // Remove field permission settings from fields.
  $messages = array();
  $result = db_query('SELECT field_name, global_settings FROM {' . content_field_tablename() . '}');
  while ($field = db_fetch_object($result)) {
    $global_settings = unserialize($field->global_settings);
    if (isset($global_settings['field_permissions'])) {
      unset($global_settings['field_permissions']);
      $global_settings = serialize($global_settings);

      // We cannot use update_sql() here because of curly braces in serialized array.
      db_query("UPDATE {" . content_field_tablename() . "} SET global_settings = '%s' WHERE field_name = '%s'", $global_settings, $field->field_name);
      $messages[] = $t('Field permission settings have been removed from field %field-name.', array(
        '%field-name' => $field->field_name,
      ));
    }
  }
  drupal_set_message($t('Field Permissions module has been uninstalled successfully.'));
  if (!empty($messages)) {
    content_clear_type_cache();
    drupal_set_message(implode('<br />', $messages));
  }
}