~spreadubuntu/spreadubuntu/devel-drupal6

« back to all changes in this revision

Viewing changes to modules/og/og.install

  • Committer: ruben
  • Date: 2009-06-08 09:38:49 UTC
  • Revision ID: ruben@captive-20090608093849-s1qtsyctv2vwp1x1
SpreadUbuntu moving to Drupal6. Based on ubuntu-drupal theme and adding our modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// $Id: og.install,v 1.71 2009/01/30 02:54:16 weitzman Exp $
 
3
 
 
4
/**
 
5
 * TODO: upgrade all update_14+ updates to d6
 
6
 */
 
7
 
 
8
 
 
9
/**
 
10
 * Definition of hook_schema();
 
11
 */
 
12
function og_schema() {
 
13
  $schema = array();
 
14
 
 
15
  $schema['og'] = array(
 
16
    'description'     => t('Stores information about each group.'),
 
17
    'fields'          => array(
 
18
      'nid'             => array(
 
19
        'description'     => t("The group's {node}.nid."),
 
20
        'type'            => 'int',
 
21
        'size'            => 'normal',
 
22
        'not null'        => TRUE,
 
23
      ),
 
24
      'og_selective'       => array(
 
25
        'description'     => t('Determines how subscription requests are handled (open, moderated, invite only, closed).'),
 
26
        'type'            => 'int',
 
27
        'size'            => 'normal',
 
28
        'not null'        => TRUE,
 
29
        'default'         => 0,
 
30
      ),
 
31
      'og_description'     => array(
 
32
        'description'     => t('Group description. Shows up by default on group directory.'),
 
33
        'type'            => 'varchar',
 
34
        'length'          => 255,
 
35
        'not null'        => FALSE,
 
36
      ),
 
37
      'og_theme'           => array(
 
38
        'description'     => t('The group specific theme (if any). See {system}.name.'),
 
39
        'type'            => 'varchar',
 
40
        'length'          => 255,
 
41
        'not null'        => FALSE,
 
42
      ),
 
43
      'og_register'        => array(
 
44
        'description'     => t('Should users be able to join this group from registration form.'),
 
45
        'type'            => 'int',
 
46
        'size'            => 'tiny',
 
47
        'not null'        => TRUE,
 
48
        'default'         => 0,
 
49
      ),
 
50
      'og_directory'       => array(
 
51
        'description'     => t('Should this group appear in the groups directory.'),
 
52
        'type'            => 'int',
 
53
        'size'            => 'tiny',
 
54
        'not null'        => TRUE,
 
55
        'default'         => 0,
 
56
      ),
 
57
      'og_language'        => array(
 
58
        'description'     => t('Group specific language. See {languages}.language.'),
 
59
        'type'            => 'varchar',
 
60
        'length'          => 12,
 
61
        'not null'        => TRUE,
 
62
        'default'         => '',
 
63
      ),
 
64
      'og_private'         => array(
 
65
        'description'     => t('Is group home page private or public.'),
 
66
        'type'            => 'int',
 
67
        'size'            => 'tiny',
 
68
        'not null'        => TRUE,
 
69
        'default'         => 0,
 
70
      ),
 
71
    ),
 
72
    'primary key'       => array('nid'),
 
73
  );
 
74
 
 
75
  $schema['og_uid'] = array(
 
76
    'description'     => t('Group memberships'),
 
77
    'fields'          => array(
 
78
      'nid'             => array(
 
79
        'description'     => t("Group's {node}.nid."),
 
80
        'type'            => 'int',
 
81
        'size'            => 'normal',
 
82
        'not null'        => TRUE,
 
83
      ),
 
84
      'og_role'         => array(
 
85
        'description'     => t('Not currently used.'),
 
86
        'type'            => 'int',
 
87
        'size'            => 'tiny',
 
88
        'not null'        => TRUE,
 
89
        'default'         => 0,
 
90
      ),
 
91
      'is_active'       => array(
 
92
        'description'     => t('Is this membership active or pending?'),
 
93
        'type'            => 'int',
 
94
        'size'            => 'tiny',
 
95
        'not null'        => TRUE,
 
96
        'default'         => 0,
 
97
      ),
 
98
      'is_admin'        => array(
 
99
        'description'     => t('Is this user a group administrator?'),
 
100
        'type'            => 'int',
 
101
        'size'            => 'tiny',
 
102
        'not null'        => TRUE,
 
103
        'default'         => 0,
 
104
      ),
 
105
      'uid'             => array(
 
106
        'description'     => t('The user for this membership. See {users}.uid.'),
 
107
        'type'            => 'int',
 
108
        'size'            => 'normal',
 
109
        'not null'        => TRUE,
 
110
      ),
 
111
      'created'         => array(
 
112
        'description'     => t('Time when this membership was created.'),
 
113
        'type'            => 'int',
 
114
        'size'            => 'normal',
 
115
        'not null'        => FALSE,
 
116
        'default'         => 0,
 
117
      ),
 
118
      'changed'         => array(
 
119
        'description'     => t('Time when this membership was last changed.'),
 
120
        'type'            => 'int',
 
121
        'size'            => 'normal',
 
122
        'not null'        => FALSE,
 
123
        'default'         => 0,
 
124
      ),
 
125
    ),
 
126
    'primary key'       => array('nid', 'uid'),
 
127
  );
 
128
  $schema['og_ancestry'] = array(
 
129
    'description'     => '',
 
130
    'fields'          => array(
 
131
      'nid'             => array(
 
132
        'description'     => t("The post's {node}.nid."),
 
133
        'type'            => 'int',
 
134
        'size'            => 'normal',
 
135
        'not null'        => TRUE,
 
136
      ),
 
137
      'group_nid'       => array(
 
138
        'description'     => t("The group's {node}.nid."),
 
139
        'type'            => 'int',
 
140
        'size'            => 'normal',
 
141
        'not null'        => TRUE,
 
142
      ),
 
143
      'is_public'       => array(
 
144
        'description'     => t('Is this a public or private post? This value is always the same across all groups for a given post.'),
 
145
        'type'            => 'int',
 
146
        'size'            => 'tiny',
 
147
        'default'         => 1,
 
148
        'not null'        => TRUE,
 
149
      ),
 
150
    ),
 
151
    'indexes'         => array(
 
152
      'nid'             => array('nid'),
 
153
      'group_nid'       => array('group_nid'),
 
154
    ),
 
155
  );
 
156
 
 
157
  return $schema;
 
158
}
 
