<?php

/**
 * @file
 */

function stormperson_install() {
  drupal_install_schema('stormperson');
  variable_set('node_options_stormperson', array('status'));
}

function stormperson_disable() {
  drupal_set_message(t('Nodes of type "Person" have not been deleted on disabling SuiteDesk Person. Please note that they will now have reduced functionality, and will not be protected by SuiteDesk Person access controls.'), 'warning');
}

function stormperson_uninstall() {
  drupal_uninstall_schema('stormperson');
}

function stormperson_schema() {
  $schema['stormperson'] = array(
    'fields'                => array(
      'vid'                 => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
      'nid'                 => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
      'organization_nid'    => array('type' => 'int'),
      'organization_title'  => array('type' => 'varchar', 'length' => 150),
      'prefix'              => array('type' => 'varchar', 'length' => 100),
      'fullname'            => array('type' => 'varchar', 'length' => 100),
      'email'               => array('type' => 'varchar', 'length' => 50),
      'www'                 => array('type' => 'varchar', 'length' => 100),
      'phone'               => array('type' => 'varchar', 'length' => 100),
      'im'                  => array('type' => 'varchar', 'length' => 100),
      'user_uid'            => array('type' => 'int'),
    ),
    'primary key' => array('vid'),
    'indexes'     => array(
      'nid'              => array('nid'),
      'organization_nid' => array('organization_nid'),
      'user_uid'         => array('user_uid'),
    ),
  );

  return $schema;
}

/**
 * Improve primary keys and indexes
 */
function stormperson_update_6201() {
  $return = array();
  db_drop_primary_key($return, 'stormperson');
  db_add_primary_key($return, 'stormperson', array('vid'));
  db_add_index($return, 'stormperson', 'nid', array('nid'));
  db_add_index($return, 'stormperson', 'organization_nid', array('organization_nid'));
  db_add_index($return, 'stormperson', 'user_uid', array('user_uid'));
  return $return;
}
