Newer
Older
* Install, update, and uninstall functions for the Organic groups module.
// Add "User request" to the default group membership type.
$field_name = OG_MEMBERSHIP_REQUEST_FIELD;
if (!field_info_field($field_name)) {
$field = array(
'field_name' => $field_name,
'type' => 'text_long',
'entity_types' => array('og_membership'),
'cardinality' => 1,
// Although we would prefer to not allow deleting this field, we can not
// lock it, as it will not allow adding it to other bundles.
'locked' => FALSE,
);
$field = field_create_field($field);
}
if (!field_info_instance('og_membership', $field_name, OG_MEMBERSHIP_TYPE_DEFAULT)) {
$instance = array(
'field_name' => $field_name,
'bundle' => OG_MEMBERSHIP_TYPE_DEFAULT,
'entity_type' => 'og_membership',
'label' => t('Request message'),
'description' => t('This is the text a user may send to the group administrators.'),
'required' => FALSE,
);
field_create_instance($instance);
}
db_delete('variable')
->condition('name', 'og_group_manager_default_rids_%', 'LIKE')
->execute();
'og_context',
'og_group_manager_full_access',
'og_skip_access',
'og_update_batch_size',
'og_upgrade_7001',
'og_node_access_strict',
);
foreach ($vars as $var) {
variable_del($var);
}
// Remove all fields owned by organic groups.
foreach (field_read_fields(array('module' => 'og'), array('include_inactive' => TRUE)) as $field){
// We need to invoke the storage_delete hook and the field_delete_instance
// here, even though this should be done by field_delete_field().
// The current version of this function only works on active fields,
// and during uninstall, the fields will be inactive.
// Can be removed once
// http://drupal.org/node/943772
// is fixed.
module_invoke($field['storage']['module'], 'field_storage_delete_field', $field);
$instances = field_read_instances(array('field_id' => $field['id']), array('include_inactive' => TRUE));
foreach ($instances as $instance) {
field_delete_instance($instance, FALSE);
}
field_delete_field($field['field_name']);
}
Amitaibu
committed
return og_schema_info();
}
function og_schema_info() {
'description' => 'Stores the permissions assigned to user roles per group.',
'fields' => array(
'rid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Foreign Key: {role}.rid.',
),
'permission' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'A single permission granted to the role identified by rid.',
),
'module' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The module declaring the permission.",
),
),
'primary key' => array('rid', 'permission'),
'indexes' => array(
'permission' => array('permission'),
),
'foreign keys' => array(
'og_role' => array(
'table' => 'og_role',
'columns' => array('rid' => 'rid'),
),
'description' => 'Stores user roles per group.',
'fields' => array(
'rid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Primary Key: Unique role ID.',
),
'gid' => array(
'description' => "The group's unique ID.",
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
),
'group_type' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The group's entity type.",
),
'group_bundle' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The group's bundle name.",
),
'name' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'Unique role name per group.',
),
),
'primary key' => array('rid'),
);
'description' => 'Maps users to roles.',
'fields' => array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Primary Key: {users}.uid for user.',
),
'rid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Primary Key: {og_role}.rid for role.',
),
'gid' => array(
'description' => "The group's unique ID.",
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
),
'group_type' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The group's entity type.",
),
'primary key' => array('uid', 'rid', 'gid'),
'indexes' => array(
'rid' => array('rid'),
),
'foreign keys' => array(
'user' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
'og_role' => array(
'table' => 'og_role',
'columns' => array('rid' => 'rid'),
),
$schema['og_membership_type'] = array(
'description' => 'The group membership type.',
'fields' => array(
// Although the "name" should be enough as the primary key, the numeric ID
// is required for the internal use of entity API.
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Numeric group membership type ID.',
),
'name' => array(
'description' => 'The unified identifier for a group membership type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'Description for this group membership type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
// This is equivilent to ENTITY_CUSTOM.
'default' => 0x01,
'size' => 'tiny',
'description' => 'The exportable status of the entity.',
),
'module' => array(
'description' => 'The name of the providing module if the entity has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
'primary key' => array('id'),
'unique keys' => array(
'name' => array('name'),
),
);
$schema['og_membership'] = array(
'description' => 'The group membership table.',
'fields' => array(
'id' => array(
'description' => "The group membership's unique ID.",
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'Reference to a group membership type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'etid' => array(
'description' => "The entity ID.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'entity_type' => array(
'description' => "The entity type (e.g. node, comment, etc').",
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
),
'gid' => array(
'description' => "The group's unique ID.",
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
),
'group_type' => array(
'description' => "The group's entity type (e.g. node, comment, etc').",
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
),
'state' => array(
'description' => 'The state of the group content.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'created' => array(
'description' => 'The Unix timestamp when the group content was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'field_name' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The name of the field holding the group ID, the OG memebership is associated with.",
),
'indexes' => array(
// Entity index; When searching for an entity, we use both the id and type.
'entity' => array('etid', 'entity_type'),
'group' => array('gid', 'group_type'),
'og_membership_type' => array(
'table' => 'og_membership_type',
'columns' => array('name' => 'name'),
),
'table' => 'og',
'columns' => array('gid' => 'gid'),
),
),
);
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
/**
* Return the schema for upgrade 7000.
*/
function og_schema_7000_info() {
$schema = array();
$schema['og'] = array(
'description' => 'Store information related to the groups.',
'fields' => array(
'gid' => array(
'description' => "The group's unique ID.",
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'etid' => array(
'description' => "The entity ID.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'entity_type' => array(
'description' => "The entity type (e.g. node, comment, etc').",
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
),
'label' => array(
'description' => "The entity label (e.g. node's title).",
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'state' => array(
'description' => 'The state of the group (i.e. active or disabled).',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'created' => array(
'description' => 'The Unix timestamp when the group was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('gid'),
);
$schema['og_role_permission'] = array(
'description' => 'Stores the permissions assigned to user roles per group.',
'fields' => array(
'rid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Foreign Key: {role}.rid.',
),
'permission' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'A single permission granted to the role identified by rid.',
),
'module' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The module declaring the permission.",
),
),
'primary key' => array('rid', 'permission'),
'indexes' => array(
'permission' => array('permission'),
),
'foreign keys' => array(
'og_role' => array(
'table' => 'og_role',
'columns' => array('rid' => 'rid'),
),
),
);
$schema['og_role'] = array(
'description' => 'Stores user roles per group.',
'fields' => array(
'rid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Primary Key: Unique role ID.',
),
'gid' => array(
'description' => "The group's unique ID.",
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
),
'name' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'Unique role name per group.',
),
),
'primary key' => array('rid'),
);
$schema['og_users_roles'] = array(
'description' => 'Maps users to roles.',
'fields' => array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Primary Key: {users}.uid for user.',
),
'rid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Primary Key: {og_role}.rid for role.',
),
'gid' => array(
'description' => "The group's unique ID.",
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
),
),
'primary key' => array('uid', 'rid', 'gid'),
'indexes' => array(
'rid' => array('rid'),
),
'foreign keys' => array(
'user' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
'og_role' => array(
'table' => 'og_role',
'columns' => array('rid' => 'rid'),
),
),
);
$schema['og_membership_type'] = array(
'description' => 'The group membership type.',
'fields' => array(
// Although the "name" should be enough as the primary key, the numeric ID
// is required for the internal use of entity API.
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Numeric group membership type ID.',
),
'name' => array(
'description' => 'The unified identifier for a group membership type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'Description for this group membership type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
// This is equivilent to ENTITY_CUSTOM.
'default' => 0x01,
'size' => 'tiny',
'description' => 'The exportable status of the entity.',
),
'module' => array(
'description' => 'The name of the providing module if the entity has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
'primary key' => array('id'),
'unique keys' => array(
'name' => array('name'),
),
);
$schema['og_membership'] = array(
'description' => 'The group membership table.',
'fields' => array(
'id' => array(
'description' => "The group membership's unique ID.",
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'name' => array(
'description' => 'Reference to a group membership type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'etid' => array(
'description' => "The entity ID.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'entity_type' => array(
'description' => "The entity type (e.g. node, comment, etc').",
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
),
'gid' => array(
'description' => "The group's unique ID.",
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
),
'state' => array(
'description' => 'The state of the group content.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'created' => array(
'description' => 'The Unix timestamp when the group content was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('id'),
'foreign keys' => array(
'og_membership_type' => array(
'table' => 'og_membership_type',
'columns' => array('name' => 'name'),
),
'group' => array(
'table' => 'og',
'columns' => array('gid' => 'gid'),
),
),
);
return $schema;
}
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
/**
* Return the schema for upgrade 7001.
*/
function og_schema_7001_info() {
$schema = array();
$schema['og_membership_type'] = array(
'description' => 'The group membership type.',
'fields' => array(
// Although the "name" should be enough as the primary key, the numeric ID
// is required for the internal use of entity API.
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Numeric group membership type ID.',
),
'name' => array(
'description' => 'The unified identifier for a group membership type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'Description for this group membership type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
// This is equivilent to ENTITY_CUSTOM.
'default' => 0x01,
'size' => 'tiny',
'description' => 'The exportable status of the entity.',
),
'module' => array(
'description' => 'The name of the providing module if the entity has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
'primary key' => array('id'),
'unique keys' => array(
'name' => array('name'),
),
);
$schema['og_membership'] = array(
'description' => 'The group membership table.',
'fields' => array(
'id' => array(
'description' => "The group membership's unique ID.",
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'Reference to a group membership type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'etid' => array(
'description' => "The entity ID.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'entity_type' => array(
'description' => "The entity type (e.g. node, comment, etc').",
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
),
'gid' => array(
'description' => "The group's unique ID.",
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
),
'state' => array(
'description' => 'The state of the group content.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'created' => array(
'description' => 'The Unix timestamp when the group content was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('id'),
'indexes' => array(
// Entity index; When searching for an entity, we use both the id and type.
'entity' => array('etid', 'entity_type'),
'gid' => array('gid'),
),
'foreign keys' => array(
'og_membership_type' => array(
'table' => 'og_membership_type',
'columns' => array('name' => 'name'),
),
'group' => array(
'table' => 'og',
'columns' => array('gid' => 'gid'),
),
),
);
return $schema;
}
/**
* Implements hook_field_schema().
*/
function og_field_schema($field) {
$columns = array(
'gid' => array(
'description' => 'The group unique ID.',
'type' => 'float',
'unsigned' => TRUE,
'not null' => FALSE,
),
// This columns should be deprecated and removed, as the group membership
// entity takes care of it. However, there is currently no way to remove
// them.
'state' => array(
'description' => 'The state of the group content.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'created' => array(
'description' => 'The Unix timestamp when the group content was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
);
return array(
'columns' => $columns,
'indexes' => array(
'gid' => array('gid'),
),
'foreign keys' => array(
'og' => array(
'table' => 'og',
'columns' => array('gid' => 'gid'),
),
),
);
}
/**
* Upgrade from Organic groups 6 to 7.
*/
function og_update_7000(&$sandbox) {
if (db_field_exists('og', 'nid') && !db_table_exists('d6_og')) {
// Rename the old table, so we can populate the new {og} table using API
// functions, that assume the new DB structure.
db_rename_table('og', 'd6_og');
db_rename_table('og_ancestry', 'd6_og_ancestry');
db_rename_table('og_uid', 'd6_og_uid');
// Add serial ID to d6_og* tables so we can keep track of records that were
// processed.
foreach (array('d6_og', 'd6_og_ancestry', 'd6_og_uid') as $table) {
// Drop the current primary key, as we are adding a serial column.
db_drop_primary_key($table);
db_add_field($table, 'upgrade_id', array(
'description' => 'This a serial ID that keeps track of records that were processed.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
array('primary key' => array('upgrade_id')));
}
$schema = og_schema_7000_info();
foreach (array('og', 'og_role_permission', 'og_role', 'og_users_roles') as $table) {
db_create_table($table, $schema[$table]);
// We can't call og_needs_migrate() directly, so just set the variable.
variable_set('og_needs_migrate', TRUE);
return t('Renamed Organic groups 6 tables. Enable Organic groups migrate module to continue the migration of data.');
return t('No change needed in Organic groups schema.');
* Add group membership entities instead of field data.
*/
function og_update_7001(&$sandbox) {
// Due to changes in the upgrade path (e.g. moving data migration to
// og-migrate) some users already have the tables, so be careful about
// the creation of these tables.
$schema = og_schema_7001_info();
db_create_table('og_membership', $schema['og_membership']);
}
if (!db_table_exists('og_membership_type')) {
db_create_table('og_membership_type', $schema['og_membership_type']);
}
// We can't call og_needs_migrate() directly, so just set the variable.
variable_set('og_needs_migrate', TRUE);
}
/**
* Add indexes to og and og_membership tables.
*/
function og_update_7100(&$sandbox) {
// Make sure we don't try to re-add an index that was added in previous
// updates.
if (!db_index_exists('og_membership', 'entity')) {
db_add_index('og_membership', 'entity', array('etid', 'entity_type'));
}
if (!db_index_exists('og_membership', 'gid')) {
db_add_index('og_membership', 'gid', array('gid'));
}
return t('Added table indexes to {og_membership} table.');
/**
* Rename the 'name' column to 'type' in {OG membership}.
*/
function og_update_7101() {
if (db_field_exists('og_membership', 'type')) {
// Return early if field already created in og_update_7000().
return;
}
$column = array(
'description' => 'Reference to a group membership type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
);
db_change_field('og_membership', 'name', 'type', $column);
}
/**
* Deprecate OG group entity, and add per-bundle roles.
*/
function og_update_7200() {
if (!module_enable(array('entityreference'))) {
throw new DrupalUpdateException('This version of OG requires Entity reference, but it could not be enabled.');
}
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
$column = array(
'description' => "The group's entity type (e.g. node, comment, etc').",
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
);
db_add_field('og_membership', 'group_type', $column);
// Re-add index.
db_drop_index('og_membership', 'gid');
db_add_index('og_membership', 'group', array('gid', 'group_type'));
$column = array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The group's entity type.",
);
db_add_field('og_role', 'group_type', $column);
db_add_field('og_users_roles', 'group_type', $column);
$column = array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The group's bundle name.",
);
db_add_field('og_role', 'group_bundle', $column);
$column = array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The name of the field holding the group ID, the OG memebership is associated with.",
);
db_add_field('og_membership', 'field_name', $column);
// Delete the old group-audience field. The OG membership is not
// affected by this.
field_delete_field('group_audience');
// Variable cleanup.
variable_del('og_skip_access');
// We can't call og_needs_migrate() directly, so just set the variable.
variable_set('og_needs_migrate', TRUE);
// See http://drupal.org/node/996236
entity_info_cache_clear();
}