通过drush命令行将用户设置为管理员?


11

如何通过drush将用户设置为特定角色?就我而言,我想将管理员角色授予用户。

Answers:


15
drush help user-add-role
Add a role to the specified user accounts.

Examples:
 drush user-add-role "power user" 5,user3  Add the "power user" role to the accounts with name, id, or email 5 or user3, uids 2 
 --uid=2,3 --name=someguy,somegal          and 3, names someguy and somegal, and email address of billgates@microsoft.com       
 --mail=billgates@microsoft.com

Arguments:
 role                                      The name of the role to add                                                
 users                                     (optional) A comma delimited list of uids, user names, or email addresses.

Options:
 --mail=<me@example.com>                   A comma delimited list of user mail addresses of users to operate on. 
 --name=<foo>                              A comma delimited list of user names of users to operate on.          
 --uid=<3,5>                               A comma delimited list of uids of users to operate on.

Aliases: urol

因此,对于您的用例:

drush user-add-role administrator USERNAME


太容易了!= P ...至少现在我知道如何通过sql来做...大声笑
Patoshiパトシ2015年

@duckx,但这就像用后刮痕器划伤您的前脸
Patrick Ryan

0

首先,您需要像这样在users表中获取用户的ID(UID):

drush sqlq 'select * from users \Gamma'

我想要的uid是 uid = 444

然后通过执行以下操作,获取要分配给该用户的角色ID:

drush sqlq 'select * from role'

管理员角色摆脱= 3

现在我有了uid并摆脱了,我执行以下操作:

drush sqlq 'insert into users_roles (uid, rid) values (444, 3);'

1
永远不要这样做!不要养成操作数据库的习惯,最终,当您跳过一个钩子(如果您使用正确的API会调用该钩子)时,某些东西将彻底崩溃。我认为这个答案应该删除。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.