library.install in Library 7
Same filename and directory in other branches
@author Jess Straatmann Install and uninstall all required databases.
Also do incremental database updates.
File
library.installView source
<?php
/**
* @file
* @author Jess Straatmann
* Install and uninstall all required databases.
*
* Also do incremental database updates.
*/
/**
* Implements hook_schema().
*/
function library_schema() {
$schema['library'] = array(
'description' => 'Determines if a library item may be checked out.',
'fields' => array(
'id' => array(
'description' => 'The primary identifier for a library item.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'barcode' => array(
'description' => 'The barcode/identifier for this item.',
'type' => 'varchar',
'length' => 60,
'not null' => FALSE,
'default' => '',
),
'nid' => array(
'description' => 'The node identifier.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'in_circulation' => array(
'description' => 'Boolean indicating whether the item is in circulation.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'library_status' => array(
'description' => 'Boolean indicating whether the item is available. Not directly editable.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'notes' => array(
'description' => 'Short description field for additional comments about the item.',
'type' => 'varchar',
'length' => 256,
'not null' => FALSE,
'default' => '',
),
'created' => array(
'type' => 'int',
'description' => 'Timestamp for when the item was created.',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'nid' => array(
'nid',
),
),
'primary key' => array(
'id',
),
);
$schema['library_transactions'] = array(
'description' => 'The table where library transactions are stored.',
'fields' => array(
'tid' => array(
'description' => 'The primary identifier for a transaction.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'item_id' => array(
'description' => 'The associated library item.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
'description' => 'The associated library node.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'description' => 'The associated patron user.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'action_aid' => array(
'description' => 'The action performed.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'duedate' => array(
'type' => 'int',
'description' => 'Timestamp for the current duedate.',
'not null' => FALSE,
'default' => NULL,
),
'notes' => array(
'description' => 'Short description field for additional comments about the transaction.',
'type' => 'varchar',
'length' => 256,
'not null' => FALSE,
'default' => NULL,
),
'created' => array(
'type' => 'int',
'description' => 'Timestamp for when transaction occurred.',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'item_id' => array(
'item_id',
),
'uid' => array(
'uid',
),
'action_aid' => array(
'action_aid',
),
),
'primary key' => array(
'tid',
),
);
$schema['library_actions'] = array(
'description' => 'The table where library transactions are stored.',
'fields' => array(
'aid' => array(
'description' => 'The unique identifier of this action.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'name' => array(
'description' => 'The name of this action.',
'type' => 'varchar',
'length' => 60,
'not null' => TRUE,
'default' => '',
),
'status_change' => array(
'description' => 'Indicates if the action changes item status.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'aid',
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function library_install() {
$t = get_t();
$fields = array(
'name' => 'Check Out',
'status_change' => 1,
);
try {
$return_value = db_insert('library_actions')
->fields($fields)
->execute();
} catch (Exception $e) {
drupal_set_message($t('db_insert failed. Message = %message, query= %query', array(
'%message' => $e
->getMessage(),
'%query' => $e->query_string,
)), 'error');
}
$fields = array(
'name' => 'Check In',
'status_change' => 2,
);
try {
$return_value = db_insert('library_actions')
->fields($fields)
->execute();
} catch (Exception $e) {
drupal_set_message($t('db_insert failed. Message = %message, query= %query', array(
'%message' => $e
->getMessage(),
'%query' => $e->query_string,
)), 'error');
}
// Notify user of changes.
// @ignore rule:sniffer_files_linelength_toolong
drupal_set_message($t('Library module successfully installed. You can configure library settings at admin/config/workflow/library. To start creating library items, edit one or more content types to be included in the library.'));
}
/**
* Implements hook_uninstall().
*/
function library_uninstall() {
foreach (node_type_get_types() as $type => $info) {
variable_del('library_' . $type . '_due_dates');
variable_del('library_' . $type);
module_load_include('module', 'library', 'library');
foreach (library_actions() as $key => $value) {
variable_del('library_days_for_' . $type . '_' . library_clean_action_name($value['name']));
variable_del('library_hours_for_' . $type . '_' . library_clean_action_name($value['name']));
variable_del('library_period_for_' . $type . '_' . library_clean_action_name($value['name']));
}
}
variable_del('library_links_display_available');
variable_del('library_links_display_unavailable');
variable_del('library_links_display_reference');
variable_del('library_item_barcodes');
variable_del('library_unique_titles');
variable_del('library_cron');
variable_del('library_list_status_display');
variable_del('library_status_display');
variable_del('library_quantity_display');
variable_del('library_taxonomy_display');
variable_del('library_available_text');
variable_del('library_reference_only_text');
variable_del('library_unavailable_noduedates_text');
variable_del('library_send_automatic_email');
variable_del('library_mail_notify_overdue_subject');
variable_del('library_mail_notify_overdue_body');
// Clear the cache tables.
cache_clear_all();
drupal_set_message(st('Library module successfully uninstalled'));
}
Functions
Name | Description |
---|---|
library_install | Implements hook_install(). |
library_schema | Implements hook_schema(). |
library_uninstall | Implements hook_uninstall(). |