| 1 |
<?php
|
| 2 |
// $Id: asterisk.install,v 1.5 2007/11/09 22:10:44 thehunmonkgroup Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_install()
|
| 6 |
*
|
| 7 |
* This will automatically install the database tables for the Asterisk
|
| 8 |
* module for the MySQL database.
|
| 9 |
*
|
| 10 |
* If you are using another database, you will have to install the
|
| 11 |
* tables by hand, using the queries below as a reference.
|
| 12 |
*
|
| 13 |
* Note that the curly braces around table names are a drupal-specific
|
| 14 |
* feature to allow for automatic database table prefixing, and will
|
| 15 |
* need to be removed.
|
| 16 |
*/
|
| 17 |
function asterisk_install() {
|
| 18 |
$ret = drupal_install_schema('asterisk');
|
| 19 |
|
| 20 |
$failed = array();
|
| 21 |
foreach ($ret as $query) {
|
| 22 |
if (!$query['success']) {
|
| 23 |
$failed[] = $query['query'];
|
| 24 |
}
|
| 25 |
}
|
| 26 |
if (empty($failed)) {
|
| 27 |
drupal_set_message(t('Asterisk module installed successfully.'));
|
| 28 |
}
|
| 29 |
else {
|
| 30 |
drupal_set_message(t('Table installation for the Asterisk module was unsuccessful. The following queries failed: !queries', array('!queries' => theme('item_list', $failed))), 'error');
|
| 31 |
}
|
| 32 |
}
|
| 33 |
|
| 34 |
/**
|
| 35 |
* Implementation of hook_schema().
|
| 36 |
*/
|
| 37 |
function asterisk_schema() {
|
| 38 |
|
| 39 |
$schema['asterisk_call_queue'] = array(
|
| 40 |
'description' => t('Storage table for asterisk calls.'),
|
| 41 |
'fields' => array(
|
| 42 |
'call_id' => array(
|
| 43 |
'description' => t('The primary identifier for a call.'),
|
| 44 |
'type' => 'serial',
|
| 45 |
'not null' => TRUE,
|
| 46 |
),
|
| 47 |
'caller_number' => array(
|
| 48 |
'description' => t('The number intiating the call.'),
|
| 49 |
'type' => 'varchar',
|
| 50 |
'length' => 255,
|
| 51 |
'not null' => TRUE,
|
| 52 |
'default' => '',
|
| 53 |
),
|
| 54 |
'callee_number' => array(
|
| 55 |
'description' => t('The number receiving the call.'),
|
| 56 |
'type' => 'varchar',
|
| 57 |
'length' => 255,
|
| 58 |
'not null' => TRUE,
|
| 59 |
'default' => '',
|
| 60 |
),
|
| 61 |
'module' => array(
|
| 62 |
'description' => t('The module initiating the call.'),
|
| 63 |
'type' => 'varchar',
|
| 64 |
'length' => 255,
|
| 65 |
'not null' => TRUE,
|
| 66 |
'default' => '',
|
| 67 |
),
|
| 68 |
'uid' => array(
|
| 69 |
'description' => t('The uid of the user placing the call.'),
|
| 70 |
'type' => 'int',
|
| 71 |
'not null' => TRUE,
|
| 72 |
'default' => 0,
|
| 73 |
),
|
| 74 |
'dispatch_time' => array(
|
| 75 |
'description' => t('Time the call was placed (timestamp).'),
|
| 76 |
'type' => 'int',
|
| 77 |
'not null' => TRUE,
|
| 78 |
'default' => 0,
|
| 79 |
),
|
| 80 |
'caller_id' => array(
|
| 81 |
'description' => t('The caller ID of the caller.'),
|
| 82 |
'type' => 'varchar',
|
| 83 |
'length' => 255,
|
| 84 |
'not null' => TRUE,
|
| 85 |
'default' => '',
|
| 86 |
),
|
| 87 |
'vars' => array(
|
| 88 |
'description' => t('An serialized array of variables to pass to Asterisk. These variables can then be used in a dialplan or AGI script.'),
|
| 89 |
'type' => 'text',
|
| 90 |
'not null' => TRUE,
|
| 91 |
'size' => 'big',
|
| 92 |
),
|
| 93 |
'max_retries' => array(
|
| 94 |
'description' => t('The number of times to retry the call.'),
|
| 95 |
'type' => 'int',
|
| 96 |
'not null' => TRUE,
|
| 97 |
'default' => 2,
|
| 98 |
),
|
| 99 |
'retry_time' => array(
|
| 100 |
'description' => t('Number of seconds to wait before retrying a call.'),
|
| 101 |
'type' => 'int',
|
| 102 |
'not null' => TRUE,
|
| 103 |
'default' => 60,
|
| 104 |
),
|
| 105 |
'wait_time' => array(
|
| 106 |
'description' => t(''),
|
| 107 |
'type' => 'int',
|
| 108 |
'not null' => TRUE,
|
| 109 |
'default' => 30,
|
| 110 |
),
|
| 111 |
'context' => array(
|
| 112 |
'description' => t('The context the call will pass to in extensions.conf.'),
|
| 113 |
'type' => 'varchar',
|
| 114 |
'length' => 255,
|
| 115 |
'not null' => TRUE,
|
| 116 |
'default' => 'drupal',
|
| 117 |
),
|
| 118 |
'priority' => array(
|
| 119 |
'description' => t('The priority the call will start at in the specified context.'),
|
| 120 |
'type' => 'varchar',
|
| 121 |
'length' => 10,
|
| 122 |
'not null' => TRUE,
|
| 123 |
'default' => '1',
|
| 124 |
),
|
| 125 |
'call_status' => array(
|
| 126 |
'description' => t('The current status of the call.'),
|
| 127 |
'type' => 'varchar',
|
| 128 |
'length' => 32,
|
| 129 |
'not null' => TRUE,
|
| 130 |
'default' => 'uncalled',
|
| 131 |
),
|
| 132 |
'queuetime' => array(
|
| 133 |
'description' => t(''),
|
| 134 |
'type' => 'int',
|
| 135 |
'not null' => TRUE,
|
| 136 |
'default' => 0,
|
| 137 |
),
|
| 138 |
),
|
| 139 |
'primary key' => array('call_id'),
|
| 140 |
);
|
| 141 |
|
| 142 |
$schema['asterisk_users'] = array(
|
| 143 |
'description' => t('Storage table for asterisk calls.'),
|
| 144 |
'fields' => array(
|
| 145 |
'uid' => array(
|
| 146 |
'description' => t('The uid of the user.'),
|
| 147 |
'type' => 'int',
|
| 148 |
'not null' => TRUE,
|
| 149 |
'default' => 0,
|
| 150 |
),
|
| 151 |
'pin' => array(
|
| 152 |
'description' => t('The phone password for VoIP calls.'),
|
| 153 |
'type' => 'varchar',
|
| 154 |
'length' => 32,
|
| 155 |
'not null' => TRUE,
|
| 156 |
'default' => '',
|
| 157 |
),
|
| 158 |
'number' => array(
|
| 159 |
'description' => t('The phone number of the user.'),
|
| 160 |
'type' => 'varchar',
|
| 161 |
'length' => 255,
|
| 162 |
'not null' => TRUE,
|
| 163 |
'default' => '',
|
| 164 |
),
|
| 165 |
),
|
| 166 |
);
|
| 167 |
|
| 168 |
return $schema;
|
| 169 |
}
|
| 170 |
|
| 171 |
|
| 172 |
/**
|
| 173 |
* UTF8 table update
|
| 174 |
*/
|
| 175 |
function asterisk_update_1() {
|
| 176 |
return _system_update_utf8(array('asterisk_call_queue', 'asterisk_users'));
|
| 177 |
}
|
| 178 |
|
| 179 |
/**
|
| 180 |
* Implementation of hook_uninstall().
|
| 181 |
*
|
| 182 |
*/
|
| 183 |
function asterisk_uninstall() {
|
| 184 |
|
| 185 |
// Drop tables.
|
| 186 |
drupal_uninstall_schema('asterisk');
|
| 187 |
|
| 188 |
// Drop variables.
|
| 189 |
$variables = array(
|
| 190 |
'asterisk_audio_block_items',
|
| 191 |
'asterisk_call_number_help',
|
| 192 |
'asterisk_phone_number_message',
|
| 193 |
'asterisk_server_url',
|
| 194 |
'asterisk_server_pass',
|
| 195 |
'asterisk_drupal_url',
|
| 196 |
'asterisk_queuelength',
|
| 197 |
);
|
| 198 |
foreach ($variables as $variable) {
|
| 199 |
variable_del($variable);
|
| 200 |
}
|
| 201 |
|
| 202 |
// Remove all node type settings.
|
| 203 |
$types = db_query("SELECT name FROM {variable} WHERE name LIKE 'asterisk_node_%'");
|
| 204 |
while ($type = db_fetch_object($types)) {
|
| 205 |
variable_del($type->name);
|
| 206 |
}
|
| 207 |
|
| 208 |
drupal_set_message(t('Asterisk module uninstalled successfully.'));
|
| 209 |
}
|