-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtwilio.install
133 lines (126 loc) · 3.41 KB
/
twilio.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* @file
* Install and uninstall functions for the twilio module.
*/
/**
* Implements hook_install().
*/
function twilio_install() {
$t = get_t();
drupal_set_message($t("Twilio module settings are available under !link",
array( '!link' => l($t('Administer > Site configuration > Twilio'), 'admin/config/system/twilio'))
));
}
/**
* Implements hook_install().
*/
function twilio_uninstall() {
// Remove all the twilio variables.
variable_del('twilio_account');
variable_del('twilio_number');
variable_del('twilio_path');
variable_del('twilio_registration_form');
variable_del('twilio_token');
variable_del('twilio_area_codes');
}
/**
* Implements hook_schema().
*/
function twilio_schema() {
$schema['twilio_user'] = array(
'fields' => array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'number' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => 32,
),
'country' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => 32,
'default' => '1',
),
'status' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'code' => array(
'type' => 'varchar',
'not null' => FALSE,
'length' => 16,
'default' => ''
),
),
'primary key' => array('number'),
'indexes' => array('uid' => array('uid')),
);
return $schema;
}
/**
* Implements hook_requirements().
*/
function twilio_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
// Ensure translations do not break at install time
$t = get_t();
$requirements['twilio']['title'] = $t('Twilio library');
if (module_exists('libraries') && function_exists('libraries_detect')) {
$library = libraries_detect(TWILIO_LIBRARY);
$twilio_installed = ($library['installed']) ? TRUE : FALSE;
}
else {
$twilio_installed = FALSE;
}
if ($twilio_installed) {
$requirements['twilio']['value'] = $t('Installed API version !version', array('!version' => $library['version']));
$requirements['twilio']['severity'] = REQUIREMENT_OK;
}
else {
$requirements['twilio']['value'] = $t('Not installed');
$requirements['twilio']['severity'] = REQUIREMENT_ERROR;
$requirements['twilio']['description'] = $t('Please download the Twilio PHP library from !link.', array('!link' => l('http://www.twilio.com/docs/libraries', 'http://www.twilio.com/docs/libraries')));
}
}
return $requirements;
}
/**
* Create new database table {twilio_twiml}.
*/
function twilio_update_7000() {
// Get the schema array we've defined.
$schema = twilio_schema();
// Create the table.
db_create_table('twilio_twiml', $schema['twilio_twiml']);
}
/**
* Add 'country' column to {twilio_user} table
*/
function twilio_update_7001() {
$spec = array(
'type' => 'varchar',
'not null' => TRUE,
'length' => 32,
'default' => '1',
);
db_add_field( 'twilio_user', 'country', $spec);
}
/**
* Enable the twilio_twiml module if necessary.
*/
function twilio_update_7002() {
$result = db_query('SELECT COUNT(*) FROM {twilio_twiml}')->fetchField();
if (!empty($result)) {
if (module_enable(array('twilio_twiml'))) {
return "Enabled the Twilio Twiml module.";
}
}
return "Twilio Twiml module was not enabled.";
}