Drupal Organic Group 角色数据存储在哪里?我如何访问它?
Posted
技术标签:
【中文标题】Drupal Organic Group 角色数据存储在哪里?我如何访问它?【英文标题】:Where is Drupal Organic Group Role Data stored? How do I access it? 【发布时间】:2011-08-31 22:20:18 【问题描述】:我为我的组创建了一个自定义角色。 我已经为这个特殊角色分配了一个用户,他是该组的成员。 现在,我想通过 php 访问用户在组中的角色,但我在任何地方都找不到。 我仔细研究了用户和组的开发。我可以访问用户是用户 group_audience 数组中组的 成员 的事实,但不能访问他们在该组中的 角色。
有什么建议吗?
编辑:Drupal 7
【问题讨论】:
您使用的是什么版本的 Drupal 和 OG? 6 还是 7? OG 7.x-1.x-dev,Drupal 7 @Dan 我刚刚更新了我的答案;我认为它现在将具体回答您的问题。无论如何,我希望你能把它整理好,但如果我真的回答了你的问题,请给我一个闪亮的绿色勾号;o) 【参考方案1】:编辑:这里先有一些背景,然后才是真正的答案。
背景
查看我们开发服务器上的 mysql 数据库,我们的 Drupal 数据库中似乎有一些与 OG 相关的表。我很确定在 devserver 上运行的版本是 og-7.x-1.x-dev。
og
og_membership
og_membership_type
og_menu
og_role
og_role_permission
og_users_roles
field_data_og_membership_request
field_revision_og_membership_request
它们的定义如下所示:
mysql> describe og;
+-------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+----------------+
| gid | int(10) unsigned | NO | PRI | NULL | auto_increment |
| etid | int(10) unsigned | NO | MUL | 0 | |
| entity_type | varchar(32) | NO | | | |
| label | varchar(255) | NO | | | |
| state | int(11) | NO | | 1 | |
| created | int(11) | NO | | 0 | |
+-------------+------------------+------+-----+---------+----------------+
6 rows in set (0.02 sec)
mysql> describe og_membership;
+-------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| type | varchar(255) | NO | | | |
| etid | int(10) unsigned | NO | MUL | 0 | |
| entity_type | varchar(32) | NO | | | |
| gid | int(11) | NO | MUL | NULL | |
| state | varchar(255) | YES | | | |
| created | int(11) | NO | | 0 | |
+-------------+------------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
mysql> describe og_membership_type;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | UNI | | |
| description | varchar(255) | NO | | | |
| status | tinyint(4) | NO | | 1 | |
| module | varchar(255) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
mysql> describe og_menu;
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| gid | int(11) | NO | PRI | NULL | |
| menu_name | varchar(128) | NO | PRI | | |
+-----------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> describe og_role;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| rid | int(10) unsigned | NO | PRI | NULL | auto_increment |
| gid | int(11) | NO | | NULL | |
| name | varchar(64) | NO | | | |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> describe og_role_permission;
+------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+-------+
| rid | int(10) unsigned | NO | PRI | NULL | |
| permission | varchar(64) | NO | PRI | | |
| module | varchar(255) | NO | | | |
+------------+------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> describe og_users_roles;
+-------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+-------+
| uid | int(10) unsigned | NO | PRI | 0 | |
| rid | int(10) unsigned | NO | PRI | 0 | |
| gid | int(11) | NO | PRI | NULL | |
+-------+------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> describe field_data_og_membership_request;
+------------------------------+------------------+------+-----+---------+
| Field | Type | Null | Key | Default |
+------------------------------+------------------+------+-----+---------+
| entity_type | varchar(128) | NO | PRI | |
| bundle | varchar(128) | NO | MUL | |
| deleted | tinyint(4) | NO | PRI | 0 |
| entity_id | int(10) unsigned | NO | PRI | NULL |
| revision_id | int(10) unsigned | YES | MUL | NULL |
| language | varchar(32) | NO | PRI | |
| delta | int(10) unsigned | NO | PRI | NULL |
| og_membership_request_value | longtext | YES | | NULL |
| og_membership_request_format | varchar(255) | YES | MUL | NULL |
+------------------------------+------------------+------+-----+---------+
9 rows in set (0.00 sec)
mysql> describe field_revision_og_membership_request;
+------------------------------+------------------+------+-----+---------+
| Field | Type | Null | Key | Default |
+------------------------------+------------------+------+-----+---------+
| entity_type | varchar(128) | NO | PRI | |
| bundle | varchar(128) | NO | MUL | |
| deleted | tinyint(4) | NO | PRI | 0 |
| entity_id | int(10) unsigned | NO | PRI | NULL |
| revision_id | int(10) unsigned | NO | PRI | NULL |
| language | varchar(32) | NO | PRI | |
| delta | int(10) unsigned | NO | PRI | NULL |
| og_membership_request_value | longtext | YES | | NULL |
| og_membership_request_format | varchar(255) | YES | MUL | NULL |
+------------------------------+------------------+------+-----+---------+
9 rows in set (0.00 sec)
(我已从两个 field_*
表中删除了空的 Extras 列以避免水平滚动。)希望对您有帮助吗?
我的工作
我自己在自己的 Drupal 站点上搞砸了这个问题,结果发现og_membership
为每个组中的每个用户都有一行(我将type
缩写为og_membership_type_default
):
mysql> select * from og_membership where gid = 324 and etid = 182905;
+--------+-----------------+--------+-------------+-----+-------+------------+
| id | type | etid | entity_type | gid | state | created |
+--------+-----------------+--------+-------------+-----+-------+------------+
| 223562 | og_m..._default | 182905 | user | 324 | 1 | 1329388409 |
+--------+-----------------+--------+-------------+-----+-------+------------+
1 row in set (0.01 sec)
在这一行中,id
是表 og_membership
的自动递增标识符,etid
对应于相关用户的 users.uid
,gid
对应于表的 og.gid
有问题的组。
所以如果我运行查询
update og_membership set gid = 38 where gid = 324;
然后将组#324 的所有成员移动到组#38(这是我刚需要做的,因为导入脚本中的错误)。
我认为你的问题的答案是og_membership.type
对应于og_membership_type.name
。看着那张桌子:
mysql> select * from og_membership_type;
+----+----------------------------+-------------+--------+--------+
| id | name | description | status | module |
+----+----------------------------+-------------+--------+--------+
| 1 | og_membership_type_default | Default | 2 | og |
+----+----------------------------+-------------+--------+--------+
1 row in set (0.00 sec)
,我认为og_membership_type.status
对应og_role.rid
:
mysql> select * from og_role;
+-----+-----+----------------------+
| rid | gid | name |
+-----+-----+----------------------+
| 1 | 0 | non-member |
| 2 | 0 | member |
| 3 | 0 | administrator member |
+-----+-----+----------------------+
3 rows in set (0.00 sec)
实际答案
所以我认为你想要的查询是:
select og_role.name
from og_role
inner join og_membership_type on og_role.rid = og_membership_type.status
inner join og_membership on og_membership_type.name = og_membership.type
where og_membership.gid = $group_id;
其中$group_id
是相关组的og.gid
。 (出现在 URL 中的 ID 是 og.etid
,因此您可能需要在该查询中添加另一个 join
。
【讨论】:
以上是关于Drupal Organic Group 角色数据存储在哪里?我如何访问它?的主要内容,如果未能解决你的问题,请参考以下文章
允许 Drupal Organic Group Admins 删除和编辑对所有组节点的访问权限
Drupal Group 模块,以编程方式将用户添加到具有特定角色的组
Drupal Group模块,以编程方式将用户添加到具有特定角色的组中
使用 Drupal Organic Groups、LifeRay Social 或 Alfresco Share 创建安全的外联网