159
 
 
160
function og_install() {
 
161
  drupal_install_schema('og');
 
162
 
 
163
  // enable standard og blocks. for custom profiles, block may not be included yet.
 
164
  if (function_exists('_block_rehash')) {
 
165
    _block_rehash();
 
166
  }
 
167
  
 
168
 
 
169
  // Need og_readme() function.
 
170
  drupal_load('module', 'og');
 
171
  drupal_set_message(t('Organic groups module enabled. Please see the included !readme_file for further installation instructions.', array('!readme_file' => og_readme())));
 
172
}
 
173
 
 
174
// First 5.x update.
 
175
// use the new na_arbitrator way of writing to node_access table
 
176
function og_update_14() {
 
177
  switch ($GLOBALS['db_type']) { 
 
178
    case 'mysql': 
 
179
    case 'mysqli': 
 
180
      $ret[] = update_sql("CREATE TABLE {og_ancestry} (
 
181
        nid int(11) NOT NULL,
 
182
        group_nid int(11) NOT NULL,
 
183
        is_public int(1) NULL,
 
184
        KEY  (nid),
 
185
        KEY  (group_nid)
 
186
      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
 
187
    break;
 
188
    case 'pgsql':
 
189
      db_query("CREATE TABLE {og_ancestry} (
 
190
        nid int NOT NULL,
 
191
        group_nid int NOT NULL,
 
192
        is_public smallint NOT NULL
 
193
      );");
 
194
      db_query("CREATE INDEX {og_ancestry}_nid_idx ON {og_ancestry} (nid);");
 
195
      db_query("CREATE INDEX {og_ancestry}_group_nid_idx ON {og_ancestry} (group_nid);");
 
196
    break;
 
197
  }
 
198
  og_migrate_type_basic_14();
 
199
  
 
200
  // populate og_ancestry.
 
201
  $result = db_query_temporary(
 
202
    "SELECT na.nid, na.gid, IF(MIN(na.realm) = 'og_all', 1, 0) AS is_public 
 
203
     FROM {node_access} na INNER JOIN {node} n ON na.nid=n.nid 
 
204
     WHERE realm IN ('og_all', 'og_subscriber') AND n.type NOT IN ('%s') GROUP BY na.nid, na.gid ORDER BY nid ASC", 
 
205
       implode(', ', variable_get('og_node_types', array('og'))), 'og_migrate');
 
206
  $sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public) SELECT nid, gid, is_public FROM {og_migrate}";
 
207
  db_query($sql);
 
208
  
 
209
  // rebuild takes care of writing new access records
 
210
  // too bad this part can't be performed over multiple updates
 
211
  node_access_rebuild();
 
212
  return array();
 
213
}
 
