1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Install, update, and uninstall functions for the field_example module.
|
5
|
*/
|
6
|
|
7
|
/**
|
8
|
* Implements hook_field_schema().
|
9
|
*
|
10
|
* Defines the database schema of the field, using the format used by the
|
11
|
* Schema API.
|
12
|
*
|
13
|
* The data we will store here is just one 7-character element, even
|
14
|
* though the widget presents the three portions separately.
|
15
|
*
|
16
|
* All implementations of hook_field_schema() must be in the module's
|
17
|
* .install file.
|
18
|
*
|
19
|
* @see http://drupal.org/node/146939
|
20
|
* @see schemaapi
|
21
|
* @see hook_field_schema()
|
22
|
* @ingroup field_example
|
23
|
*/
|
24
|
function pollfield_field_schema($field) {
|
25
|
$columns = array(
|
26
|
'question' => array('type' => 'text', 'size' => 'medium', 'not null' => FALSE),
|
27
|
'choice' => array('type' => 'text', 'size' => 'medium', 'not null' => FALSE),
|
28
|
'anonymous'=> array('type' => 'text', 'size' => 'small', 'not null' => FALSE),
|
29
|
'poll_features'=>array('type' => 'text', 'size' => 'medium', 'not null' => FALSE),
|
30
|
'active' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0),
|
31
|
'runtime'=> array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0),
|
32
|
'votes'=> array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0),
|
33
|
);
|
34
|
$indexes = array(
|
35
|
|
36
|
);
|
37
|
return array(
|
38
|
'columns' => $columns,
|
39
|
'indexes' => $indexes,
|
40
|
);
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* Implements hook_schema().
|
45
|
*
|
46
|
* @ingroup nodeapi_example
|
47
|
*/
|
48
|
function pollfield_schema() {
|
49
|
|
50
|
|
51
|
$schema['pollfield'] = array(
|
52
|
'description' => 'Inventory of all pollfields their basic settings',
|
53
|
'fields' => array(
|
54
|
'nid' => array(
|
55
|
'description' => 'Node ID',
|
56
|
'type' => 'int',
|
57
|
'unsigned' => 1,
|
58
|
'default' => 0,
|
59
|
),
|
60
|
'field_table' => array(
|
61
|
'description' => 'The table where the pollfield is stored',
|
62
|
'type' => 'varchar',
|
63
|
'length' => 255,
|
64
|
'default' => '',
|
65
|
),
|
66
|
'field_name' => array(
|
67
|
'description' => 'Pollfield name',
|
68
|
'type' => 'varchar',
|
69
|
'length' => 32,
|
70
|
'default' => '',
|
71
|
),
|
72
|
'field_name_delta' => array(
|
73
|
'description' => 'Delta for multiple fields',
|
74
|
'type' => 'int',
|
75
|
'default' => 0,
|
76
|
),
|
77
|
'runtime' => array(
|
78
|
'description' => 'Time in seconds a pollfield is scheduled to be active',
|
79
|
'type' => 'int',
|
80
|
'default' => 0,
|
81
|
),
|
82
|
'active' => array(
|
83
|
'description' => 'Whether the poll is active or not',
|
84
|
'type' => 'int',
|
85
|
'unsigned' => 1,
|
86
|
'default' => 0,
|
87
|
),
|
88
|
),
|
89
|
'indexes' => array(
|
90
|
'nid' => array('nid'),
|
91
|
'field_table' => array('field_table'),
|
92
|
),
|
93
|
);
|
94
|
|
95
|
$schema['pollfield_votes'] = array(
|
96
|
'description' => 'Pollfield results table',
|
97
|
'fields' => array(
|
98
|
'nid' => array(
|
99
|
'description' => 'Pollfield node ID',
|
100
|
'type' => 'int',
|
101
|
'unsigned' => 1,
|
102
|
'not null' => TRUE,
|
103
|
),
|
104
|
'field_table' => array(
|
105
|
'description' => 'The table where the pollfield is stored',
|
106
|
'type' => 'varchar',
|
107
|
'length' => 255,
|
108
|
'not null' => TRUE,
|
109
|
'default' => '',
|
110
|
),
|
111
|
'field_name' => array(
|
112
|
'description' => 'The table where the pollfield is stored',
|
113
|
'type' => 'varchar',
|
114
|
'length' => 32,
|
115
|
'not null' => TRUE,
|
116
|
'default' => '',
|
117
|
),
|
118
|
'uid' => array(
|
119
|
'description' => 'Voter user ID',
|
120
|
'type' => 'int',
|
121
|
'unsigned' => 1,
|
122
|
'not null' => TRUE,
|
123
|
'default' => 0,
|
124
|
),
|
125
|
'delta' => array(
|
126
|
'description' => 'Choice',
|
127
|
'type' => 'int',
|
128
|
'not null' => TRUE,
|
129
|
'default' => -1,
|
130
|
),
|
131
|
'hostname' => array(
|
132
|
'description' => 'Voter hostname',
|
133
|
'type' => 'varchar',
|
134
|
'length' => 128,
|
135
|
'not null' => TRUE,
|
136
|
'default' => '',
|
137
|
),
|
138
|
|
139
|
'field_name_delta' => array(
|
140
|
'description' => 'Pollfield delta',
|
141
|
'type' => 'int',
|
142
|
'unsigned' => 1,
|
143
|
'not null' => TRUE,
|
144
|
'default' => 0,
|
145
|
),
|
146
|
'weight' => array(
|
147
|
'description' => 'Weight for mulitchoice',
|
148
|
'type' => 'int',
|
149
|
'unsigned' => 1,
|
150
|
'not null' => TRUE,
|
151
|
'default' => 0,
|
152
|
),
|
153
|
'cookie' => array(
|
154
|
'description' => 'Cookie for anonymous voters',
|
155
|
'type' => 'varchar',
|
156
|
'length' => 128,
|
157
|
'not null' => TRUE,
|
158
|
'default' => '',
|
159
|
),
|
160
|
),
|
161
|
'indexes' => array(
|
162
|
'nid' => array('nid'),
|
163
|
'uid' => array('uid'),
|
164
|
'field_table' => array('field_table'),
|
165
|
'hostname' => array('hostname'),
|
166
|
),
|
167
|
);
|
168
|
|
169
|
return $schema;
|
170
|
}
|
171
|
|
172
|
/**
|
173
|
* Implements hook_uninstall().
|
174
|
*
|
175
|
* We need to clean up our variables data when uninstalling our module.
|
176
|
*
|
177
|
* Our implementation of nodeapi_example_form_alter() automatically
|
178
|
* creates a nodeapi_example_node_type_<contentType> variable for each node type
|
179
|
* the user wants to rate.
|
180
|
*
|
181
|
* To delete our variables we call variable_del for our variables'
|
182
|
* namespace, 'nodeapi_example_node_type_'. Note that an average module would
|
183
|
* have known variables that it had created, and it could just delete those
|
184
|
* explicitly. For example, see render_example_uninstall(). It's important
|
185
|
* not to delete variables that might be owned by other modules, so normally
|
186
|
* we would just explicitly delete a set of known variables.
|
187
|
*
|
188
|
* hook_uninstall() will only be called when uninstalling a module, not when
|
189
|
* disabling a module. This allows our data to stay in the database if the user
|
190
|
* only disables our module without uninstalling it.
|
191
|
*
|
192
|
* @ingroup nodeapi_example
|
193
|
*/
|
194
|
function pollfield_uninstall() {
|
195
|
// Simple DB query to get the names of our variables.
|
196
|
$results = db_select('variable', 'v')
|
197
|
->fields('v', array('name'))
|
198
|
->condition('name', 'pollfield_%', 'LIKE')
|
199
|
->execute();
|
200
|
// Loop through and delete each of our variables.
|
201
|
foreach ($results as $result) {
|
202
|
variable_del($result->name);
|
203
|
}
|
204
|
}
|