This repository has been archived by the owner on Jun 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinvite.install
executable file
·273 lines (255 loc) · 8.41 KB
/
invite.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
// $Id: invite.install,v 1.13.2.3 2009/10/04 12:34:24 smk Exp $
/**
* @file
* Installation file for invite module.
*/
/**
* Install the initial schema.
*/
function invite_install() {
drupal_install_schema('invite');
}
function invite_schema() {
$schema['invite'] = array(
'description' => 'The base table for invites.',
'fields' => array(
'code' => array(
'description' => 'Stores the issued registration code and is the primary identifier for an invite.',
'type' => 'varchar',
'length' => 8,
'not null' => TRUE,
'default' => '',
),
'email' => array(
'description' => 'Stores the e-mail the invite has been addressed to.',
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
'default' => '',
),
'uid' => array(
'description' => 'Stores the user id of the inviter.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'invitee' => array(
'description' => 'Stores the user id of the invitee upon registration.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'created' => array(
'description' => 'Stores the creation time of the invite.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'expiry' => array(
'description' => 'Stores the expiry time of the invite.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'joined' => array(
'description' => 'Will be filled with the time the invite was accepted upon registration.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'canceled' => array(
'description' => 'Stores whether the invite has been withdrawn.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'sent' => array(
'description' => 'How many times the invite has been (re-)sent.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 1,
),
'data' => array(
'description' => 'Stores auxiliary data.',
'type' => 'text',
'not null' => TRUE,
),
),
'unique keys' => array(
'code' => array('code'),
),
'indexes' => array(
'email' => array('email'),
'uid' => array('uid'),
),
);
$schema['invite_notifications'] = array(
'description' => 'Stores notifications of inviters.',
'fields' => array(
'uid' => array(
'description' => 'Stores the user id to be notified (inviter).',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'invitee' => array(
'description' => 'Stores the user id of the invitee.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'unique keys' => array(
'uid_invitee' => array('uid', 'invitee'),
)
);
return $schema;
}
/**
* Implementation of hook_uninstall().
*/
function invite_uninstall() {
// Drop database schema.
drupal_uninstall_schema('invite');
// Delete variables
$sql = "DELETE from {variable} WHERE name LIKE '%s%%'";
db_query($sql, 'invite_target_role_');
db_query($sql, 'invite_maxnum_');
db_query($sql, 'invite_maxmultiple_');
variable_del('invite_target_role_default');
variable_del('invite_expiry');
variable_del('invite_allow_join_delete');
variable_del('invite_subject');
variable_del('invite_use_users_email');
variable_del('invite_use_users_email_replyto');
variable_del('invite_manual_from');
variable_del('invite_manual_reply_to');
variable_del('invite_page_title');
variable_del('invite_default_mail_template');
variable_del('invite_help_text');
// invite_stats module
variable_del('invite_num_ranks');
}
/**
* Implementation of hook_update_last_removed().
*/
function invite_update_last_removed() {
// Removed 1.x version updates. The next update function is
// invite_update_200().
return 12;
}
/**
* Helper function to update a variable name using role name to role id.
*/
function _invite_update_role_name_to_id($variable) {
$result = db_query("SELECT * FROM {role} ORDER BY name ASC");
while ($role = db_fetch_object($result)) {
// Look for both a translated (D6) and untranslated (D5) variables.
// A translated one is newer and has therefore precendence.
$translated_role = str_replace(' ', '_', t($role->name));
$value = variable_get($variable .'_'. $translated_role, NULL);
if (is_null($value)) {
$untranslated_role = str_replace(' ', '_', $role->name);
$value = variable_get($variable .'_'. $untranslated_role, NULL);
}
if (!is_null($value)) {
variable_set($variable .'_'. $role->rid, $value);
db_query("DELETE FROM {variable} WHERE name IN('%s', '%s')", $variable .'_'. $translated_role, $variable .'_'. $untranslated_role);
}
}
}
/**
* @{
* Invite 2.x updates
*/
/**
* 1. Allow multiple invitations for the same e-mail address.
* 2. Changed some column names to be more descriptive.
* 3. Added a column to flag canceled invites.
* 4. Added resent column.
*/
function invite_update_200() {
$ret = array();
db_drop_primary_key($ret, 'invite');
db_add_index($ret, 'invite', 'email', array('email'));
db_change_field($ret, 'invite', 'mid', 'invitee', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
db_change_field($ret, 'invite', 'timestamp', 'joined', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
db_add_field($ret, 'invite', 'created', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
db_add_field($ret, 'invite', 'canceled', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
db_add_field($ret, 'invite', 'resent', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
return $ret;
}
/**
* Revamped notification system.
*/
function invite_update_201() {
$ret = array();
db_create_table($ret, 'invite_notifications', array(
'description' => 'Stores notifications of inviters.',
'fields' => array(
'uid' => array(
'description' => 'Stores the user id to be notified (inviter).',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'invitee' => array(
'description' => 'Stores the user id of the invitee.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'uid' => array('uid'),
)
));
// Convert old data
$ret[] = update_sql("INSERT INTO {invite_notifications} (uid, invitee) SELECT uid, invitee FROM {invite} WHERE joined <> 0 AND received = 0");
// Drop old column
db_drop_field($ret, 'invite', 'received');
return $ret;
}
/**
* Optimize index of notification table.
*/
function invite_update_202() {
$ret = array();
db_drop_index($ret, 'invite_notifications', 'uid');
db_add_unique_key($ret, 'invite_notifications', 'uid_invitee', array('uid', 'invitee'));
return $ret;
}
/**
* Update variable names to use role id instead of translated role name.
* @see #322748
*/
function invite_update_203() {
$ret = array();
_invite_update_role_name_to_id('invite_maxnum');
_invite_update_role_name_to_id('invite_target_role');
return $ret;
}
/**
* Rename database column reg_code to code.
*/
function invite_update_204() {
$ret = array();
db_drop_unique_key($ret, 'invite', 'reg_code');
db_change_field($ret, 'invite', 'reg_code', 'code', array('type' => 'varchar', 'length' => 8, 'not null' => TRUE, 'default' => ''), array('unique keys' => array('code' => array('code'))));
return $ret;
}
/**
* Change column resent to sent.
*/
function invite_update_205() {
$ret = array();
db_change_field($ret, 'invite', 'resent', 'sent', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 1));
// Each invite has been sent at least once.
db_query("UPDATE {invite} SET sent = sent + 1");
return $ret;
}