<?php

/**
 * @file
 * Content access install file.
 */

/**
 * Implements hook_uninstall().
 */
function content_access_uninstall() {
  foreach (node_type_get_types() as $type_name => $type) {
    variable_del('content_access_' . $type_name);
  }
}

/**
 * Implements hook_schema().
 */
function content_access_schema() {
  $schema['content_access'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0
      ),
      'settings' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'medium'
      ),
    ),
    'primary key' => array('nid')
  );
  return $schema;
}

/**
 * Convert content type settings to a new features-friendly storage format.
 */
function content_access_update_7101() {
  $settings = variable_get('content_access_settings', array());
  foreach ($settings as $setting => $data) {
    foreach ($data as $type_name => $value) {
      $settings_new[$type_name][$setting] = $value;
    }
  }
  foreach ($settings_new as $type_name => $data) {
    variable_set('content_access_' . $type_name, $data);
  }
  variable_del('content_access_settings');
}
