<?php
// $Id: ldapgroups.install,v 1.6 2009/07/04 21:54:28 miglius Exp $

/**
 * @file
 * ldapgroups module installation and upgrade code.
 */

//////////////////////////////////////////////////////////////////////////////
// Core API hooks

/**
 * Implementation of hook_install().
 */
function ldapgroups_install() {
  // We're adding to an existing table, not creating a new one.
  $ret = array();

  db_add_field($ret, 'ldapauth', 'ldapgroups_in_dn', array(
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => '0',
  ));
  db_add_field($ret, 'ldapauth', 'ldapgroups_dn_attribute', array(
    'type' => 'varchar',
    'length' => 255,
  ));
  db_add_field($ret, 'ldapauth', 'ldapgroups_attr', array(
    'type' => 'varchar',
    'length' => 255,
  ));
  db_add_field($ret, 'ldapauth', 'ldapgroups_in_attr', array(
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => '0',
  ));
  db_add_field($ret, 'ldapauth', 'ldapgroups_as_entries', array(
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => '0',
  ));
  db_add_field($ret, 'ldapauth', 'ldapgroups_entries', array(
    'type' => 'text',
  ));
  db_add_field($ret, 'ldapauth', 'ldapgroups_entries_attribute',  array(
    'type' => 'varchar',
    'length' => 255,
  ));
  db_add_field($ret, 'ldapauth', 'ldapgroups_mappings',  array(
    'type' => 'text',
    'not null' => FALSE,
  ));
  db_add_field($ret, 'ldapauth', 'ldapgroups_mappings_filter', array(
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => '0',
  ));
  db_add_field($ret, 'ldapauth', 'ldapgroups_filter_php',  array(
    'type' => 'text',
    'not null' => FALSE,
  ));
  db_add_field($ret, 'ldapauth', 'ldapgroups_groups',  array(
    'type' => 'text',
    'not null' => FALSE,
  ));

  return $ret;
}

/**
 * Implementation of hook_uninstall().
 */
function ldapgroups_uninstall() {
  // We're removing fileds from an existing table, not deleting a whole one.
  $ret = array();

  db_drop_field($ret, 'ldapauth', 'ldapgroups_in_dn');
  db_drop_field($ret, 'ldapauth', 'ldapgroups_dn_attribute');
  db_drop_field($ret, 'ldapauth', 'ldapgroups_attr');
  db_drop_field($ret, 'ldapauth', 'ldapgroups_in_attr');
  db_drop_field($ret, 'ldapauth', 'ldapgroups_as_entries');
  db_drop_field($ret, 'ldapauth', 'ldapgroups_entries');
  db_drop_field($ret, 'ldapauth', 'ldapgroups_entries_attribute');
  db_drop_field($ret, 'ldapauth', 'ldapgroups_mappings');
  db_drop_field($ret, 'ldapauth', 'ldapgroups_mappings_filter');
  db_drop_field($ret, 'ldapauth', 'ldapgroups_filter_php');
  db_drop_field($ret, 'ldapauth', 'ldapgroups_groups');

  return $ret;
}

function ldapgroups_update_6001() {
  $ret = array();
  db_add_field($ret, 'ldapauth', 'ldapgroups_mappings',  array(
    'type' => 'text',
    'not null' => FALSE,
  ));
  db_add_field($ret, 'ldapauth', 'ldapgroups_mappings_filter', array(
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => '0',
  ));
  db_add_field($ret, 'ldapauth', 'ldapgroups_filter_php',  array(
    'type' => 'text',
    'not null' => FALSE,
  ));
  db_add_field($ret, 'ldapauth', 'ldapgroups_groups',  array(
    'type' => 'text',
    'not null' => FALSE,
  ));
  return $ret;
}

