You are here

patron.install in Library 6

Same filename and directory in other branches
  1. 5.2 patron/patron.install
  2. 6.2 patron/patron.install

@author Jess Straatmann patron.install Install and uninstall all required databases. Also do incremental database updates.

File

patron/patron.install
View source
<?php

/**
 * @author Jess Straatmann
 * @file patron.install
 * Install and uninstall all required databases.
 * Also do incremental database updates.
 */
function patron_schema() {
  $schema['library_patrons'] = array(
    'description' => t('The table where patron information is stored.'),
    'fields' => array(
      'nid' => array(
        'description' => t('The primary identifier for a node.'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'name_last' => array(
        'description' => t('The patron last name.'),
        'type' => 'varchar',
        'length' => 60,
        'not null' => TRUE,
        'default' => '',
      ),
      'name_first' => array(
        'description' => t('The patron first name.'),
        'type' => 'varchar',
        'length' => 60,
        'not null' => TRUE,
        'default' => '',
      ),
      'email' => array(
        'description' => t('The patron email.'),
        'type' => 'varchar',
        'length' => 60,
        'not null' => TRUE,
        'default' => '',
      ),
      'patron_uid' => array(
        'description' => t('Drupal user id of the user corresponding to this patron.'),
        'type' => 'int',
        'not null' => FALSE,
        'unsigned' => TRUE,
        'default' => NULL,
      ),
      'barcode' => array(
        'description' => t('Card number for this patron.'),
        'type' => 'varchar',
        'length' => 60,
        'not null' => FALSE,
        'default' => '',
      ),
      'disabled' => array(
        'description' => t('Boolean indicating whether the patron account is disabled.'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(),
    'unique keys' => array(
      'email' => array(
        'email',
      ),
      'patron_uid' => array(
        'patron_uid',
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install()
 */
function patron_install() {
  drupal_install_schema('patron');

  // Notify of changes
  drupal_set_message(t("Library patron module successfully installed."));
}

/**
 * Implementation of hook_uninstall().
 */
function patron_uninstall() {
  variable_del('patron_is_user');
  variable_del('patron_use_barcodes');
  variable_del('patron_autocreate');
  $result = db_query("SELECT nid FROM {node} WHERE type = 'patron'");
  if ($result) {
    while ($row = db_fetch_object($result)) {
      set_time_limit(5);
      node_delete($row->nid);
    }
  }
  drupal_uninstall_schema('patron');

  // Clear the cache tables.
  cache_clear_all(null, 'cache');
  cache_clear_all(null, 'cache_filter');
  cache_clear_all(null, 'cache_menu');
  cache_clear_all(null, 'cache_page');
  drupal_set_message(t('Library patron module successfully uninstalled'));
}
function patron_update_1() {
  $ret = array();
  $ret[] = update_sql("UPDATE {library_patrons} SET patron_uid = NULL WHERE patron_uid = 0");
  return $ret;
}

Functions

Namesort descending Description
patron_install Implementation of hook_install()
patron_schema @author Jess Straatmann @file patron.install Install and uninstall all required databases. Also do incremental database updates.
patron_uninstall Implementation of hook_uninstall().
patron_update_1