<?php
/**
 * @file
 * Install and uninstall functions for the mailman integration module.
 */

/**
 * Implements hook_schema().
 */
function mailman_integration_schema() {
  $schema['mailman_integration_list'] = array(
    'description' => 'Mailman List',
    'fields' => array(
      'list_id' => array(
        'description' => 'Mailman List Id',
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'entity_id' => array(
        'description' => 'Entity Id',
        'type' => 'int',
        'not null' => FALSE,
        'default'  => NULL,
      ),
      'entity_type' => array(
        'description' => 'Entity Type',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
        'default'  => NULL,
      ),
      'bundle' => array(
        'description' => 'Entity Bundle',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
        'default'  => NULL,
      ),
      'list_name' => array(
        'description' => 'Mailman List Name',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'default'  => NULL,
      ),
      'list_owners' => array(
        'description' => 'Mailman List Owners',
        'type' => 'text',
        'not null' => FALSE,
      ),
      'visible_to_user' => array(
        'description' => 'User can subscribe.',
        'type' => 'int',
        'not null' => TRUE,
        'default'  => 0,
      ),
      'description' => array(
        'description' => 'Mailman List Description',
        'type' => 'text',
        'not null' => FALSE,
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the List Creadted',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'changed' => array(
        'description' => 'The Unix timestamp when the List Updated',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('list_id'),
  );
  $schema['mailman_list_users'] = array(
    'description' => 'Mailman List Users',
    'fields' => array(
      'id' => array(
        'description' => 'Field Id',
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'uid' => array(
        'description' => 'Drupal User Id',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'list_id' => array(
        'description' => 'Mailman List ID',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'mail' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Subscriber email',
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the User Subscribed',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'created_by' => array(
        'description' => 'Subscriber User Id. Admin Can subscribe for User.',
        'type' => 'int',
        'not null' => FALSE,
        'default' => 0,
      ),
    ),
    'primary key' => array('id'),
  );
  $schema['mailman_list_roles'] = array(
    'description' => 'Mailman List Roles',
    'fields' => array(
      'id' => array(
        'description' => 'Mailman List Id',
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'list_id' => array(
        'description' => 'Mailman List Id',
        'type' => 'int',
        'not null' => FALSE,
        'default' => 0,
      ),
      'role_id' => array(
        'description' => 'Role Id',
        'type' => 'int',
        'not null' => FALSE,
        'default'  => NULL,
      ),
      'list_name' => array(
        'description' => 'Mailman List Name',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'default'  => NULL,
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the List Creadted',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'changed' => array(
        'description' => 'The Unix timestamp when the List Updated',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('id'),
  );
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function mailman_integration_uninstall() {
  variable_del('mailman_integration_admin_url');
  variable_del('mailman_integration_domain_name');
  variable_del('mailman_integration_authenticate_password');
  variable_del('mailman_integration_sub_acknowledgement_to_user');
  variable_del('mailman_integration_sub_acknowledgement_to_owner');
  variable_del('mailman_integration_unsub_acknowledgement_to_user');
  variable_del('mailman_integration_unsub_acknowledgement_to_owner');
  variable_del('mailman_integration_list_pagination');
  variable_del('mailman_connection_error');
  variable_del('mailman_integration_auto_sync');
}