214
 
 
215
// Create a user managed node type which replaces the deprecated og_basic module
 
216
// helper function for og_update_14
 
217
function og_migrate_type_basic_14() {
 
218
  if (og_is_group_type('og')) {
 
219
    $info = array('type' => 'og', 'name' => 'group', 'module' => 'node', 'has_title' => 1, 'title_label' => 'Group name', 'has_body' => 1, 'body_label' => 'Welcome message', 'description' => 'A group provides a home page for like minded users. There they post articles about their shared interest.', 'help' => '', 'min_word_count' => 0, 'custom' => 1, 'modified' => 1, 'locked' => 0, 'orig_type' => 'og');
 
220
    node_type_save((object)$info);
 
221
    module_disable(array('og_basic'));
 
222
    node_types_rebuild();
 
223
  }
 
224
}
 
225
 
 
226
function og_update_15() {
 
227
  variable_del('og_max_posts');
 
228
  variable_del('og_home_page_presentation');
 
229
  return array();
 
230
}
 
231
 
 
232
function og_update_16() {
 
233
  // we are no longer denying access to nodes without groups. see http://drupal.org/node/107289
 
234
  if (variable_get('og_enabled', 0)) {
 
235
    node_access_rebuild();
 
236
  }
 
237
  return array();
 
238
}
 
239
 
 
240
function og_update_17() {
 
241
  // we are once again putting group nodes into the node access system. see http://drupal.org/node/128306
 
242
  if (variable_get('og_enabled', 0)) {
 
243
    node_access_rebuild();
 
244
  }
 
245
  return array();
 
246
}
 
247
 
 
248
function og_update_18() {
 
249
  // woops. got it a bit wrong last time
 
250
  if (variable_get('og_enabled', 0)) {
 
251
    node_access_rebuild();
 
252
  }
 
253
  return array();
 
254
}
 
255
 
 
256
// Formerly contained og_uid_global code which is no longer required.
 
257
function og_update_19() {
 
258
  return array();
 
259
}
 
260
 
 
261
function og_update_20() {
 
262
  switch ($GLOBALS['db_type']) {
 
263
  case 'mysql':
 
264
  case 'mysqli':
 
265
    $ret[] = update_sql("ALTER TABLE {og} ADD private int(1) NOT NULL default 0");
 
266
    break;
 
267
  case 'pgsql':
 
268
    $ret[] = update_sql("ALTER TABLE {og} ADD private smallint NOT NULL default 0");
 
269
    break;
 
270
  }
 
271
  return $ret;
 
272
}
 
273
 
 
274
/**
 
275
 * Changes '@body' to '@node_teaser' in existing e-mail templates.
 
276
 */ 
 
277
function og_update_5600() {
 
278
  $ret = array();
 
279
  $variables = array('og_new_node_body', 'og_new_node_subject');
 
280
  foreach ($variables as $variable) {
 
281
    $value = variable_get($variable, '');
 
282
    if (!empty($value)) {
 
283
      variable_set($variable, str_replace('@body', '@node_teaser', $value));
 
284
      $ret[] = array('success' => TRUE, 'query' => "Replaced @body with @node_teaser in $variable");
 
285
    }
 
286
  }
 
287
  return $ret;
 
288
}
 
