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

Contents of /contributions/modules/signup/signup.install

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


Revision 1.30 - (show annotations) (download) (as text)
Sat Sep 19 01:42:52 2009 UTC (2 months ago) by dww
Branch: MAIN
CVS Tags: HEAD
Changes since 1.29: +23 -1 lines
File MIME type: text/x-php
#581652 by dww: Added a {signup_log}.count_towards_limit column and
adjusted the limit logic to only operate on the effective total (the
SUM() of {signup_log}.count_towards_limit) not the total # of signups.
Both signup_total and signup_effective_total are loaded into $node.
1 <?php
2 // $Id: signup.install,v 1.29 2008/12/27 00:40:23 dww Exp $
3
4
5 /**
6 * Implementation of hook_schema().
7 */
8 function signup_schema() {
9 $schema['signup'] = array(
10 'description' => t('Signup module per-node settings.'),
11 'fields' => array(
12 'nid' => array(
13 'description' => t('Primary key: node ID'),
14 'type' => 'int',
15 'unsigned' => TRUE,
16 'not null' => TRUE,
17 'default' => 0,
18 ),
19 'forwarding_email' => array(
20 'description' => t('Email address to send signup notifications to.'),
21 'type' => 'varchar',
22 'length' => 64,
23 'not null' => TRUE,
24 'default' => '',
25 ),
26 'send_confirmation' => array(
27 'description' => t('Boolean indicating whether confirmation emails should be sent.'),
28 'type' => 'int',
29 'not null' => TRUE,
30 'default' => 0,
31 ),
32 'confirmation_email' => array(
33 'description' => t('Email template to send to users when they signup.'),
34 'type' => 'text',
35 'size' => 'big',
36 'not null' => TRUE,
37 ),
38 'send_reminder' => array(
39 'description' => t('Boolean indicating whether reminder emails should be sent. This is set to 0 once the reminders are sent.'),
40 'type' => 'int',
41 'not null' => TRUE,
42 'default' => 0,
43 ),
44 'reminder_days_before' => array(
45 'description' => t('Number of days before the start of a time-based node when the reminder emails should be sent.'),
46 'type' => 'int',
47 'unsigned' => TRUE,
48 'not null' => TRUE,
49 'default' => 0,
50 ),
51 'reminder_email' => array(
52 'description' => t('Email template to send to users to remind them about a signup.'),
53 'type' => 'text',
54 'size' => 'big',
55 'not null' => TRUE,
56 ),
57 'close_in_advance_time' => array(
58 'description' => t('Number of hours before the start of a time-based node when signups should automatically be closed. This column is not currently used and the behavior is controlled by a site-wide setting. See http://drupal.org/node/290249 for more information.'),
59 'type' => 'int',
60 'unsigned' => TRUE,
61 'not null' => TRUE,
62 'default' => 0,
63 ),
64 'close_signup_limit' => array(
65 'description' => t('Maximum number of users who can signup before signups are closed. If set to 0, there is no limit.'),
66 'type' => 'int',
67 'unsigned' => TRUE,
68 'not null' => TRUE,
69 'default' => 0,
70 ),
71 'status' => array(
72 'description' => t('Boolean indicating if signups are open (1) or closed (0) for the given node'),
73 'type' => 'int',
74 'not null' => TRUE,
75 'default' => 1,
76 ),
77 ),
78 'primary key' => array('nid'),
79 );
80
81 $schema['signup_log'] = array(
82 'description' => t('Records information for each user who signs up for a node.'),
83 'fields' => array(
84 'sid' => array(
85 'description' => t('Primary key: signup ID'),
86 'type' => 'serial',
87 'size' => 'normal',
88 'unsigned' => TRUE,
89 'not null' => TRUE,
90 ),
91 'uid' => array(
92 'description' => t('Key: the user ID of the user who signed up.'),
93 'type' => 'int',
94 'unsigned' => TRUE,
95 'not null' => TRUE,
96 'default' => 0,
97 ),
98 'nid' => array(
99 'description' => t('Key: the node ID of the node the user signed up for.'),
100 'type' => 'int',
101 'unsigned' => TRUE,
102 'not null' => TRUE,
103 'default' => 0,
104 ),
105 'anon_mail' => array(
106 'description' => t('The email address for an anonymous user who signed up, or an empty string for authenticated users.'),
107 'type' => 'varchar',
108 'length' => 255,
109 'not null' => TRUE,
110 'default' => '',
111 ),
112 'signup_time' => array(
113 'description' => t('Integer timestamp of when the user signed up for the node.'),
114 'type' => 'int',
115 'unsigned' => TRUE,
116 'not null' => TRUE,
117 'default' => 0,
118 ),
119 'form_data' => array(
120 'description' => t('Serialized string of additional signup form values. See theme_signup_user_form() from theme/signup.theme for more information.'),
121 'type' => 'text',
122 'size' => 'big',
123 'not null' => TRUE,
124 ),
125 'attended' => array(
126 'description' => t('Did this user actually attend the node they signed up for?'),
127 'type' => 'int',
128 'size' => 'tiny',
129 ),
130 'count_towards_limit' => array(
131 'description' => t('How many slots (if any) this signup should use towards the total signup limit for this node'),
132 'type' => 'int',
133 'not null' => TRUE,
134 'default' => 1,
135 ),
136 ),
137 'primary key' => array('sid'),
138 'indexes' => array(
139 'uid' => array('uid'),
140 'nid' => array('nid'),
141 ),
142 );
143
144 return $schema;
145 }
146
147 /**
148 * Implementation of hook_install().
149 *
150 * This will automatically install the database tables for the Signup
151 * module for both the MySQL and PostgreSQL databases.
152 *
153 * If you are using another database, you will have to install the
154 * tables by hand, using the queries below as a reference.
155 *
156 * Note that the curly braces around table names are a drupal-specific
157 * feature to allow for automatic database table prefixing, and will
158 * need to be removed.
159 */
160 function signup_install() {
161 // Create tables.
162 drupal_install_schema('signup');
163 signup_insert_default_signup_info();
164 }
165
166 function signup_uninstall() {
167 // Remove tables.
168 drupal_uninstall_schema('signup');
169
170 $variables = db_query("SELECT name FROM {variable} WHERE name LIKE 'signup%%'");
171 while ($variable = db_fetch_object($variables)) {
172 variable_del($variable->name);
173 }
174 }
175
176 /**
177 * Helper method to insert the default signup information into the
178 * {signup} table (stored in a row for nid 0). These are the default
179 * settings for new signup-enabled nodes.
180 */
181 function signup_insert_default_signup_info() {
182 return db_query("INSERT INTO {signup} (nid, forwarding_email,
183 send_confirmation, confirmation_email,
184 send_reminder, reminder_days_before, reminder_email,
185 close_in_advance_time, close_signup_limit, status) VALUES (0, '',
186 1, 'Enter your default confirmation email message here',
187 1, 1, 'Enter your default reminder email message here',
188 0, 0, 1)");
189 }
190
191 function signup_update_3() {
192 $ret = array();
193 switch ($GLOBALS['db_type']) {
194 case 'mysql':
195 case 'mysqli':
196 $ret[] = update_sql("ALTER TABLE {signup_log} ADD anon_mail VARCHAR( 255 ) NOT NULL default '' AFTER nid;");
197 $ret[] = update_sql("ALTER TABLE {signup_log} DROP INDEX uid_nid;");
198 $ret[] = update_sql("ALTER TABLE {signup_log} ADD INDEX (uid);");
199 $ret[] = update_sql("ALTER TABLE {signup_log} ADD INDEX (nid);");
200 break;
201
202 case 'pgsql':
203 db_add_column($ret, 'signup_log', 'anon_mail', 'text', array('not null' => TRUE, 'default' => "''"));
204 $ret[] = update_sql("DROP INDEX {signup_log}_uid_nid_idx;");
205 $ret[] = update_sql("CREATE INDEX {signup_log}_uid_idx ON {signup_log}(uid);");
206 $ret[] = update_sql("CREATE INDEX {signup_log}_nid_idx ON {signup_log}(nid);");
207 break;
208 }
209 return $ret;
210 }
211
212 /**
213 * Rename the signup permissions.
214 * See http://drupal.org/node/69283 for details.
215 * Also, remove the 'signup_user_view' setting in favor of a permission.
216 * See http://drupal.org/node/69367 for details.
217 */
218 function signup_update_4() {
219 $ret = array();
220
221 // Setup arrays holding regexps to match and the corresponding
222 // strings to replace them with, for use with preg_replace().
223 $old_perms = array(
224 '/allow signups/',
225 '/admin signups/',
226 '/admin own signups/',
227 );
228 $new_perms = array(
229 'sign up for content',
230 'administer all signups',
231 'administer signups for own content',
232 );
233
234 // Now, loop over all the roles, and do the necessary transformations.
235 $query = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
236 while ($role = db_fetch_object($query)) {
237 $fixed_perm = preg_replace($old_perms, $new_perms, $role->perm);
238 if ($role->rid == 2 && variable_get('signup_user_view', 0)) {
239 // The setting is currently enabled, so add the new permission to
240 // the "authenticated user" role as a reasonable default.
241 if (!strpos($fixed_perm, 'view all signups')) {
242 $fixed_perm .= ', view all signups';
243 drupal_set_message(t('The old %signup_user_view setting was enabled on your site, so the %view_all_signups permission has been added to the %authenticated_user role. Please consider customizing what roles have this permission on the !access_control page.', array('%signup_user_view' => t('Users can view signups'), '%view_all_signups' => 'view all signups', '%authenticated_user' => 'Authenticated user', '!access_control' => l(t('Access control'), '/admin/user/access'))));
244 }
245 }
246 $ret[] = update_sql("UPDATE {permission} SET perm = '$fixed_perm' WHERE rid = $role->rid");
247 }
248
249 // Remove the stale setting from the {variable} table in the DB.
250 variable_del('signup_user_view');
251 drupal_set_message(t('The %signup_user_view setting has been removed.', array('%signup_user_view' => t('Users can view signups'))));
252
253 return $ret;
254 }
255
256 /**
257 * Convert the misnamed "completed" column to "status" (and swap all
258 * the values: 0 == closed, 1 == open).
259 */
260 function signup_update_5200() {
261 $ret = array();
262 switch ($GLOBALS['db_type']) {
263 case 'mysql':
264 case 'mysqli':
265 $ret[] = update_sql("ALTER TABLE {signup} ADD status int NOT NULL default '1'");
266 break;
267
268 case 'pgsql':
269 db_add_column($ret, 'signup', 'status', 'integer', array('not null' => TRUE, 'default' => "'1'"));
270 break;
271 }
272 $ret[] = update_sql("UPDATE {signup} SET status = (1 - completed)");
273 $ret[] = update_sql("ALTER TABLE {signup} DROP completed");
274 return $ret;
275 }
276
277 /**
278 * Add the close_signup_limit field to the {signup} table to allow
279 * signup limits for sites that upgraded from 4.6.x. The original
280 * signup.install for 4.7.x accidentally included this column in the
281 * DB, but it's never been used in the code until now. However, sites
282 * that upgraded from 4.6.x need this column for the module to work,
283 * so just to be safe, we also add that here.
284 */
285 function signup_update_5201() {
286 $ret = array();
287 switch ($GLOBALS['db_type']) {
288 case 'mysql':
289 case 'mysqli':
290 if (!db_column_exists('signup', 'close_signup_limit')) {
291 $ret[] = update_sql("ALTER TABLE {signup} ADD close_signup_limit int(10) unsigned NOT NULL default '0'");
292 }
293 break;
294
295 case 'pgsql':
296 if (!db_column_exists('signup', 'close_signup_limit')) {
297 db_add_column($ret, 'signup', 'close_signup_limit', 'integer', array('not null' => TRUE, 'default' => "'0'"));
298 }
299 break;
300 }
301 return $ret;
302 }
303
304 /**
305 * Add "cancel own signups" permission to all roles that have "sign up
306 * for content" permission.
307 */
308 function signup_update_5202() {
309 $ret = array();
310 switch ($GLOBALS['db_type']) {
311 case 'mysql':
312 case 'mysqli':
313 $ret[] = update_sql("UPDATE {permission} SET perm = CONCAT(perm, ', cancel own signups') WHERE CONCAT(perm, ', ') LIKE '%%sign up for content, %%'");
314 break;
315
316 case 'pgsql':
317 $ret[] = update_sql("UPDATE {permission} SET perm = perm || ', cancel own signups' WHERE perm || ', ' LIKE '%%sign up for content, %%'");
318 break;
319 }
320 drupal_set_message(t("Added the 'cancel own signups' permission to all roles that have the 'sign up for content' permission.") .'<br />'. t('If you do not want your users to cancel their own signups, go to the <a href="@access_url">Access control</a> page and unset this permission.', array('@access_url' => url('/admin/user/access'))));
321 return $ret;
322 }
323
324 /**
325 * Migrate signup settings per content type so that signups can be disabled
326 * completely for a content type.
327 */
328 function signup_update_5203() {
329 $old_prefix = 'signup_form_';
330 $result = db_query("SELECT name FROM {variable} WHERE name LIKE '$old_prefix%%'");
331 while ($row = db_fetch_object($result)) {
332 $old_name = $row->name;
333 $new_name = 'signup_node_default_state_'. substr($old_name, strlen($old_prefix));
334 $new_value = variable_get($old_name, 0) == 1 ? 'enabled_on' : 'disabled';
335 variable_del($old_name);
336 variable_set($new_name, $new_value);
337 }
338 drupal_set_message(t('Migrated signup settings per content type.'));
339 return array();
340 }
341
342 /**
343 * Rename all the tokens in existing email templates and the global settings.
344 */
345 function signup_update_5204() {
346 $ret = array();
347
348 // Multi-part update.
349 if (!isset($_SESSION['signup_update_5204'])) {
350 // We need to start at nid 0 for the site-wide defaults, so
351 // initialize our variable to the value below that.
352 $_SESSION['signup_update_5204'] = -1;
353 $_SESSION['signup_update_5204_max'] = db_result(db_query("SELECT MAX(nid) FROM {signup}"));
354 }
355
356 // Array of replacements mapping old names to the new names.
357 // NOTE: To avoid trouble with db_query() trying to interpret the
358 // '%', we escape all of them as '%%' to get % literals.
359 $replacements = array(
360 '%%eventurl' => '%%node_url',
361 '%%event' => '%%node_title',
362 '%%time' => '%%node_start_time',
363 '%%username' => '%%user_name',
364 '%%useremail' => '%%user_mail',
365 '%%info' => '%%user_signup_info',
366 );
367
368 // Build up a nested REPLACE() fragment to have the DB do all the string
369 // conversions for us in a single query, instead of pulling the records out
370 // of the DB, doing the string manipulation in PHP, and writing back the
371 // values in a bunch of separate queries. According to the docs, REPLACE()
372 // works the same way on both MySQL and PgSQL.
373 $reminder_replace = 'reminder_email';
374 $confirmation_replace = 'confirmation_email';
375 foreach ($replacements as $from => $to) {
376 $reminder_replace = "REPLACE($reminder_replace, '$from', '$to')";
377 $confirmation_replace = "REPLACE($confirmation_replace, '$from', '$to')";
378 }
379
380 // Do the next batch of the deed.
381 // Find the next N records to update, or do the final batch.
382 $next = min($_SESSION['signup_update_5204'] + 2000, $_SESSION['signup_update_5204_max']);
383 // Perform the UPDATE in our specified range of nid values.
384 db_query("UPDATE {signup} SET reminder_email = $reminder_replace, confirmation_email = $confirmation_replace WHERE nid > %d AND nid <= %d", $_SESSION['signup_update_5204'], $next);
385 // Remember where we left off.
386 $_SESSION['signup_update_5204'] = $next;
387
388 if ($_SESSION['signup_update_5204'] == $_SESSION['signup_update_5204_max']) {
389 // We're done, clear these out.
390 unset($_SESSION['signup_update_5204']);
391 unset($_SESSION['signup_update_5204_max']);
392
393 // Provide a human-readable explaination of what we did.
394 $tokens = array(
395 '%event' => '%event',
396 '%eventurl' => '%eventurl',
397 '%time' => '%time',
398 '%username' => '%username',
399 '%useremail' => '%useremail',
400 '%info' => '%info',
401 '%node_title' => '%node_title',
402 '%node_url' => '%node_url',
403 '%node_start_time' => '%node_start_time',
404 '%user_name' => '%user_name',
405 '%user_mail' => '%user_mail',
406 '%user_signup_info' => '%user_signup_info',
407 );
408 $ret[] = array('success' => TRUE, 'query' => t('Replaced %event, %eventurl, %time, %username, %useremail, and %info tokens with %node_title, %node_url, %node_start_time, %user_name, %user_mail, and %user_signup_info in the reminder and confirmation email templates.', $tokens));
409 }
410 else {
411 // Report how much is left to complete.
412 $ret['#finished'] = $_SESSION['signup_update_5204'] / $_SESSION['signup_update_5204_max'];
413 }
414 return $ret;
415 }
416
417 /**
418 * Migrate signup user list view display type to the new variable.
419 */
420 function signup_update_6000() {
421 $ret = array();
422 variable_del('signup_user_list_view_name');
423 variable_del('signup_user_list_view_type');
424 $ret[] = array(
425 'success' => TRUE,
426 'query' => t('Removed the deprecated %old_view_name and %old_view_type variables. If you were using embedding a view on signup-enabled nodes, please visit the <a href="@signup_settings_url">Signup configuration page</a> and select a new value for the %setting_name setting (which is located under the Advanced settings).', array(
427 '%old_view_name' => 'signup_user_list_view_name',
428 '%old_view_type' => 'signup_user_list_view_type',
429 // NOTE: we can't use url() here because it would use 'update.php?q=...'
430 '@signup_settings_url' => base_path() .'?q=admin/settings/signup',
431 '%setting_name' => t('View to embed for the signup user list'),
432 )),
433 );
434 return $ret;
435 }
436
437 /**
438 * Add unique id column to signup_log as the primary key.
439 *
440 * http://drupal.org/node/341382 for more infomation.
441 */
442 function signup_update_6001() {
443 $ret = array();
444 $field = array(
445 'type' => 'serial',
446 'size' => 'normal',
447 'unsigned' => TRUE,
448 'not null' => TRUE,
449 );
450 db_add_field($ret, 'signup_log', 'sid', $field, array('primary key' => array('sid')));
451 return $ret;
452 }
453
454 /**
455 * Add an 'attended' field to the {signup_log} table.
456 *
457 * http://drupal.org/node/55168 for more infomation.
458 */
459 function signup_update_6002() {
460 $ret = array();
461 $field = array(
462 'type' => 'int',
463 'size' => 'tiny',
464 );
465 db_add_field($ret, 'signup_log', 'attended', $field);
466 return $ret;
467 }
468
469 /**
470 * Add the 'count_towards_limit' field to the {signup_log} table.
471 *
472 * http://drupal.org/node/581652 for more infomation.
473 */
474 function signup_update_6003() {
475 $ret = array();
476 $field = array(
477 'type' => 'int',
478 'not null' => TRUE,
479 'default' => 1,
480 );
481 db_add_field($ret, 'signup_log', 'count_towards_limit', $field);
482 return $ret;
483 }
484

  ViewVC Help
Powered by ViewVC 1.1.2