/[drupal]/contributions/modules/temporary_invitation/temporary_invitation.install
ViewVC logotype

Contents of /contributions/modules/temporary_invitation/temporary_invitation.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download) (as text)
Thu Feb 5 13:30:48 2009 UTC (9 months, 3 weeks ago) by jpetso
Branch: MAIN
CVS Tags: DRUPAL-5--2-4, DRUPAL-5--2-3, HEAD
Changes since 1.9: +2 -4 lines
File MIME type: text/x-php
* Make it possible for modules to alter the email template and body.
* Streamline message template retrieval, and make it pluggable too.
* Update the copyright notices, and remove the amateur GPL header
  (drupal.org now explicitely states GPLv2+ anyways).
1 <?php
2 // $Id: temporary_invitation.install,v 1.9 2009/02/02 13:41:44 jpetso Exp $
3 /**
4 * @file
5 * Temporary Invitation - Invite guests for a limited timespan.
6 *
7 * Copyright 2007, 2009 by Jakob Petsovits ("jpetso", http://drupal.org/user/56020)
8 */
9
10 /**
11 * Implementation of hook_install().
12 */
13 function temporary_invitation_install() {
14 switch ($GLOBALS['db_type']) {
15 case 'mysql':
16 case 'mysqli':
17 db_query("CREATE TABLE {temporary_invitation} (
18 passcode_md5 char(32) NOT NULL,
19 host_uid int unsigned NOT NULL default '0',
20 name varchar(64) NOT NULL default '',
21 created int unsigned NOT NULL default '0',
22 PRIMARY KEY (passcode_md5)
23 ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
24 break;
25
26 case 'pgsql':
27 db_query("CREATE TABLE {temporary_invitation} (
28 passcode_md5 char(32) NOT NULL,
29 host_uid int NOT NULL default '0',
30 name varchar(64) NOT NULL default '',
31 created int NOT NULL default '0',
32 PRIMARY KEY (passcode_md5)
33 )");
34 break;
35
36 default:
37 break;
38 }
39 }
40
41 function temporary_invitation_uninstall() {
42 // If the {loginticket} table doesn't exist, it probably has been uninstalled
43 // before the uninstallation of temporary invitation. Which also means that
44 // it's not necessary to delete 'temporary_invitation' tickets, as this has
45 // been done by loginticket_uninstall() before.
46
47 if (db_table_exists('loginticket')) {
48 include_once(drupal_get_filename('module', 'loginticket'));
49
50 $tickets = loginticket_load_array('temporary_invitation', array(), TRUE);
51 if ($tickets) {
52 loginticket_delete($tickets);
53 }
54 }
55 db_query("DROP TABLE {temporary_invitation}");
56
57 $variables = array(
58 'temporary_invitation_show_menu',
59 'temporary_invitation_user_roles_default',
60 'temporary_invitation_no_roles_for_existing_user',
61 'temporary_invitation_login_target',
62 'temporary_invitation_default_duration_metric',
63 'temporary_invitation_default_duration_value',
64 'temporary_invitation_delete_action',
65 'temporary_invitation_notified_users',
66 'temporary_invitation_email_host_subject',
67 'temporary_invitation_email_host_body',
68 'temporary_invitation_email_invited_subject',
69 'temporary_invitation_email_invited_body',
70 );
71 foreach ($variables as $variable) {
72 variable_del($variable);
73 }
74 }
75
76
77 /**
78 * Implementation of hook_update_N(): original release.
79 */
80 function temporary_invitation_update_1() {
81 $items = array();
82 // Examples ONLY
83 // $items[] = update_sql("ALTER TABLE {temporary_invitation} ADD new_column text");
84 // $items[] = update_sql("ALTER TABLE {temporary_invitation} DROP old_column");
85 return $items;
86 }
87
88 /**
89 * Implementation of hook_update_N(): in preparation of release 5.x-1.7.
90 * The big variable deleting and renaming, caused by modifications in
91 * the user interface, which is in turn caused by the introduction of
92 * invited user notification mails.
93 */
94 function temporary_invitation_update_2() {
95 $items = array();
96
97 // Delete some variables - the user interface would be too complex if the
98 // same level of configuration was kept with the increasing feature set.
99 $message_without_email = variable_get('temporary_invitation_message_without_email', NULL);
100 if (isset($message_without_email)) {
101 variable_del('temporary_invitation_message_without_email');
102 $items[] = array(
103 'success' => TRUE,
104 'query' => 'Deleted variable: temporary_invitation_message_without_email',
105 );
106 }
107 $message_with_email = variable_get('temporary_invitation_message_with_email', NULL);
108 if (isset($message_with_email)) {
109 variable_del('temporary_invitation_message_with_email');
110 $items[] = array(
111 'success' => TRUE,
112 'query' => 'Deleted variable: temporary_invitation_message_with_email',
113 );
114 }
115
116 // Rename some variables, because there's both host and invited user
117 // mails, so that variable name would be ambigous the way it is now.
118 $email_subject = variable_get('temporary_invitation_email_subject', NULL);
119 if (isset($email_subject)) {
120 variable_del('temporary_invitation_email_subject');
121 variable_set('temporary_invitation_email_host_subject', $email_subject);
122 $items[] = array(
123 'success' => TRUE,
124 'query' => 'Renamed variable: temporary_invitation_email_subject -> '.
125 'temporary_invitation_email_host_subject',
126 );
127 }
128 $email_body = variable_get('temporary_invitation_email_body', NULL);
129 if (isset($email_body)) {
130 variable_del('temporary_invitation_email_body');
131 variable_set('temporary_invitation_email_host_body', $email_body);
132 $items[] = array(
133 'success' => TRUE,
134 'query' => 'Renamed variable: temporary_invitation_email_body -> '.
135 'temporary_invitation_email_host_body',
136 );
137 }
138
139 // notification_types is deleted, but there's a proper replacement for it.
140 $notification_types = variable_get('temporary_invitation_notification_types', NULL);
141 if (isset($notification_types)) {
142 variable_del('temporary_invitation_notification_types');
143
144 variable_set('temporary_invitation_notified_users',
145 in_array('email', $notification_types) ? 'host' : 'none'
146 );
147 variable_set('temporary_invitation_show_login_info_message',
148 in_array('drupal_message', $notification_types) ? 1 : 0
149 );
150 $items[] = array(
151 'success' => TRUE,
152 'query' => 'Replaced the temporary_invitation_notified_users variable '.
153 'with a combination of temporary_invitation_notified_users '.
154 'and temporary_invitation_show_login_info_message.',
155 );
156 }
157
158 return $items;
159 }
160
161 /**
162 * Implementation of hook_update_N(): still in preparation of release 5.x-1.7.
163 * More variable updating.
164 */
165 function temporary_invitation_update_3() {
166 $items = array();
167
168 // Replace the 'toplevel' item value of the array with 'standard_item'.
169 $show_menu = variable_get('temporary_invitation_show_menu', NULL);
170 if (isset($show_menu) && in_array('toplevel', $show_menu)) {
171 foreach ($show_menu as $key => $value) {
172 if ($value == 'toplevel') {
173 $show_menu[$key] = 'standard_item';
174 }
175 }
176 variable_set('temporary_invitation_show_menu', $show_menu);
177
178 $items[] = array(
179 'success' => TRUE,
180 'query' => 'Updated the temporary_invitation_show_menu array variable - '.
181 'its "toplevel" item has been renamed to "standard_item".',
182 );
183 }
184
185 return $items;
186 }
187
188 /**
189 * Implementation of hook_update_N(): still in preparation of release 5.x-1.7.
190 * One more variable update. In hindsight, the notification_types storage
191 * method was not so bad after all, so let's return to a mix of the previous
192 * and the current system.
193 */
194 function temporary_invitation_update_4() {
195 $items = array();
196
197 $notified_users = variable_get('temporary_invitation_notified_users', NULL);
198 if (isset($notified_users)) {
199 switch ($notified_users) {
200 case 'none':
201 $notified_users = array();
202 break;
203 case 'both':
204 $notified_users = array('host', 'invited');
205 break;
206 case 'host':
207 case 'invited':
208 $notified_users = array($notified_users); // either 'host' or 'invited'
209 break;
210 }
211 variable_set('temporary_invitation_notified_users', $notified_users);
212
213 $items[] = array(
214 'success' => TRUE,
215 'query' => 'Updated the temporary_invitation_notified_users variable '.
216 'to a new but functionally equivalent storage format.',
217 );
218 }
219
220 return $items;
221 }
222
223 /**
224 * Implementation of hook_update_N(): Update to 5.x-2.0-rc2,
225 * which includes a great simplification of admin settings.
226 */
227 function temporary_invitation_update_5() {
228 $items = array();
229
230 $deleted_vars = array(
231 'notified_users',
232 'show_login_info_message',
233 'email_host_subject',
234 'email_host_body',
235 'email_invited_subject',
236 'email_invited_body',
237 );
238 foreach ($deleted_vars as $key) {
239 variable_del('temporary_invitation_'. $key);
240 }
241
242 // Add the 'temporary_invitation_remove_user' property to existing
243 // temporary users, so that they will still be blocked or deleted.
244 // In previous versions, normal site users could not be invited,
245 // so any invited user could be blocked or deleted.
246 include_once(drupal_get_filename('module', 'user')); // for user_load() and user_save()
247 $result = db_query('SELECT invited_uid FROM {temporary_invitation}');
248
249 while ($invitation = db_fetch_object($result)) {
250 $user = user_load(array('uid' => $invitation->invited_uid));
251 if ($user) {
252 $userinfo = array('temporary_invitation_remove_user' => TRUE);
253 user_save($user, $userinfo);
254 }
255 }
256
257 // Replace invited_uid with passcode_md5 as primary key.
258 switch ($GLOBALS['db_type']) {
259 case 'mysql':
260 case 'mysqli':
261 $items[] = update_sql('ALTER TABLE {temporary_invitation}
262 ADD COLUMN passcode_md5 char(32) NOT NULL FIRST');
263 $items[] = update_sql('UPDATE {temporary_invitation} t, {loginticket} l
264 SET t.passcode_md5 = l.passcode_md5
265 WHERE t.invited_uid = l.uid');
266 $items[] = update_sql('ALTER TABLE {temporary_invitation}
267 DROP PRIMARY KEY,
268 ADD PRIMARY KEY (passcode_md5),
269 DROP COLUMN invited_uid');
270 break;
271
272 case 'pgsql':
273 $items[] = update_sql('ALTER TABLE {temporary_invitation}
274 ADD COLUMN passcode_md5 char(32) NOT NULL');
275 $items[] = update_sql('UPDATE {temporary_invitation} t
276 SET t.passcode_md5 =
277 (SELECT l.passcode_md5
278 FROM {loginticket} l
279 WHERE t.invited_uid = l.uid)');
280 $items[] = update_sql('ALTER TABLE {temporary_invitation}
281 DROP CONSTRAINT {temporary_invitation}_pkey,
282 ADD PRIMARY KEY (passcode_md5),
283 DROP COLUMN invited_uid');
284 break;
285 }
286
287 $items[] = array(
288 'success' => TRUE,
289 'query' => 'Updated Temporary Invitation to 5.x-2.0-rc2.',
290 );
291 return $items;
292 }
293
294 /**
295 * Implementation of hook_update_N(): Upgrade to 5.x-2.0-rc3.
296 * Feature: Token support. Measure: renaming template variables.
297 */
298 function temporary_invitation_update_6() {
299 $items = array();
300
301 $email_body = variable_get('temporary_invitation_email_body', NULL);
302 if (isset($email_body)) {
303 $variable_replacements = array(
304 '!email_body' => '[mail:body]',
305 '!passcode' => '[invitation:login-code]',
306 '!direct_login_url' => '[invitation:direct-login-url]',
307 '!login_form_url' => '[invitation:login-form-url]',
308 '!expiration_date' => '[invitation:expiration-date]',
309 '!username' => '[host-user:user-raw]',
310 '!site' => '[invitation:site-name]',
311 '!uri' => '[invitation:site-url]',
312 '!uri_brief' => '[invitation:site-url]',
313 '!date' => '[invitation:site-date]',
314 );
315 $email_body = strtr($email_body, $variable_replacements);
316 variable_set('temporary_invitation_email_body', $email_body);
317 }
318
319 $target_path = variable_get('temporary_invitation_login_target', NULL);
320 if (isset($target_path)) {
321 $variable_replacements = array(
322 '!host_uid' => '[host-user:uid]',
323 '!invited_uid' => '[invited-user:uid]',
324 );
325 $target_path = strtr($target_path, $variable_replacements);
326 variable_set('temporary_invitation_login_target', $target_path);
327 }
328
329 $items[] = array(
330 'success' => TRUE,
331 'query' => 'Replaced !var-name variables in the Temporary Invitation login target path and mail template with [object:var-name] style ones (for Token compatibility).',
332 );
333 return $items;
334 }
335
336 /**
337 * Implementation of hook_update_N(): Upgrade to 5.x-2.0 (final).
338 * Only enable the new option for new installs, but keep it the way that it
339 * worked before for upgraders.
340 */
341 function temporary_invitation_update_7() {
342 $items = array();
343
344 variable_set('temporary_invitation_no_roles_for_existing_user', FALSE);
345 $items[] = array(
346 'success' => TRUE,
347 'query' => 'Unset the new option "Don\'t assign roles to existing users" (which is enabled by default for new installs), so that the behaviour is the same after the update as it was before. You can still enable that option in the administration settings for Temporary Invitation.',
348 );
349
350 $items[] = update_sql('DELETE FROM {cache_menu}');
351 return $items;
352 }
353
354 /**
355 * Implementation of hook_update_N(): Upgrade to 5.x-2.1.
356 * Clear the menu cache, because the login path is now a pure callback function
357 * instead of a form callback (thus the cached menu path has been changed).
358 */
359 function temporary_invitation_update_8() {
360 return array(update_sql('DELETE FROM {cache_menu}'));
361 }
362
363 function temporary_invitation_update_9() {
364 $ret = array();
365
366 // Replace invited_uid with passcode_md5 as primary key.
367 switch ($GLOBALS['db_type']) {
368 case 'mysql':
369 case 'mysqli':
370 $ret[] = update_sql("ALTER TABLE {temporary_invitation}
371 ADD COLUMN created int unsigned NOT NULL default '0'");
372 break;
373
374 case 'pgsql':
375 $ret[] = update_sql("ALTER TABLE {temporary_invitation}
376 ADD COLUMN created int NOT NULL default '0'");
377 break;
378 }
379 return $ret;
380 }

  ViewVC Help
Powered by ViewVC 1.1.2