289
 
 
290
/**
 
291
 * Enable og_access module if needed
 
292
 */ 
 
293
function og_update_5700() {
 
294
  $ret = array();
 
295
  if (variable_get('og_enabled', FALSE) && !module_exists('og_access')) {
 
296
    drupal_install_modules('og_access');
 
297
  }
 
298
  // variable_del('og_enabled'); is harmless to leave around, and will help if someone reruns the update.
 
299
  
 
300
  return $ret;
 
301
}
 
302
 
 
303
/**
 
304
 * Update variables to new content type system. Also rebuild node_access for new grants system.
 
305
 * 
 
306
 * @return void
 
307
 **/
 
308
function og_update_5701() {
 
309
  $ret = array();
 
310
  $types = node_get_types();
 
311
  foreach ($types as $type) {
 
312
    if (in_array($type->type, variable_get('og_node_types', array('og')))) {
 
313
      variable_set('og_content_type_usage_'. $type->type, 'group');
 
314
    }
 
315
    elseif (in_array($type->type, variable_get('og_omitted', array('og')))) {
 
316
      variable_set('og_content_type_usage_'. $type->type, 'omitted');
 
317
    }
 
318
    elseif (in_array($type->type, variable_get('og_omitted_email_node_types', array('og')))) {
 
319
     variable_set('og_content_type_usage_'. $type->type, 'group_post_standard_nomail');
 
320
    }
 
321
    else {
 
322
      variable_set('og_content_type_usage_'. $type->type, 'group_post_standard_mail');
 
323
    } 
 
324
  }
 
325
 
 
326
 node_access_rebuild();
 
327
 return $ret;
 
328
}
 
329
 
 
330
/**
 
331
 * Notifications upgrade: Set flag to indicate that this is an upgraded 
 
332
 * installation.
 
333
 */ 
 
334
function og_update_5703() {
 
335
  // Remove mail / no mail options from OG group types and move preferences to
 
336
  // og_notifications.
 
337
  drupal_load('module', 'og');
 
338
  $types = og_get_types('group_post');
 
339
  $mail_types = array();
 
340
  foreach ($types as $type) {
 
341
    $variable = 'og_content_type_usage_'. $type;
 
342
    $usage = variable_get($variable, '');
 
343
    switch ($usage) {
 
344
      case 'group_post_standard_mail':
 
345
        $mail_types[$type] = $type;
 
346
      case 'group_post_standard_nomail':
 
347
        variable_set($variable, 'group_post_standard');
 
348
        break;
 
349
      case 'group_post_wiki_mail':
 
350
        $mail_types[$type] = $type;
 
351
      case 'group_post_wiki_nomail':
 
352
        variable_set($variable, 'group_post_wiki');
 
353
        break;
 
354
    }
 
355
  }
 
356
  // Set variable for og_notifications. If it is never enabled, this variable
 
357
  // is also deleted in og_uninstall.
 
358
  variable_set('og_notifications_content_types', $mail_types);
 
359
 
 
360
  // Vestigial variable.
 
361
  variable_del('og_omitted_email_node_types');
 
362
 
 
363
  // Set update flag for og_notifications.
 
364
  variable_set('og_notifications_update_required', 1);
 
365
 
 
366
  return array();
 
367
}
 
368
 
 
369
function og_update_6000() {
 
370
  $ret = array();
 
371
  // Fix how we append the custom request text from a group join request.
 
372
  $name = 'og_request_user_body';
 
373
  if ($txt = variable_get($name, FALSE)) {
 
374
    $txt .= "\n\nPersonal message from @username:\n------------------\n\n@request";
 
375
    variable_set($name, $txt);
 
376
  }
 
377
  return $ret;
 
378
}
 
379
 
 
380
// Update to support views modularization while retaining backward compatibility.
 
381
function og_update_6001() {
 
382
  $ret = array();
 
383
  drupal_install_modules(array('og_views'));
 
384
  //enable the og_views block instead of the plain og one
 
385
  $ret[] = update_sql("UPDATE {blocks} SET module = 'og_views', delta = '1' WHERE module = 'og' AND delta = '5'");
 
386
  return $ret;
 
387
}
 
