| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @author Jess Straatmann
|
| 6 |
* @file library.install
|
| 7 |
* Install and uninstall all required databases.
|
| 8 |
* Also do incremental database updates.
|
| 9 |
*/
|
| 10 |
|
| 11 |
function library_schema() {
|
| 12 |
$schema['library'] = array(
|
| 13 |
'description' => t('Determines if a library item may be checked out.'),
|
| 14 |
'fields' => array(
|
| 15 |
'id' => array(
|
| 16 |
'description' => t('The primary identifier for a library item.'),
|
| 17 |
'type' => 'serial',
|
| 18 |
'unsigned' => TRUE,
|
| 19 |
'not null' => TRUE),
|
| 20 |
'barcode' => array(
|
| 21 |
'description' => t('The barcode/identifier for this item.'),
|
| 22 |
'type' => 'varchar',
|
| 23 |
'length' => 60,
|
| 24 |
'not null' => FALSE,
|
| 25 |
'default' => ''),
|
| 26 |
'nid' => array(
|
| 27 |
'description' => t('The node identifier.'),
|
| 28 |
'type' => 'int',
|
| 29 |
'unsigned' => TRUE,
|
| 30 |
'not null' => TRUE),
|
| 31 |
'in_circulation' => array(
|
| 32 |
'description' => t('Boolean indicating whether the item is in circulation.'),
|
| 33 |
'type' => 'int',
|
| 34 |
'not null' => TRUE,
|
| 35 |
'default' => 0),
|
| 36 |
'library_status' => array(
|
| 37 |
'description' => t('Boolean indicating whether the item is available. Not directly editable.'),
|
| 38 |
'type' => 'int',
|
| 39 |
'not null' => TRUE,
|
| 40 |
'default' => 0),
|
| 41 |
'notes' => array(
|
| 42 |
'description' => t('Short description field for additional comments about the item.'),
|
| 43 |
'type' => 'varchar',
|
| 44 |
'length' => 256,
|
| 45 |
'not null' => FALSE,
|
| 46 |
'default' => ''),
|
| 47 |
'created' => array(
|
| 48 |
'type' => 'int',
|
| 49 |
'description' => t('Timestamp for when the item was created.'),
|
| 50 |
'not null' => TRUE,
|
| 51 |
'default' => 0),
|
| 52 |
),
|
| 53 |
'indexes' => array(
|
| 54 |
'nid' => array('nid'),
|
| 55 |
),
|
| 56 |
'primary key' => array('id'),
|
| 57 |
);
|
| 58 |
$schema['library_transactions'] = array(
|
| 59 |
'description' => t('The table where library transactions are stored.'),
|
| 60 |
'fields' => array(
|
| 61 |
'tid' => array(
|
| 62 |
'description' => t('The primary identifier for a transaction.'),
|
| 63 |
'type' => 'serial',
|
| 64 |
'unsigned' => TRUE,
|
| 65 |
'not null' => TRUE),
|
| 66 |
'item_id' => array(
|
| 67 |
'description' => t('The associated library item.'),
|
| 68 |
'type' => 'int',
|
| 69 |
'unsigned' => TRUE,
|
| 70 |
'not null' => TRUE),
|
| 71 |
'nid' => array(
|
| 72 |
'description' => t('The associated library node.'),
|
| 73 |
'type' => 'int',
|
| 74 |
'unsigned' => TRUE,
|
| 75 |
'not null' => TRUE),
|
| 76 |
'patron_id' => array(
|
| 77 |
'description' => t('The associated customer.'),
|
| 78 |
'type' => 'int',
|
| 79 |
'unsigned' => TRUE,
|
| 80 |
'not null' => TRUE),
|
| 81 |
'action_aid' => array(
|
| 82 |
'description' => t('The action performed.'),
|
| 83 |
'type' => 'int',
|
| 84 |
'unsigned' => TRUE,
|
| 85 |
'not null' => TRUE),
|
| 86 |
'duedate' => array(
|
| 87 |
'type' => 'int',
|
| 88 |
'description' => t('Timestamp for the current duedate.'),
|
| 89 |
'not null' => FALSE,
|
| 90 |
'default' => NULL),
|
| 91 |
'notes' => array(
|
| 92 |
'description' => t('Short description field for additional comments about the transaction.'),
|
| 93 |
'type' => 'varchar',
|
| 94 |
'length' => 256,
|
| 95 |
'not null' => FALSE,
|
| 96 |
'default' => NULL),
|
| 97 |
'created' => array(
|
| 98 |
'type' => 'int',
|
| 99 |
'description' => t('Timestamp for when transaction occurred.'),
|
| 100 |
'not null' => TRUE,
|
| 101 |
'default' => 0),
|
| 102 |
),
|
| 103 |
'indexes' => array(
|
| 104 |
'item_id' => array('item_id'),
|
| 105 |
'patron_id' => array('patron_id'),
|
| 106 |
'action_aid' => array('action_aid'),
|
| 107 |
),
|
| 108 |
'primary key' => array('tid'),
|
| 109 |
);
|
| 110 |
$schema['library_actions'] = array(
|
| 111 |
'description' => t('The table where library transactions are stored.'),
|
| 112 |
'fields' => array(
|
| 113 |
'aid' => array(
|
| 114 |
'description' => t('The unique identifier of this action.'),
|
| 115 |
'type' => 'serial',
|
| 116 |
'unsigned' => TRUE,
|
| 117 |
'not null' => TRUE),
|
| 118 |
'name' => array(
|
| 119 |
'description' => t('The name of this action.'),
|
| 120 |
'type' => 'varchar',
|
| 121 |
'length' => 60,
|
| 122 |
'not null' => TRUE,
|
| 123 |
'default' => ''),
|
| 124 |
'status_change' => array(
|
| 125 |
'description' => t('Indicates if the action changes item status.'),
|
| 126 |
'type' => 'int',
|
| 127 |
'unsigned' => TRUE,
|
| 128 |
'not null' => TRUE,
|
| 129 |
'default' => 0),
|
| 130 |
),
|
| 131 |
'primary key' => array('aid'),
|
| 132 |
);
|
| 133 |
return $schema;
|
| 134 |
}
|
| 135 |
|
| 136 |
/**
|
| 137 |
* Implementation of hook_install()
|
| 138 |
*/
|
| 139 |
function library_install() {
|
| 140 |
drupal_install_schema('library');
|
| 141 |
db_query("INSERT INTO {library_actions} (name, status_change) VALUES ('%s', %d)", 'Check Out', 1);
|
| 142 |
db_query("INSERT INTO {library_actions} (name, status_change) VALUES ('%s', %d)", 'Check In', 2);
|
| 143 |
global $base_url;
|
| 144 |
// Notify of changes
|
| 145 |
drupal_set_message(t('Library module successfully installed. You can configure library settings <a href="@link">here</a>. To start creating library items, edit one or more content types to be included in the library.', array('@link' => $base_url .'/admin/settings/library')));
|
| 146 |
|
| 147 |
}
|
| 148 |
|
| 149 |
/**
|
| 150 |
* Implementation of hook_uninstall().
|
| 151 |
*/
|
| 152 |
function library_uninstall() {
|
| 153 |
foreach (library_get_content_fields() as $fields) {
|
| 154 |
foreach ($fields as $type) {
|
| 155 |
foreach ($type as $field) {
|
| 156 |
variable_del('library_display_field_'. $field['field_name']);
|
| 157 |
}
|
| 158 |
}
|
| 159 |
}
|
| 160 |
foreach (node_get_types() as $type => $info) {
|
| 161 |
variable_del('library_'. $type .'_due_dates');
|
| 162 |
variable_del('library_'. $type);
|
| 163 |
foreach (library_actions() as $key => $value) {
|
| 164 |
variable_del('library_days_for_'. $type .'_'. library_clean_action_name($value['name']));
|
| 165 |
variable_del('library_hours_for_'. $type .'_'. library_clean_action_name($value['name']));
|
| 166 |
variable_del('library_period_for_'. $type .'_'. library_clean_action_name($value['name']));
|
| 167 |
}
|
| 168 |
}
|
| 169 |
|
| 170 |
variable_del('library_links_display_available');
|
| 171 |
variable_del('library_links_display_unavailable');
|
| 172 |
variable_del('library_links_display_reference');
|
| 173 |
variable_del('library_item_barcodes');
|
| 174 |
variable_del('library_unique_titles');
|
| 175 |
variable_del('library_cron');
|
| 176 |
variable_del('library_list_status_display');
|
| 177 |
variable_del('library_status_display');
|
| 178 |
variable_del('library_quantity_display');
|
| 179 |
variable_del('library_taxonomy_display');
|
| 180 |
variable_del('library_available_text');
|
| 181 |
variable_del('library_reference_only_text');
|
| 182 |
variable_del('library_unavailable_noduedates_text');
|
| 183 |
variable_del('library_send_automatic_email');
|
| 184 |
variable_del('library_mail_notify_overdue_subject');
|
| 185 |
variable_del('library_mail_notify_overdue_body');
|
| 186 |
drupal_uninstall_schema('library');
|
| 187 |
|
| 188 |
// Clear the cache tables.
|
| 189 |
cache_clear_all(null, 'cache');
|
| 190 |
cache_clear_all(null, 'cache_filter');
|
| 191 |
cache_clear_all(null, 'cache_menu');
|
| 192 |
cache_clear_all(null, 'cache_page');
|
| 193 |
|
| 194 |
drupal_set_message(t('Library module successfully uninstalled'));
|
| 195 |
}
|
| 196 |
|