388
 
 
389
// Change field names in {og} table. Enables use of drupal_write_record()
 
390
function og_update_6002() {
 
391
  $ret = array();
 
392
  
 
393
  $schema = drupal_get_schema_unprocessed('og', 'og');
 
394
  $fields = $schema['fields'];
 
395
  db_change_field($ret, 'og', 'selective', 'og_selective', $fields['og_selective']);
 
396
  db_change_field($ret, 'og', 'register', 'og_register', $fields['og_register']);
 
397
  db_change_field($ret, 'og', 'theme', 'og_theme', $fields['og_theme']);
 
398
  db_change_field($ret, 'og', 'directory', 'og_directory', $fields['og_directory']);
 
399
  db_change_field($ret, 'og', 'description', 'og_description', $fields['og_description']);
 
400
  db_change_field($ret, 'og', 'language', 'og_language', $fields['og_language']);
 
401
  db_change_field($ret, 'og', 'private', 'og_private', $fields['og_private']);
 
402
  return $ret;
 
403
}
 
404
 
 
405
// end updates //
 
406
 
 
407
function og_uninstall() {
 
408
  drupal_uninstall_schema('og');
 
409
 
 
410
  // In case og_notifications has never been enabled, the vestigial 
 
411
  // og_uid_global table will still be around. 
 
412
  if (variable_get('og_notifications_update_required', FALSE)) {
 
413
    db_query('DROP TABLE {og_uid_global}');
 
414
  }
 
415
 
 
416
  // Delete variables
 
417
  $variables = array(
 
418
    'og_help', 'og_block_cnt_2', 'og_block_cnt_3',
 
419
    'og_audience_checkboxes', 'og_omitted', 'og_content_type_usage',
 
420
    'og_audience_required',
 
421
    'og_visibility_directory', 'og_visibility_registration',
 
422
    'og_home_page_view', 'og_email_max', 'og_node_types',
 
423
    'og_admin_email_body', 'og_email_notification_pattern',
 
424
    'og_approve_user_body', 'og_approve_user_subject',
 
425
    'og_deny_user_body', 'og_deny_user_subject',
 
426
    'og_invite_user_body', 'og_invite_user_subject',
 
427
    'og_new_admin_body', 'og_new_admin_subject',
 
428
    'og_new_node_body', 'og_new_node_subject',
 
429
    'og_request_user_body', 'og_request_user_subject',
 
430
    'og_notifications_update_required', 'og_notifications_content_types'
 
431
  );
 
432
  foreach ($variables as $variable) {
 
433
    variable_del($variable);
 
434
  }
 
435
}
 
436
 
 
437
function og_requirements($phase) {
 
438
  // Need og_readme() function.
 
439
  drupal_load('module', 'og');
 
440
  
 
441
  $requirements = array();
 
442
  // Ensure translations don't break at install time
 
443
  $t = get_t();
 
444
  if ($phase == 'runtime') {
 
445
    $og_types = og_get_types('group');
 
446
    $all_types = array_keys(node_get_types('types'));
 
447
    if (!count(array_intersect($og_types, $all_types))) {
 
448
      $requirements['og_group_types']  = array(
 
449
        'title' => $t('Organic groups group type'),
 
450
        'value' => $t('You have no node types which are acting as groups. See the notes section of the !readme_file and the content types fieldset at top of <a href="!settings">OG settings</a>.', array('!readme_file' => og_readme(), '!settings' => url('admin/og/og'))),
 
451
        'severity' => REQUIREMENT_ERROR,
 
452
      );
 
453
    }
 
454
 
 
455
    if (!module_exists('og_access')) {
 
456
      $requirements['og_access'] = array(
 
457
        'title' => $t('Organic groups access control'),
 
458
        'value' => $t('Organic groups access control module is disabled. See the <a href="@modules">modules page</a>.', array('@modules' => url('admin/build/modules'))),
 
459
        'severity' => REQUIREMENT_INFO
 
460
      );
 
461
    }
 
462
  }
 
463
  
 
464
  return $requirements;
 
465
}